Class: Vacuum::Request

Inherits:
Object
  • Object
show all
Includes:
Jeff
Defined in:
lib/vacuum/request.rb

Overview

An Amazon Product Advertising API request.

Constant Summary collapse

BadLocale =
Class.new ArgumentError
MissingTag =
Class.new ArgumentError
HOSTS =

A list of Amazon Product Advertising API hosts.

{
  'CA' => 'ecs.amazonaws.ca',
  'CN' => 'webservices.amazon.cn',
  'DE' => 'ecs.amazonaws.de',
  'ES' => 'webservices.amazon.es',
  'FR' => 'ecs.amazonaws.fr',
  'IT' => 'webservices.amazon.it',
  'JP' => 'ecs.amazonaws.jp',
  'UK' => 'ecs.amazonaws.co.uk',
  'US' => 'ecs.amazonaws.com'
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(locale = nil) ⇒ Request

Creates a new request for given locale and credentials.

locale - The String Product Advertising API locale (default: US).

Raises a Bad Locale error if locale is not valid.



33
34
35
36
# File 'lib/vacuum/request.rb', line 33

def initialize(locale = nil)
  host = HOSTS[locale || 'US'] or raise BadLocale
  self.endpoint = "http://#{host}/onca/xml"
end

Instance Attribute Details

#tagObject

Gets the String Associate Tag.

Raises a Missing Tag error if Associate Tag is missing.



59
60
61
# File 'lib/vacuum/request.rb', line 59

def tag
  @tag or raise MissingTag
end

Instance Method Details

#configure(credentials, &blk) ⇒ Object

Configures the Amazon Product Advertising API request.

credentials - The Hash credentials of the API endpoint.

:key    - The String Amazon Web Services (AWS) key.
:secret - The String AWS secret.
:tag    - The String Associate Tag.

Yields self.

Returns nothing.



48
49
50
51
52
53
54
# File 'lib/vacuum/request.rb', line 48

def configure(credentials, &blk)
  if block_given?
    yield self
  else
    credentials.each { |key, val| self.send "#{key}=", val }
  end
end