Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Amazon Simple INterface - Simple ItemLookup for Amazon E-Commerce
Ruby
tree: 53475aaf74

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
spec
.document
.gitignore
.rvmrc
.travis.yml
Gemfile
Gemfile.lock
README.rdoc
asin.gemspec
rakefile.rb

README.rdoc

Installation

Status:

The gem is tested against 1.9.2 and 1.8.7 (compatibility with Heroku-Bamboo-Stack) and runs smoothly with Rails 3.

gem install asin
gem install httpclient # optional, see HTTPI

Configuration

Rails style initializer (config/initializers/asin.rb):

ASIN::Configuration.configure do |config|
  config.secret = 'your-secret'
  config.key = 'your-key'
end

YAML style configuration:

ASIN::Configuration.configure :yaml => 'config/asin.yml'

Inline style configuration:

ASIN::Configuration.configure :secret => 'your-secret', :key => 'your-key'
# or
client.configure :secret => 'your-secret', :key => 'your-key'

Usage

ASIN is designed as a module, so you can include it into any object you like:

# require and include
require 'asin'
include ASIN

# lookup an ASIN
lookup '1430218150'

But you can also use the client method to get a client-object:

# just require
require 'asin'

# create an ASIN client
client = ASIN.client

# lookup an item with the amazon standard identification number (asin)
item = client.lookup '1430218150'

# have a look at the title of the item
item.title
=> Learn Objective-C on the Mac (Learn Series)

# search for any kind of stuff on amazon with keywords
items = search_keywords 'Learn', 'Objective-C'
items.first.title
=> "Learn Objective-C on the Mac (Learn Series)"

# search for any kind of stuff on amazon with custom parameters
search :Keywords => 'Learn Objective-C', :SearchIndex => :Books
items.first.title
=> "Learn Objective-C on the Mac (Learn Series)"

# access the internal data representation (Hashie::Mash)
item.raw.ItemAttributes.ListPrice.FormattedPrice
=> $39.99

There is an additional set of methods to support AWS cart operations:

#just require
require 'asin'

# create a cart with an item
cart = create_cart({:asin => '1430218150', :quantity => 1})
cart.items
=> [<#Hashie::Mash ASIN="1430218150" CartItemId="U3G241HVLLB8N6" ... >]

# get an already existing cart from a CartId and HMAC
cart = get_cart('176-9182855-2326919', 'KgeVCA0YJTbuN/7Ibakrk/KnHWA=')
cart.empty?
=> false

# clear everything from the cart
cart = clear_cart(cart)
cart.empty?
=> true

# add items to the cart
cart = add_items(cart, {:asin => '1430216263', :quantity => 2})
cart.empty?
=> false

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

HTTPI

ASIN uses HTTPI as a HTTP-Client adapter. See the HTTPI documentation for how to configure different clients or the logger. As a default HTTPI uses httpclient so you should add that dependency to your project:

gem 'httpclient'

Infos

Have a look at the RDOC for this project, if you want further information.

For more information on the REST calls, have a look at the whole Amazon E-Commerce-API.

The code currently runs best on Ruby-1.9 due to encoding issues with the Amazon REST output (if YOU know how to backport this to 1.8.7, you are welcome!).

Something went wrong with that request. Please try again.