RakutenWebService
This gem provides a client for easily accessing Rakuten Web Service APIs.
日本語のドキュメントはこちら。
Table of Contents
Prerequisite
Installation
Add this line to your application's Gemfile:
gem 'rakuten_web_service'
And then execute:
bundle
Or install it yourself as:
gem install rakuten_web_service
Usage
Prerequisite: Getting Application ID
You need to get Application ID for your application to access to Rakuten Web Service APIs.
If you have not got it, register your application here.
Configuration
At first, you have to specify your application's key. And you can tell the client your afiiliate id with RakutenWebService.configure
.
In Your Code
RakutenWebService.configure do |c|
c.application_id = 'YOUR_APPLICATION_ID'
c.affiliate_id = 'YOUR_AFFILIATE_ID'
c.max_retries = 3
c.debug = true
end
Please note that you need to replace 'YOUR_APPLICATION_ID'
and 'YOUR_AFFILIATE_ID'
with actual ones you have.
Environment Variables
You can configure application_id
and affiliate_id
by defining environment variables RWS_APPLICATION_ID
and RWS_AFFILIATE_ID
.
Search Ichiba Items
items = RakutenWebService::Ichiba::Item.search(keyword: 'Ruby')
items.first(10).each do |item|
puts "#{item['itemName']}, #{item.price} yen"
end
Responses of resources' search
such as RakutenWebService::Ichiba::Item.search
have methods for paginating fetched resources.
items = RakutenWebService::Ichiba::Item.search(keyword: 'Ruby')
items.count
last_items = items.page(3)
while last_items.next_page?
last_items = last_items.next_page
end
last_items.each do |item|
puts item.name
end
items.page(3).all do |item|
puts item.name
end
Genre
Genre class provides an interface to traverse sub genres.
root = RakutenWebService::Ichiba::Genre.root
root.children.each do |child|
puts "[#{child.id}] #{child.name}"
end
RakutenWebService::Ichiba::Genre[100316].name
Ichiba Item Ranking
ranking_by_age = RakutenWebService::Ichiba::Item.ranking(age: 30, sex: 1)
ranking_by_age.each do |ranking|
puts item.name
end
ranking_by_genre = RakutenWebService::Ichiba::Genre[200162].ranking
ranking_by_genre.each do |ranking|
puts item.name
end
Recipe
categories = RakutenWebService::Recipe.small_categories
categories.each do |category|
category.name
end
recipes = categories.first.ranking
recipes.each do |recipe|
recipe.title
end
Supported APIs
Now rakuten_web_service is supporting the following APIs:
Rakuten Ichiba APIs
Rakuten Books APIs
Rakuten Kobo APIs
Rakuten Recipe APIs
Rakuten GORA APIs
Rakuten Travel APIs
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request