Class: SolidusShipstation::Api::RequestRunner
- Inherits:
-
Object
- Object
- SolidusShipstation::Api::RequestRunner
- Defined in:
- lib/solidus_shipstation/api/request_runner.rb
Constant Summary collapse
- API_BASE =
'https://ssapi.shipstation.com'
Instance Attribute Summary collapse
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Class Method Summary collapse
Instance Method Summary collapse
- #call(method, path, params = {}) ⇒ Object
-
#initialize(username:, password:) ⇒ RequestRunner
constructor
A new instance of RequestRunner.
Constructor Details
#initialize(username:, password:) ⇒ RequestRunner
Returns a new instance of RequestRunner.
19 20 21 22 |
# File 'lib/solidus_shipstation/api/request_runner.rb', line 19 def initialize(username:, password:) @username = username @password = password end |
Instance Attribute Details
#password ⇒ Object (readonly)
Returns the value of attribute password.
8 9 10 |
# File 'lib/solidus_shipstation/api/request_runner.rb', line 8 def password @password end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
8 9 10 |
# File 'lib/solidus_shipstation/api/request_runner.rb', line 8 def username @username end |
Class Method Details
.from_config ⇒ Object
11 12 13 14 15 16 |
# File 'lib/solidus_shipstation/api/request_runner.rb', line 11 def from_config new( username: SolidusShipstation.config.api_key, password: SolidusShipstation.config.api_secret, ) end |
Instance Method Details
#call(method, path, params = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/solidus_shipstation/api/request_runner.rb', line 24 def call(method, path, params = {}) response = HTTParty.send( method, URI.join(API_BASE, path), body: params.to_json, basic_auth: { username: @username, password: @password, }, headers: { 'Content-Type' => 'application/json', 'Accept' => 'application/json', }, ) case response.code.to_s when /2\d{2}/ response.parsed_response when '429' raise RateLimitedError.from_response(response) else raise RequestError.from_response(response) end end |