Giter Site home page Giter Site logo

vacuum's Introduction

Vacuum

Travis

Vacuum is a fast, light-weight Ruby wrapper to the Amazon Product Advertising API.

vacuum

Amazon is a $250 billion dollar company that reacts to you buying a vacuum by going THIS GUY LOVES BUYING VACUUMS HERE ARE SOME MORE VACUUMS

@kibblesmith

Usage

Prerequisite

Your Access Id must be registered for the Amazon Product Advertising API. Use the AccessKey Id obtained after registering at https://affiliate-program.amazon.com/gp/flex/advertising/api/sign-in.html

Setup

Create a request:

request = Vacuum.new

The locale will default to the US. To use another locale, reference its two-letter country code:

request = Vacuum.new('GB')

Configure the request credentials:

request.configure(
    aws_access_key_id: 'key',
    aws_secret_access_key: 'secret',
    associate_tag: 'tag'
)

You can omit the above if you set your key and secret as environment variables:

export AWS_ACCESS_KEY_ID=key
export AWS_SECRET_ACCESS_KEY=secret

You will still need to set an associate tag:

request.associate_tag = 'tag'

Provided you are looking to earn commission, you have to register independently with each locale you query. Otherwise, you may reuse any dummy associate tag.

The API version defaults to 2013-08-01. To use another version, reference its date string:

request.version = '2011-08-01'

Request

Browse Node Lookup

BrowseNodeLookup returns a specified browse node’s name and ancestors:

response = request.browse_node_lookup(
  query: {
    'BrowseNodeId' => 123
  }
)

Cart Operations

The CartCreate operation creates a remote shopping cart:

response = request.cart_create(
  query: {
    'HMAC' => 'secret',
    'Item.1.OfferListingId' => '123',
    'Item.1.Quantity' => 1
  }
)

The CartAdd operation adds items to an existing remote shopping cart:

response = request.cart_add(
  query: {
    'CartId' => '123',
    'HMAC' => 'secret',
    'Item.1.OfferListingId' => '123',
    'Item.1.Quantity' => 1
  }
)

The CartClear operation removes all of the items in a remote shopping cart:

response = request.cart_clear(
  query: {
    'CartId' => '123',
    'HMAC' => 'secret'
  }
)

The CartGet operation retrieves the IDs, quantities, and prices of the items, including SavedForLater ones, in a remote shopping cart:

response = request.cart_get(
  query: {
    'CartId' => '123',
    'HMAC' => 'secret',
    'CartItemId' => '123'
  }
)

Item Lookup

The ItemLookup operation returns some or all of the attributes of an item, depending on the response group specified in the request. By default, the operation returns an item’s ASIN, manufacturer, product group, and title.

response = request.item_lookup(
  query: {
    'ItemId' => '0679753354'
  }
)

Item Search

The ItemSearch operation returns items that satisfy the search criteria, including one or more search indices.

response = request.item_search(
  query: {
    'Keywords' => 'Architecture',
    'SearchIndex' => 'Books'
  }
)

Similarity Lookup

The SimilarityLookup operation returns up to ten products per page that are similar to one or more items specified in the request. This operation is typically used to pique a customer’s interest in buying something similar to what they’ve already ordered.

response = request.similarity_lookup(
  query: {
    'ItemId' => '0679753354'
  }
)

Configuring a request

Vacuum wraps Excon. Use the latter's API to tweak your request.

For example, to use a persistent connection:

response = request.item_search(
  query: {
    'ItemId' => '0679753354'
  },
  persistent: true
)

Response

The quick and dirty way to consume a response is to parse it into a Ruby hash:

response.to_h

In production, you may prefer to use a custom parser to do some XML heavy-lifting:

class MyParser
  # A parser has to respond to this.
  def self.parse(body)
    new(body)
  end

  def initialize(body)
    @body = body
  end

  # Implement parser here.
end

response.parser = MyParser
response.parse

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

vacuum's People

Contributors

hakanensari avatar ezkl avatar gerhard avatar bruno-campos avatar laszpio avatar cambridgemike avatar christophebelpaire avatar heathnaylor avatar jmoon90 avatar snoblenet avatar aisensiy avatar ryanmarshall avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.