Class: Amazon::MWS::Base
- Inherits:
-
Object
- Object
- Amazon::MWS::Base
- Defined in:
- lib/amazon/mws/base.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
Class Method Summary collapse
Instance Method Summary collapse
- #connected? ⇒ Boolean
-
#initialize(options = {}) ⇒ Base
constructor
A new instance of Base.
-
#request(verb, path, query_params = {}, body = nil, attempts = 0, &block) ⇒ Object
Wraps the current connection’s request method and picks the appropriate response class to wrap the response in.
Constructor Details
#initialize(options = {}) ⇒ Base
Returns a new instance of Base.
22 23 24 25 26 |
# File 'lib/amazon/mws/base.rb', line 22 def initialize( ={}) @merchant_id = ['merchant_id'] raise "Must supply merchant_id" unless @merchant_id @connection = Amazon::MWS::Connection.connect() end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
17 18 19 |
# File 'lib/amazon/mws/base.rb', line 17 def connection @connection end |
Class Method Details
.debug ⇒ Object
19 |
# File 'lib/amazon/mws/base.rb', line 19 def self.debug; @@debug ||= false end |
.debug=(bool) ⇒ Object
20 |
# File 'lib/amazon/mws/base.rb', line 20 def self.debug=(bool); @@debug = bool end |
Instance Method Details
#connected? ⇒ Boolean
33 34 35 |
# File 'lib/amazon/mws/base.rb', line 33 def connected? !@connection.nil? end |
#request(verb, path, query_params = {}, body = nil, attempts = 0, &block) ⇒ Object
Wraps the current connection’s request method and picks the appropriate response class to wrap the response in. If the response is an error, it will raise that error as an exception. All such exceptions can be caught by rescuing their superclass, the ResponseError exception class.
It is unlikely that you would call this method directly. Subclasses of Base have convenience methods for each http request verb that wrap calls to request.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/amazon/mws/base.rb', line 48 def request(verb, path, query_params = {}, body = nil, attempts = 0, &block) # Find the connection method in connection/management.rb which is evaled into Amazon::MWS::Base response = @connection.request(verb, path, query_params, body, attempts, &block) # Each calling class is responsible for formatting the result return response rescue InternalError, RequestTimeout if attempts == 3 raise else attempts += 1 retry end end |