Module: Amazonian

Defined in:
lib/amazonian.rb,
lib/amazonian/version.rb

Overview

This module is designed to allow easier querying of the Amazon Product Advertising API from within your Ruby or Rails applications.

Basic usage requires first calling Amazonian.setup to provide your Amazon AWS Key and Secret key for the module to use in querying the database.

Amazons internal product ids can be used to retrieve data from the API with Amazonian.asin.

Searching for products is done via Amazonian.search

Author:

  • Robert L. Carpenter (Modern codebase, interface, gem-ability)

  • phoet (Original ASIN interface and implementation of Request Signing, etc.) github.com/phoet/asin

Version:

  • 0.2.0

Defined Under Namespace

Classes: Item, Search

Constant Summary collapse

VERSION =
"0.2.0"
@@digest =

worker objects

OpenSSL::Digest::Digest.new('sha256')
@@logger =
Logger.new(STDERR)
@@patron =
Patron::Session.new

Class Method Summary collapse

Class Method Details

.asin(asin, params = {}) ⇒ Amazonian::Item

Perform an ASIN (Amazon Standard Identification Number) lookup.

Parameters:

  • The (String)

    ASIN with which to query the API.

  • Additional (Hash)

    options to be passed to the API.

  • params (Hash) (defaults to: {})

    a customizable set of options

Options Hash (params):

  • :Operation (Symbol)

    defaults to :ItemLookup

  • :ItemLookup (Symbol)

    defaults to the ASIN passed as param 1.

Returns:

See Also:

  • more information on the parameters the API accepts, see http://docs.amazonwebservices.com/AWSEcommerceService/4-0/


84
85
86
87
88
# File 'lib/amazonian.rb', line 84

def self.asin(asin, params={})
  params = params.merge :Operation => :ItemLookup, :ItemId => asin
  xml    = self.call params
  Item.new xml['ItemLookupResponse']['Items']['Item']
end

.search(query, params = {}) ⇒ Amazonian::Search

Perform a search query to the API. This is basically the same thing as searching with the Amazon website.

Parameters:

  • The (String)

    search query

  • Additional (Hash)

    options to be passed to the API

  • params (Hash) (defaults to: {})

    a customizable set of options

Options Hash (params):

  • :Operation (Symbol)

    defaults to :ItemSearch

  • :Keywords (Symbol)

    defaults to the passed search query

Returns:

  • (Amazonian::Search)

    Representing the response from the API. Items returned by the search query are represented as Amazonian::Item inside Amazonian::Search

See Also:

  • more information on the parameters the API accepts, see http://docs.amazonwebservices.com/AWSEcommerceService/4-0/


104
105
106
107
108
109
110
111
112
# File 'lib/amazonian.rb', line 104

def self.search(query, params={})
  params = params.merge :Operation => :ItemSearch,
                        :Keywords => query

  params[:SearchIndex] = @default_search if params[:SearchIndex].nil?

  xml = self.call params
  Search.new xml['ItemSearchResponse']
end

.setup {|amazonian| ... } ⇒ Object

Configure the basic request parameters for Amazonian.

Pass in a block with 1 parameter and modify configuration variables from there.

Examples:

require 'Amazonian'
Amazonian.setup do |ama|
  ama.key            = "my awesome key for AWS"
  ama.secret         = "super secret secret key for AWS"
  ama.debug          = true
  ama.default_search = :Music
  ama.cache_last     = false
end

Yields:

  • (amazonian)

    Configuration code block.



68
69
70
# File 'lib/amazonian.rb', line 68

def self.setup
  yield self if block_given?
end