Class: AmazonProductAPI
- Inherits:
-
Object
- Object
- AmazonProductAPI
- Defined in:
- lib/amazon_product_api.rb,
lib/amazon_product_api/version.rb
Overview
A very simple client for the Amazon Product Advertising API.
Constant Summary collapse
- ENDPOINTS =
{ :ca => 'https://ecs.amazonaws.ca/onca/xml', :cn => 'https://webservices.amazon.cn/onca/xml', :de => 'https://ecs.amazonaws.de/onca/xml', :es => 'https://webservices.amazon.es/onca/xml', :fr => 'https://ecs.amazonaws.fr/onca/xml', :it => 'https://webservices.amazon.it/onca/xml', :jp => 'https://ecs.amazonaws.jp/onca/xml', :uk => 'https://ecs.amazonaws.co.uk/onca/xml', :us => 'https://webservices.amazon.com/onca/xml' }
- SERVICE =
'AWSECommerceService'- API_VERSION =
'2011-08-01'- AMPERSAND =
'&'- COMMA =
','- PERCENT =
'%'- HTTPS =
'https'- USER_AGENT =
"amazon_product_api #{VERSION}"- HEADERS =
{'User-Agent' => USER_AGENT, 'Accept' => 'application/xml'}
- DIGEST =
OpenSSL::Digest::SHA256.new
- ENCODE =
/([^a-zA-Z0-9_.~-]+)/- VERSION =
"0.1.0"
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
- #get(operation, response_groups, operation_params = {}) ⇒ Net::HTTPResponse
-
#initialize(locale, access_key_id, secret_access_key, associate_tag) ⇒ AmazonProductAPI
constructor
Possible locale values are - :ca, :cn, :de, :es, :fr, :it, :jp, :uk, :us.
Constructor Details
#initialize(locale, access_key_id, secret_access_key, associate_tag) ⇒ AmazonProductAPI
Possible locale values are - :ca, :cn, :de, :es, :fr, :it, :jp, :uk, :us
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/amazon_product_api.rb', line 40 def initialize(locale, access_key_id, secret_access_key, associate_tag) # Check that the locale provided maps to an endpoint string: raise ArgumentError, "invalid locale '#{locale}'" if ENDPOINTS[locale].nil? @endpoint = URI.parse(ENDPOINTS[locale]) @access_key_id = access_key_id @secret_access_key = secret_access_key @associate_tag = associate_tag @connection = Net::HTTP.new(@endpoint.host, @endpoint.port) @default_params = { 'Service' => SERVICE, 'Version' => API_VERSION, 'AWSAccessKeyId' => @access_key_id, 'AssociateTag' => @associate_tag } if @endpoint.scheme == HTTPS @connection.use_ssl = true end end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
32 33 34 |
# File 'lib/amazon_product_api.rb', line 32 def connection @connection end |
Instance Method Details
#get(operation, response_groups, operation_params = {}) ⇒ Net::HTTPResponse
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/amazon_product_api.rb', line 65 def get(operation, response_groups, operation_params = {}) base_params = { 'Operation' => operation, 'ResponseGroup' => response_groups.join(COMMA), 'Timestamp' => Time.now.xmlschema } unsigned_params = operation_params.merge(@default_params.merge(base_params)) signed_params = unsigned_params.merge({'Signature' => signature(unsigned_params)}) request_uri = @endpoint.dup request_uri.query = query_string(signed_params) @connection.request(Net::HTTP::Get.new(request_uri.to_s, HEADERS)) end |