Giter Site home page Giter Site logo

skatkov / carriage Goto Github PK

View Code? Open in Web Editor NEW
8.0 5.0 2.0 791 KB

Carriage is a Ruby wrapper to Amazon's Cart Form functionality

Home Page: https://skatkov.github.io/carriage/

License: MIT License

Ruby 98.39% Shell 1.61%
product-advertising-api amazon amazon-associates paapi5 amazon-cart

carriage's Introduction

Gem Version Maintainability Build Status

Carriage

Carriage project logo

Carriage is a Ruby wrapper to Amazon's Cart Form functionality. Gem helps add any number of items to customer's shopping cart and direct him to Amazon website to complete order.

To use this gem, you will eventually require Amazon's AssociateTag, so consider to register first with Amazon Associate program and become more familiar with it.

Programmatic access to product data is out of scope for this gem, but I recommend to use vacuum gem if there is such a need.

Battle tested at aShop

Installation

Add this line to your application's Gemfile:

gem 'carriage'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install carriage

Usage

A lot of examples could be found in tests

There are basically two ways to use this gem bare metal and with builder. Let's start off with baremetal:

Bare metal

Carriage.call(:us, {
  AssociateTag:'tag', 
  "OfferListingId.1": "B00WR23X5I", 
  "Quantity.1": 1 
 }
)

The only thing it will validate, is a presence of locale. All other parameters will be converted by URI.encode_www_form without any verification. Be carefull!

Builder

Library also offers a simpler interface that tries to valide data with convinince methods on top.

items = [
 {Id: '123123'}.
 {ASIN: '1231234', quantity: 2}
]

Carriage.build(items, tag: 'my_attribution_tag', locale: :uk)
  • Every item should be a hash, with ASIN or ID (short for OfferListingId) key provided. All keys are case insensitive.
  • By default quantity is 1, feel free to rewrite that.
  • Carriage.build also requires :tag attribute (short for AssociateTag)
  • Defaults to locale: :us, if no other locale was provided.

Locale

All locale are based on a two letter country codes - ISO 3166-1 alpha-2. Here is an exact mapping:

https://github.com/skatkov/carriage/blob/master/lib/carriage/locale.rb#L7-L23

Getting help

Credits

Logo was done by Max Kazmin

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Carriage project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

carriage's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

carriage's Issues

Start using `URI.encode_www_form` in code

E.g. (from the Ruby docs in 1.9.3):

URI.encode_www_form([["q", "ruby"], ["lang", "en"]])
#=> "q=ruby&lang=en"
URI.encode_www_form("q" => "ruby", "lang" => "en")
#=> "q=ruby&lang=en"
URI.encode_www_form("q" => ["ruby", "perl"], "lang" => "en")
#=> "q=ruby&q=perl&lang=en"
URI.encode_www_form([["q", "ruby"], ["q", "perl"], ["lang", "en"]])
#=> "q=ruby&q=perl&lang=en"

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.