• Stars
    star
    556
  • Rank 80,098 (Top 2 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 14 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Amazon Product Advertising API in Ruby

Vacuum

Build Maintainability Test Coverage

Vacuum is a Ruby wrapper to Amazon Product Advertising API 5.0. The API provides programmatic access to query product information on the Amazon marketplaces.

Cart Form functionality is not covered by this gem but is a primary focus on carriage gem

You need to register first to use the API.

vacuum

Usage

Getting Started

Create a request with your marketplace credentials. Set the marketplace by passing its two-letter country code.

request = Vacuum.new(marketplace: 'US',
                     access_key: '<ACCESS_KEY>',
                     secret_key: '<SECRET_KEY>',
                     partner_tag: '<PARTNER_TAG>')

You can now access the API using the available operations.

response = request.search_items(title: 'lean startup')
puts response.to_h

Create a persistent connection to make multiple requests.

request.persistent

Operations

Refer to the API docs for more detailed information.

GetBrowseNodes

Given a BrowseNodeId, the GetBrowseNodes operation returns details about the specified browse node, like name, children and ancestors, depending on the resources specified in the request. The names and browse node IDs of the children and ancestor browse nodes are also returned. GetBrowseNodes enables you to traverse the browse node hierarchy to find a browse node.

request.get_browse_nodes(
  browse_node_ids: ['283155', '3040'],
  resources: ['BrowseNodes.Ancestor', 'BrowseNodes.Children']
)

GetItems

Given an Item identifier, the GetItems operation returns the item attributes, based on the resources specified in the request.

request.get_items(
  item_ids: ['B0199980K4', 'B000HZD168', 'B01180YUXS', 'B00BKQTA4A'],
  resources: ['Images.Primary.Small', 'ItemInfo.Title', 'ItemInfo.Features',
              'Offers.Summaries.HighestPrice' , 'ParentASIN']
)

GetVariations

Given an ASIN, the GetVariations operation returns a set of items that are the same product, but differ according to a consistent theme, for example size and color. These items which differ according to a consistent theme are called variations. A variation is a child ASIN. The parent ASIN is an abstraction of the children items. For example, a shirt is a parent ASIN and parent ASINs cannot be sold. A child ASIN would be a blue shirt, size 16, sold by MyApparelStore. This child ASIN is one of potentially many variations. The ways in which variations differ are called dimensions.

request.get_variations(
  asin: 'B00422MCUS',
  resources: ['ItemInfo.Title', 'VariationSummary.Price.HighestPrice',
              'VariationSummary.Price.LowestPrice',
              'VariationSummary.VariationDimension']
)

SearchItems

The SearchItems operation searches for items on Amazon based on a search query. The API returns up to ten items per search request.

request.search_items(keywords: 'harry potter')

Response

Consume a response by parsing it into a Ruby hash.

response.to_h

You can also #dig into this hash.

response.dig('ItemsResult', 'Items')

Logging

Write requests and reponses to a logger using the logging feature of the HTTP gem under the hood:

require 'logger'

logger = Logger.new(STDOUT)
request.use(logging: {logger: logger})

Bring your parser

You can extend Vacuum with a custom parser. Just swap the original with a class or module that responds to .parse.

response.parser = MyParser
response.parse

If no custom parser is set, Vacuum::Response#parse delegates to #to_h.

VCR

If you are using VCR to test an app that accesses the API, you can use the custom VCR matcher of Vacuum to stub requests.

require 'vacuum/matcher'

# in your test
VCR.insert_cassette('cassette_name',
                    match_requests_on: [Vacuum::Matcher])

In RSpec, use the :paapi metadata.

require 'vacuum/matcher'

#ย in your test
it 'queries Amazon', :paapi do
end

Development

Clone the repo and install dependencies.

bundle install

Tests and Rubocop should now pass as-is.

bundle exec rake

By default, the tests stub requests. Use the RECORD env var to record new interactions.

RECORD=true bundle exec rake test

You can set the LIVE env var to run all tests against live data.

LIVE=true bundle exec rake test

In either case, add actual API credentials to a locales.yml file under test.

Getting Help

More Repositories

1

frankfurter

๐Ÿ’ฑ Foreign exchange API that wraps currency data provided by the ECB
Ruby
473
star
2

country

IP-to-country geolocation API
JavaScript
159
star
3

structure

Lazy-parse data into thread-safe, memoized attributes
Ruby
29
star
4

google-book

A Ruby wrapper to the Google Book Search Data API
Ruby
27
star
5

jeff

Minimum-viable Amazon Web Services client
Ruby
24
star
6

ebay-ruby

Ruby wrapper to the eBay APIs
Ruby
21
star
7

bookland

Provides EAN, ISBN, and ASIN classes in Ruby
Ruby
17
star
8

mws-orders

A Ruby interface to the Amazon MWS Orders API
Ruby
15
star
9

turnpike

A Redis-backed FIFO queue
Ruby
11
star
10

net-http-local

[mort] Binds a Net::HTTP request to a specified local address and port
Ruby
8
star
11

hoover

A Node.js wrapper to the Amazon Product Advertising API
CoffeeScript
7
star
12

throttler

Rate-limits code execution across threads or processes on a server
Ruby
6
star
13

ean

A minimal EAN and ISBN implementation in JavaScript
CoffeeScript
5
star
14

crack

Really simple XML parsing
CoffeeScript
4
star
15

certainty

An object that represents truth
Ruby
4
star
16

craft

Ruby
3
star
17

double

Double allows you to use a constant before it is defined when metaprogramming
Ruby
3
star
18

bezos

A utility library that signs requests to various Amazon APIs
CoffeeScript
2
star
19

brian-eno-oblique-strategies

Ruby
2
star
20

twitter-list-curator

Auto-curates topical Twitter lists by scraping Lanyrd
Ruby
2
star
21

vimeo-portfolio

Video portfolio with Vimeo as backend
JavaScript
1
star
22

the-placeholder-site

HTML
1
star
23

powells

Powells.com API wrapper
Ruby
1
star
24

bookdepository

Ruby
1
star
25

firstratedata

Jupyter Notebook
1
star