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

BadLocale =
Class.new(ArgumentError)
LATEST_VERSION =
'2013-08-01'
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'
}.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.



53
54
55
56
57
# File 'lib/vacuum/request.rb', line 53

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

Instance Attribute Details

#associate_tagObject

Returns the value of attribute associate_tag



43
44
45
# File 'lib/vacuum/request.rb', line 43

def associate_tag
  @associate_tag
end

#versionObject

Returns the API version.



75
76
77
# File 'lib/vacuum/request.rb', line 75

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.



69
70
71
72
# File 'lib/vacuum/request.rb', line 69

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