module Malartu
Constants
- API_PATH
- API_VERSION
- VERSION
Attributes
api_version[RW]
apikey[RW]
topics[RW]
Public Class Methods
auth_params()
click to toggle source
# File lib/malartu.rb, line 34 def auth_params fail 'No apikey present. Set it with `Malartu.apikey =`' if apikey.nil? { apikey: apikey } end
base_path()
click to toggle source
# File lib/malartu.rb, line 39 def base_path "#{API_PATH}/#{version}" end
check_for_errors(response, params)
click to toggle source
# File lib/malartu.rb, line 47 def check_for_errors(response, params) case response.code when 401 fail Malartu::Error::AuthorizationError.new( message: 'Credentials do not match', parameters: { apikey: params[:apikey] }, json_body: JSON.parse(response.body) ) when 404 fail Malartu::Error::RecordNotFoundError.new( message: 'Record Not Found', parameters: { id: params[:id], model: params[:model] }, json_body: JSON.parse(response.body) ) when 429 fail Malartu::Error::RateLimitError.new( message: 'Rate Limited', parameters: { apikey: params[:apikey] }, json_body: JSON.parse(response.body) ) when 500 fail Malartu::Error::ServerError.new( message: 'Server Error', parameters: params, json_body: JSON.parse(response.body) ) end end
request(method, path, params = {}, _headers = {})
click to toggle source
# File lib/malartu.rb, line 21 def request(method, path, params = {}, _headers = {}) url = "#{base_path}#{path}" req_params = case method.to_s when 'get' { params: params.merge(auth_params) } else { json: params.merge(auth_params) } end response = HTTP.send(method, url, req_params) check_for_errors(response, params.merge(auth_params)) JSON.parse(response.body) end
version()
click to toggle source
# File lib/malartu.rb, line 43 def version api_version || API_VERSION end