Class: Amazon::MWS::Base

Inherits:
Object show all
Defined in:
lib/amazon/mws/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



11
12
13
# File 'lib/amazon/mws/base.rb', line 11

def initialize(options ={})
  @connection = Amazon::MWS::Connection.connect(options)
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



6
7
8
# File 'lib/amazon/mws/base.rb', line 6

def connection
  @connection
end

Class Method Details

.debugObject



8
# File 'lib/amazon/mws/base.rb', line 8

def self.debug; @@debug ||= false end

.debug=(bool) ⇒ Object



9
# File 'lib/amazon/mws/base.rb', line 9

def self.debug=(bool); @@debug = bool end

Instance Method Details

#connected?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/amazon/mws/base.rb', line 20

def connected?
  !@connection.nil?
end

#disconnectObject



24
25
26
27
# File 'lib/amazon/mws/base.rb', line 24

def disconnect
  @connection.http.finish if @connection.persistent?
  @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.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/amazon/mws/base.rb', line 35

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