Class: CustomerxTracking::Requestor
- Defined in:
- lib/customerx_tracking/requestor.rb
Instance Method Summary collapse
-
#initialize ⇒ Requestor
constructor
A new instance of Requestor.
- #request(meth, params = nil) ⇒ Object
Methods inherited from Base
#authorizations_is_not_present?, #connection
Constructor Details
#initialize ⇒ Requestor
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 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 |