class CustomerxTracking::Requestor

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/customerx_tracking/requestor.rb, line 3
def initialize
  super
  raise 'credential and key should be set' if authorizations_is_not_present?
end

Public Instance Methods

request(meth, params = nil) click to toggle source
# File lib/customerx_tracking/requestor.rb, line 8
def request(meth, params = nil)
  meth = meth.downcase

  begin
    response = connection.method(meth).call do |req|
      (meth == :get ? (req.params = params) : (req.body = params.to_json)) if params
    end
  rescue StandardError => e
    raise "it was not possible to carry out the request #{e}"
  end

  { status: response.status, body: JSON.parse(response.body) }
end