xwmx / vacuum

A Ruby wrapper to the Amazon Product Advertising API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Vacuum

![vacuum] 1

[![travis] 2] 3

Vacuum is a Nokogiri-backed Ruby wrapper to the [Amazon Product Advertising API] 5.

## Installation

Add to your Gemfile:

gem 'vacuum'

## Configuration

Set up a locale:

Vacuum.configure :uk do |c|
  c.key    = 'a key'
  c.secret = 'a secret'
  c.tag    = 'a tag'
end

If you do not specify a locale, Vacuum will default to the US:

Vacuum.configure do |c|
  c.key    = 'a key'
  c.secret = 'a secret'
  c.tag    = 'a tag'
end

## The Request

Create a request for the above locale:

req = Vacuum.new(:uk)

Again, if you don't specify a locale, the request will default to the US:

req = Vacuum.new

Search for something:

req << { :operation    => 'ItemSearch',
         :search_index => 'All',
         :keywords     => 'George Orwell' }
res = request.get

The following shorthand accomplishes the same search:

res = req.search('George Orwell')

Customise your request:

res = req.search('Books', :response_group => 'ItemAttributes',
                          :power          => 'George Orwell'

For all available methods and syntax, [read here] 6.

The Response

Check if the response is valid:

res.valid?

While it sounds quirky, a valid response may contain errors. Check for those as well:

res.has_errors?

Consume the entire response as a hash:

res.to_hash

Preferably, drop down to a particular node and consume the relevant bits and pieces you need:

res.each('Item') do |item|
  # item['ASIN']
end

About

A Ruby wrapper to the Amazon Product Advertising API

License:MIT License