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)
LATEST_VERSION =
'2013-08-01'.freeze
HOSTS =
{
  'BR' => 'webservices.amazon.com.br',
  'CA' => 'webservices.amazon.ca',
  'CN' => 'webservices.amazon.cn',
  'DE' => 'webservices.amazon.de',
  'ES' => 'webservices.amazon.es',
  'FR' => 'webservices.amazon.fr',
  'GB' => 'webservices.amazon.co.uk',
  'IN' => 'webservices.amazon.in',
  'IT' => 'webservices.amazon.it',
  'JP' => 'webservices.amazon.co.jp',
  'US' => 'webservices.amazon.com',
  'MX' => 'webservices.amazon.com.mx'
}.freeze
OPERATIONS =
%w[
  BrowseNodeLookup
  CartAdd
  CartClear
  CartCreate
  CartGet
  CartModify
  ItemLookup
  ItemSearch
  SimilarityLookup
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(locale = 'US', secure = false) ⇒ Request

Create a new request for given locale.

locale - The String Product Advertising API locale (default: US). secure - Whether to use the secure version of the endpoint (default:

false)

Raises a Bad Locale error if locale is not valid.



55
56
57
58
59
# File 'lib/vacuum/request.rb', line 55

def initialize(locale = 'US', secure = false)
  locale = 'GB' if locale == 'UK'
  host = HOSTS.fetch(locale) { raise BadLocale }
  @aws_endpoint = "#{secure ? 'https' : 'http'}://#{host}/onca/xml"
end

Instance Attribute Details

#associate_tagObject

Returns the value of attribute associate_tag.



45
46
47
# File 'lib/vacuum/request.rb', line 45

def associate_tag
  @associate_tag
end

#subscription_idObject

Returns the value of attribute subscription_id.



45
46
47
# File 'lib/vacuum/request.rb', line 45

def subscription_id
  @subscription_id
end

#versionObject

Returns the API version.



77
78
79
# File 'lib/vacuum/request.rb', line 77

def version
  @version || LATEST_VERSION
end

Instance Method Details

#configure(credentials) ⇒ Object

Configure the Amazon Product Advertising API request.

credentials - The Hash credentials of the API endpoint.

:aws_access_key_id     - The String Amazon Web Services
                         (AWS) key.
:aws_secret_access_key - The String AWS secret.
:associate_tag         - The String Associate Tag.
:aws_version           - The String AWS version.

Returns self.



71
72
73
74
# File 'lib/vacuum/request.rb', line 71

def configure(credentials)
  credentials.each { |key, val| send("#{key}=", val) }
  self
end