Class: CustomerxTracking::Requestor

Inherits:
Base
  • Object
show all
Defined in:
lib/customerx_tracking/requestor.rb

Instance Method Summary collapse

Methods inherited from Base

#authorizations_is_not_present?, #connection

Constructor Details

#initializeRequestor

Returns a new instance of Requestor.



3
4
5
6
# File 'lib/customerx_tracking/requestor.rb', line 3

def initialize
  super
  raise 'credential and key should be set' if authorizations_is_not_present?
end

Instance Method Details

#request(meth, params = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# 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