Low commit activity in last 3 years
No release in over a year
Client for Rakutenmarketing.com.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 11

Runtime

~> 1.13, >= 1.13.6
 Project Readme

RakutenProductApi

To experiment with this library, run bin/console for an interactive prompt.

API Documentation

The Rakuten Product API documentation can be found at the following links.

Installation

Add this line to your application's Gemfile:

gem 'rakuten_product_api'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install rakuten_product_api

Usage

The library comes with bin/console which can be used to explore the client and api. If there is a local ./config.rb the console script will load it.

To configured the library for Rails, create an initializer file config/initializers/rakuten.rb

RakutenProductApi.configure do |config|
  config.sid             = 'your-site-id'
  config.client_id       = 'your-client-id'
  config.client_secret   = 'your-client-secret'
end

Once you have configured the library, you can create a client.

client = RakutenProductApi::Client.new

client.sid
=> "your-site-id"

This client should be threadsafe. Configuration values are local to your instance.

Authentication

This library needs to query the API to retreive an access_token which has an access_token_expires_at time, prior to which, the library will refresh the token

You can initialise the library with the access_token and access_token_expires_at values to avoid this lookup. If the access_token_expires_at is nil or in the past, the library will fetch the value so you can safely cache this value and use it without checking it's expiry.

client = RakutenProductApi::Client.new(access_token: 'abcd1234', access_token_expires_at: 1613362973)

client.endpoint
=> "https://api.linksynergy.com"

client.access_token
=> "abcd1234"

Querying

Search for keywords:

You can specify which merchants to query by using mid paramater. For example Kobo Australia would be: mid: 38131

results = client.search(keyword: 'Murderbot', mid: 38131)
results.items.count
=> 7

results.items[0].merchant
=> "Rakuten Kobo Australia"

results.items[0].isbn
=> "9781250185464"

results.items[0].title
=> "Exit Strategy"

results.items[0].price
=> ["15.06", "AUD"]

results.items[0].rrp
=> ["18.70", "AUD"]

Search for ISBNs:

You can specify which merchants to query by using mid: 38131

results = client.search(keyword: '9781501977824', mid: 38131)
results.items[0].gtin
=> "9781501977824"
results.items[0].title
=> "All Systems Red"

The API also allows other attribute:

  • exact
  • one
  • none
  • sort & sorttype

When using sort, you must also use sorttype ( 'asc' or 'dsc'). See the documentation for more.

TODO

This library implement the parts I need. For example, it doesn't handle paging through results as I don't need it, but I'm happy to accept pull request.

Notes

  • ISBN is taken from either the sku or the keywords fields and mached against a regular expression /97[98]\d{10}/ as there's no specific field for it.
  • Condition is guessed by looking for the string "Used" in the description. This is a terrible idea, but there is no field for condition.
  • This library aliases rrp -> price and price -> saleprice. When sorting you need to use the original attribute names ( price / saleprice )

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 it automatically.

RakutenProductApi.configure do |config|
  config.sid             = 'your-site-id'
  config.username        = 'your-rakuten-username'
  config.password        = 'your-rakuten-password'
  config.consumer_key    = 'your-consumer-key'
  config.consumer_secret = 'your-consumer-secret'
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 the created tag, and push the .gem file to rubygems.org.

Contributing

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

License

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