Module: ASIN

Defined in:
lib/asin/client.rb,
lib/asin.rb,
lib/asin/version.rb,
lib/asin/simple_cart.rb,
lib/asin/simple_item.rb,
lib/asin/simple_node.rb,
lib/asin/configuration.rb

Overview

ASIN (Amazon Simple INterface) is a gem for easy access of the Amazon E-Commerce-API. It is simple to configure and use. Since it’s very small and flexible, it is easy to extend it to your needs.

Author

Peter Schröder ([email protected])

Usage

The ASIN module is designed as a mixin.

require 'asin'
include ASIN::Client

In order to use the Amazon API properly, you need to be a registered user (aws.amazon.com).

The registration process will give you a secret-key and an access-key (AWSAccessKeyId).

Both are needed to use ASIN (see Configuration for more details):

configure :secret => 'your-secret', :key => 'your-key'

After configuring your environment you can call the lookup method to retrieve an SimpleItem via the Amazon Standard Identification Number (ASIN):

item = lookup '1430218150'
item.first.title
=> "Learn Objective-C on the Mac (Learn Series)"

OR search with fulltext/ASIN/ISBN

items = search 'Learn Objective-C'
items.first.title
=> "Learn Objective-C on the Mac (Learn Series)"

The SimpleItem uses a Hashie::Mash as its internal data representation and you can get fetched data from it:

item.raw.ItemAttributes.ListPrice.FormattedPrice
=> "$39.99"

Further Configuration

If you need more controll over the request that is sent to the Amazon API (docs.amazonwebservices.com/AWSECommerceService/latest/DG/index.html), you can override some defaults or add additional query-parameters to the REST calls:

configure :host => 'webservices.amazon.de'
lookup(asin, :ResponseGroup => :Medium)

Cart

ASIN helps with AWS cart-operations. It currently supports the CartCreate, CartGet, CartAdd, CartModify and CartClear operations:

cart = create_cart({:asin => '1430218150', :quantity => 1})
cart.valid?
cart.items
=> true
=> [<#Hashie::Mash ASIN="1430218150" CartItemId="U3G241HVLLB8N6" ... >]

cart = get_cart('176-9182855-2326919', 'KgeVCA0YJTbuN/7Ibakrk/KnHWA=')
cart.empty?
=> false

cart = clear_cart(cart)
cart.empty?
=> true

cart = add_items(cart, {:asin => '1430216263', :quantity => 2})
cart.empty?
=> false

cart = update_items(cart, {:cart_item_id => cart.items.first.CartItemId, :action => :SaveForLater}, {:cart_item_id => cart.items.first.CartItemId, :quantity => 7})
cart.valid?
cart.saved_items
=> true
=> [<#Hashie::Mash ASIN="1430218150" CartItemId="U3G241HVLLB8N6" ... >]

Nodes

In order to browse Amazon nodes, you can use browse_node method:

node = browse_node('163357')
node.node_id
=> '163357'
node.name
=> 'Comedy'
node.children
node.ancestors

you can configure the :ResponseGroup option to your needs:

node = browse_node('163357', :ResponseGroup => :TopSellers)

Defined Under Namespace

Modules: Client Classes: Configuration, SimpleCart, SimpleItem, SimpleNode

Constant Summary collapse

VERSION =
"0.7.0"