Code Monkey home page Code Monkey logo

paapi's Introduction

Paapi

paapi is a slim wrapper around Amazon's Product Advertising API 5.0.

Build Status

If this gem doesn't meet your needs, try the Vacuum gem.

Installation

Add this line to your application's Gemfile:

gem 'paapi'

And then execute:

$ bundle

Or install it yourself as:

$ gem install paapi

Usage

Configuration

The library can be configured with an initializer. For Rails, create the file config/initializers/paapi.rb

Paapi.configure do |config|
  config.access_key = 'your-access-key'
  config.secret_key = 'your-secret-key'
  config.partner_tag = 'your-tag'
end

Configurable items:

  • access_key
  • secret_key
  • partner_tag
  • partner_type
  • market
  • partner_market
  • test_mode

Using the partner_market configuration item lets you set a hash of marketplaces and partner_tags.

Paapi.configure do |config|
  config.access_key = 'your-access-key'
  config.secret_key = 'your-secret-key'
  config.partner_market = {au: 'au_partner_tag', us: 'us_partner_tag'}
end

client = Paapi::Client.new(market: :au)

client.partner_tag
> 'au_partner_tag'

client.market = :us

client.partner_tag
> 'us_partner_tag'

The full list of market keys is au, br, ca, fr, de, in, it, jp, mx, es, tr, ae, uk, us

Using Paapi

require 'paapi'

client = Paapi::Client.new(access_key: ENV['access_key'], secret_key: ENV['secret_key'], market: :au, partner_tag: ENV['partner_tag'])

gi = client.get_items(item_ids: '1857231384')

si = client.search_items(keywords: 'Harry Potter')

gv = client.get_variations(asin: 'B00422MCUS')

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

If you create a file config.rb, it will be loaded by bin/console, allowing you to configure keys and markets.

Paapi.configure do |config|
  config.access_key = 'access_key'
  config.secret_key = 'secret_key'
  config.partner_market =  {au: 'au_tag', us: 'us_tag', uk: 'uk_tag', ca: 'ca_tag_'}
end

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/dkam/paapi.

License

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

paapi's People

Contributors

crisdias avatar dkam avatar ezaki3 avatar seadfeng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

paapi's Issues

Can't get authors data

Hello, this gem is so nice to use PA API.
But I couldn't get authors data by using authors method like "item.authors".

I checked this paapi file, and I guess there is room for improvement.

When I request book data (market is jp), the request about authors is like as below

 "ItemInfo"=>
    {"ByLineInfo"=>
      {"Contributors"=>
        [{"Locale"=>"ja_JP", "Name"=>"###", "Role"=>"่‘—", "RoleType"=>"author"},

but item.rb file is like as below

  def contributors_of(kind)
      kind = kind.to_s.gsub(/([[:alpha:]]+)/) { |w| w.capitalize }
      contributors.select { |e| e['Role'] == kind }&.map { |e| e.dig('Name') }&.reject {|n| n.to_s.empty?}
  end

  def authors
      contributors_of 'Author'
  end

so I think you might want to change like as below

  def contributors_of(kind)
      kind = kind.to_s.gsub(/([[:alpha:]]+)/) { |w| w.capitalize }
      contributors.select { |e| e['RoleType'] == kind }&.map { |e| e.dig('Name') }&.reject {|n| n.to_s.empty?}
  end

  def authors
      contributors_of 'author'
  end

I would greatly appreicate if you can give our proposal a good review.

Comma missing @ paapi.rb MARKETPLACE definitions

Hey there!I found a bug, a missing comma next to the Brazil definition (lib/pappi.rb, line 45) that was causing requests to this region to fail. I tried to push a request to github with the change but I am a total noob when it comes to helping projects on github.

Thanks for the great gem!

Can't load rails console

Hello, I know that the gem is currently under development but when installing it, and opening a rails console, an error: cannot load such file -- paapi/locales (LoadError). Do you have any idea why is it throwing that error?

Maybe let's join forces to update vacuum gem?

I've been looking if anyone has attempted to write a ruby wrapper for new PA-API and found your library. Great work, thanks for building this in an open.

I reviewed your code, but I don't think this library will fit my use-case:

  • It's really hard to come up with response object parser that fits everyone's use case.
  • I didn't felt like having yeat-another-http-adapter to increase my projects dependency (so i opted for HTTPi , so anyone can roll with their own adapter)
  • It seems, that providing DEFAULT_RESOURCE or modifying resources within a library is again, quite a opinionated move that will not fit every usecase

In my personal opinion, Vacuum was almost-perfect implementation for PA-API version 4 and had quite a following already. I attempted to re-implement Vacuum in this pull request:
hakanensari/vacuum#78

I'd love to get your input. Maybe you'll be in helping re-implement gem that already has heavily usage? :-)

Thanks again!

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.