laszpio / sucker

A Ruby wrapper to the Amazon Product Advertising API

Home Page:http://gloss.papercavalier.com/sucker

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sucker

Sucker is a minimal Ruby wrapper to the Amazon Product Advertising API. It runs on curb and the Nokogiri implementation of the XML Mini module in Active Support. It's fast and supports the entire API.

Electrolux

Examples

Set up a worker.

worker = Sucker.new(
  :locale => "us",
  :key    => "API KEY",
  :secret => "API SECRET")

Prepare a request.

asin_batch = %w{
  0816614024 0143105825 0485113600 0816616779 0942299078
  0816614008 144006654X 0486400360 0486417670 087220474X }
worker << {
  "Operation"     => "ItemLookup",
  "IdType"        => "ASIN",
  "ItemId"        => asin_batch,
  "ResponseGroup" => ["ItemAttributes", "OfferFull"] }

Perform the request.

response = worker.get

Debug.

p response.valid?,
  response.code,
  response.time,
  response.body,
  response.xml,
  response.to_hash

Iterate over items in your item lookup.

response.each("Item") { |item| ... }

Map errors to a block.

errors = response.map("Error") { |error| ... }

Or simply get a hash of matching items.

items = response.find("Item")

Repeat ad infinitum.

Check my integration specs for more examples. See twenty items and multiple locales for relatively advanced usage.

Last but not least, dive into the API docs to construct your own queries.

Stubbing

Use VCR to stub your requests.

Caveat: Match URIs on host only and create a new cassette for each query. This is how my VCR helper looks like.

Compatibility

Specs pass against Ruby 1.8.7 and Ruby 1.9.2.

Sucker works seamlessly with or without Rails.

About

A Ruby wrapper to the Amazon Product Advertising API

http://gloss.papercavalier.com/sucker

License:MIT License