Class: RubyOmx::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_omx/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



8
9
10
11
12
13
# File 'lib/ruby_omx/base.rb', line 8

def initialize(options ={})
  @http_biz_id = options['http_biz_id']
  @udi_auth_token = options['udi_auth_token']
  raise RubyOmx::MissingAccessKey.new(['udi auth token', 'http biz id']) unless @udi_auth_token && @http_biz_id
  @connection = RubyOmx::Connection.connect(options)
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



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

def connection
  @connection
end

Instance Method Details

#request(verb, 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.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ruby_omx/base.rb', line 22

def request(verb, body = nil, attempts = 0, &block)
    # Find the connection method in connection/management.rb which is evaled into Amazon::MWS::Base
  response = @connection.request(verb, 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