Class: Shipvine::Client
- Inherits:
-
Object
- Object
- Shipvine::Client
- Includes:
- HTTParty
- Defined in:
- lib/shipvine/client.rb
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Client
constructor
A new instance of Client.
- #request(method, resource, params = {}, exclude_merchant_code: false) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Client
Returns a new instance of Client.
6 7 8 |
# File 'lib/shipvine/client.rb', line 6 def initialize(opts = {}) @options = opts end |
Instance Method Details
#request(method, resource, params = {}, exclude_merchant_code: false) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/shipvine/client.rb', line 10 def request(method, resource, params = {}, exclude_merchant_code: false) = .deep_merge(@options) = if method == :get .merge(query: sanitize_query_parameters(params, exclude_merchant_code: exclude_merchant_code) ) else # TODO a sanitization method is needed here .merge(body: params) end response = self.class.send(method, resource, ) # NOTE response will be nil if the body of the response is nil if response.code != 200 # TODO response.response.message == 'Unauthorized' in the case of 401 # possibly try to sniff out more descriptive error information fail Shipvine::Error.new(response), "#{response.code} #{response.body}" else response end end |