Giter VIP home page Giter VIP logo

rws-ruby-sdk's Introduction

RakutenWebService

Build Status Gem Version

rakuten_web_serviceは、 Rubyから楽天が提供しているAPIに簡単にアクセスできるSDK(Software Development Kit)です。

English version is here.

インストール方法

bundlerを利用したアプリケーションの場合、Gemfileに以下の1行を追加します。

  gem 'rakuten_web_service'

そしてbundleコマンドでインストール。

$ bundle

もしくは、gemコマンドにより

$ gem install rakuten_web_service

とすることでインストールできます。

現在rakuten_web_serviceは下記のAPIをサポートしています。

楽天市場API

楽天ブックス系API

楽天Kobo系API

使用方法

設定

RakutenWebService.configuration メソッドを使い、Application IDとAffiliate ID(オプション)を指定することができます。

  RakutenWebService.configuration do |c|
    c.application_id = YOUR_APPLICATION_ID
    c.affiliate_id = YOUR_AFFILIATE_ID
  end

市場商品の検索

  items = RakutenWebService::Ichiba::Item.search(:keyword => 'Ruby') # This returns Enamerable object
  items.first(10).each do |item|
    puts "#{item['itemName']}, #{item.price} yen" # You can refer to values as well as Hash.
  end

ジャンル

Genreクラスは、childrenparentといったジャンル階層を辿るインターフェースを持っています。

  root = RakutenWebService::Ichiba::Genre.root # root genre
  # children returns sub genres
  root.children.each do |child|
    puts "[#{child.id}] #{child.name}"
  end

  # Use genre id to fetch genre object
  RakutenWebService::Ichiba::Genre[100316].name # => "水・ソフトドリンク"

市場商品ランキング

  RakutenWebService::Ichiba::Item.ranking(:age => 30, :sex => 0) # 30代男性 のランキングTOP 30
  RakutenWebService::Ichiba::Genre[100316].ranking # "水・ソフトドリンク" ジャンルのTOP 30

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

rws-ruby-sdk's People

Contributors

satoryu avatar

Watchers

 avatar  avatar

rws-ruby-sdk's Issues

サンプルコードでエラーが出た

~/sandbox/rakuten ⮀ ruby search_sample.rb
/Users/kazuhiro/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rakuten_web_service-0.6.2/lib/rakuten_web_service/client.rb:18:in `initialize': uninitialized constant RakutenWebService::Client::URI (NameError)
    from /Users/kazuhiro/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rakuten_web_service-0.6.2/lib/rakuten_web_service/search_result.rb:8:in `new'
    from /Users/kazuhiro/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rakuten_web_service-0.6.2/lib/rakuten_web_service/search_result.rb:8:in `initialize'
    from /Users/kazuhiro/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rakuten_web_service-0.6.2/lib/rakuten_web_service/resource.rb:29:in `new'
    from /Users/kazuhiro/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rakuten_web_service-0.6.2/lib/rakuten_web_service/resource.rb:29:in `search'
    from search_sample.rb:7:in `<main>'

ruby -v
ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]

README.md の設定が分かりにくい

RakutenWebService.configuration メソッドを使い、Application IDとAffiliate ID(オプション)を指定することができます。

「することが出来る」だとしなくてもいいのではないかという不安がある。

「することが出来ます」ではなく「する必要があります」が良いと思う。

README.md に typo

  items = RakutenWebService::Ichiba::Item.search(:keyword => 'Ruby') # This returns Enamerable object

not Enamerable but Enumerable

RakutenWebService::Books::Genre.new のテストが通らない

  1) RakutenWebService::Books::Genre.new given a genre id only call endpint only at the first time to initialize
     Failure/Error: @genre = RWS::Books::Genre.new(param)
     Faraday::ParsingError:
       757: unexpected token at '"{\"current\":{\"booksGenreId\":\"007\",\"booksGenreName\":\"DummyGenre\",\"genreLevel\":\"2\"}}"'
     # ./lib/rakuten_web_service/client.rb:26:in `get'
     # ./lib/rakuten_web_service/search_result.rb:55:in `query'
     # ./lib/rakuten_web_service/search_result.rb:17:in `each'
     # ./lib/rakuten_web_service/genre.rb:25:in `first'
     # ./lib/rakuten_web_service/genre.rb:25:in `new'
     # ./spec/rakuten_web_service/books/genre_spec.rb:70:in `block (3 levels) in <top (required)>'

テストが落ちる

RakutenWebService::Books::Genre

RakutenWebService::Books::Genre
  .search
    call the endpoint once (FAILED - 1)
    has interfaces like hash (FAILED - 2)
    has interfaces like hash with snake case key (FAILED - 3)
    has interfaces to get each attribute (FAILED - 4)
  .new
    given a genre id
      only call endpint only at the first time to initialize
  .root
    alias of constructor with the root genre id "000" (FAILED - 5)
  #children
    When get search method
      are Books::Genre objects (FAILED - 6)
    when the genre object has no children information
      call the endpoint to get children (FAILED - 7)
  #search
    if the genre_id starts with "001"
      delegate Books::Book.search (FAILED - 8)
    if the genre_id starts with "002"
      delegate Books::CD.search (FAILED - 9)
    if the genre_id starts with "003"
      delegate Books::DVD.search (FAILED - 10)
    if the genre_id starts with "004"
      delegate Books::Software.search (FAILED - 11)
    if the genre_id starts with "005"
      delegate Books::ForeignBook.search (FAILED - 12)
    if the genre_id starts with "006"
      delegate Books::Game.search (FAILED - 13)
    if the genre_id starts with "007"
      delegate Books::Magazine.search (FAILED - 14)

RakutenWebService::Kobo::Genre

RakutenWebService::Kobo::Genre
  .search
    call the endpoint once (FAILED - 15)
  #search
    Without arguments
      should call RWS::Kobo::Ebook.search with specifying genre id (FAILED - 16)
    With arguments
      should call RWS::Kobo::Ebook.search with given arguments and genre id (FAILED - 17)

Failures:

  1) RakutenWebService::Books::Genre.search call the endpoint once
     Failure/Error: to_return(:body => expected_json)
     WebMock::Response::InvalidBody:
       must be one of: [Proc, IO, Pathname, String, Array]. 'Hash' given
     # ./spec/rakuten_web_service/books/genre_spec.rb:27:in `block (2 levels) in <top (required)>'

  2) RakutenWebService::Books::Genre.search has interfaces like hash
     Failure/Error: to_return(:body => expected_json)
     WebMock::Response::InvalidBody:
       must be one of: [Proc, IO, Pathname, String, Array]. 'Hash' given
     # ./spec/rakuten_web_service/books/genre_spec.rb:27:in `block (2 levels) in <top (required)>'

  3) RakutenWebService::Books::Genre.search has interfaces like hash with snake case key
     Failure/Error: to_return(:body => expected_json)
     WebMock::Response::InvalidBody:
       must be one of: [Proc, IO, Pathname, String, Array]. 'Hash' given
     # ./spec/rakuten_web_service/books/genre_spec.rb:27:in `block (2 levels) in <top (required)>'

  4) RakutenWebService::Books::Genre.search has interfaces to get each attribute
     Failure/Error: to_return(:body => expected_json)
     WebMock::Response::InvalidBody:
       must be one of: [Proc, IO, Pathname, String, Array]. 'Hash' given
     # ./spec/rakuten_web_service/books/genre_spec.rb:27:in `block (2 levels) in <top (required)>'

  5) RakutenWebService::Books::Genre.root alias of constructor with the root genre id "000"
     Failure/Error: to_return(:body => expected_json)
     WebMock::Response::InvalidBody:
       must be one of: [Proc, IO, Pathname, String, Array]. 'Hash' given
     # ./spec/rakuten_web_service/books/genre_spec.rb:27:in `block (2 levels) in <top (required)>'

  6) RakutenWebService::Books::Genre#children When get search method are Books::Genre objects
     Failure/Error: to_return(:body => expected_json)
     WebMock::Response::InvalidBody:
       must be one of: [Proc, IO, Pathname, String, Array]. 'Hash' given
     # ./spec/rakuten_web_service/books/genre_spec.rb:27:in `block (2 levels) in <top (required)>'

  7) RakutenWebService::Books::Genre#children when the genre object has no children information call the endpoint to get children
     Failure/Error: to_return(:body => expected_json)
     WebMock::Response::InvalidBody:
       must be one of: [Proc, IO, Pathname, String, Array]. 'Hash' given
     # ./spec/rakuten_web_service/books/genre_spec.rb:27:in `block (2 levels) in <top (required)>'

  8) RakutenWebService::Books::Genre#search if the genre_id starts with "001" delegate Books::Book.search
     Failure/Error: to_return(:body => expected_json)
     WebMock::Response::InvalidBody:
       must be one of: [Proc, IO, Pathname, String, Array]. 'Hash' given
     # ./spec/rakuten_web_service/books/genre_spec.rb:27:in `block (2 levels) in <top (required)>'

  9) RakutenWebService::Books::Genre#search if the genre_id starts with "002" delegate Books::CD.search
     Failure/Error: to_return(:body => expected_json)
     WebMock::Response::InvalidBody:
       must be one of: [Proc, IO, Pathname, String, Array]. 'Hash' given
     # ./spec/rakuten_web_service/books/genre_spec.rb:27:in `block (2 levels) in <top (required)>'

  10) RakutenWebService::Books::Genre#search if the genre_id starts with "003" delegate Books::DVD.search
     Failure/Error: to_return(:body => expected_json)
     WebMock::Response::InvalidBody:
       must be one of: [Proc, IO, Pathname, String, Array]. 'Hash' given
     # ./spec/rakuten_web_service/books/genre_spec.rb:27:in `block (2 levels) in <top (required)>'

  11) RakutenWebService::Books::Genre#search if the genre_id starts with "004" delegate Books::Software.search
     Failure/Error: to_return(:body => expected_json)
     WebMock::Response::InvalidBody:
       must be one of: [Proc, IO, Pathname, String, Array]. 'Hash' given
     # ./spec/rakuten_web_service/books/genre_spec.rb:27:in `block (2 levels) in <top (required)>'

  12) RakutenWebService::Books::Genre#search if the genre_id starts with "005" delegate Books::ForeignBook.search
     Failure/Error: to_return(:body => expected_json)
     WebMock::Response::InvalidBody:
       must be one of: [Proc, IO, Pathname, String, Array]. 'Hash' given
     # ./spec/rakuten_web_service/books/genre_spec.rb:27:in `block (2 levels) in <top (required)>'

  13) RakutenWebService::Books::Genre#search if the genre_id starts with "006" delegate Books::Game.search
     Failure/Error: to_return(:body => expected_json)
     WebMock::Response::InvalidBody:
       must be one of: [Proc, IO, Pathname, String, Array]. 'Hash' given
     # ./spec/rakuten_web_service/books/genre_spec.rb:27:in `block (2 levels) in <top (required)>'

  14) RakutenWebService::Books::Genre#search if the genre_id starts with "007" delegate Books::Magazine.search
     Failure/Error: to_return(:body => expected_json)
     WebMock::Response::InvalidBody:
       must be one of: [Proc, IO, Pathname, String, Array]. 'Hash' given
     # ./spec/rakuten_web_service/books/genre_spec.rb:27:in `block (2 levels) in <top (required)>'

  15) RakutenWebService::Kobo::Genre.search call the endpoint once
     Failure/Error: to_return(:body => expected_json)
     WebMock::Response::InvalidBody:
       must be one of: [Proc, IO, Pathname, String, Array]. 'Hash' given
     # ./spec/rakuten_web_service/kobo/genre_spec.rb:23:in `block (2 levels) in <top (required)>'

  16) RakutenWebService::Kobo::Genre#search Without arguments should call RWS::Kobo::Ebook.search with specifying genre id
     Failure/Error: to_return(:body => expected_json)
     WebMock::Response::InvalidBody:
       must be one of: [Proc, IO, Pathname, String, Array]. 'Hash' given
     # ./spec/rakuten_web_service/kobo/genre_spec.rb:23:in `block (2 levels) in <top (required)>'

  17) RakutenWebService::Kobo::Genre#search With arguments should call RWS::Kobo::Ebook.search with given arguments and genre id
     Failure/Error: to_return(:body => expected_json)
     WebMock::Response::InvalidBody:
       must be one of: [Proc, IO, Pathname, String, Array]. 'Hash' given
     # ./spec/rakuten_web_service/kobo/genre_spec.rb:23:in `block (2 levels) in <top (required)>'

bundle install できない

 ~/sandbox/rakuten ⮀ bundle install
Your Gemfile has no gem server sources. If you need gems that are not already on
your machine, add a line like this to your Gemfile:
source 'https://rubygems.org'
Could not find gem 'rakuten_web_service (>= 0) ruby' in any of the gem sources
listed in your Gemfile or available on this machine.

書いたとおりにやってもダメだった
(bundle の設定が悪い?)

RakutenWebService::Books::Genre.search のテストを通す

  1) RakutenWebService::Books::Genre.search call the endpoint once
     Failure/Error: to_return(:body => expected_json)
     WebMock::Response::InvalidBody:
       must be one of: [Proc, IO, Pathname, String, Array]. 'Hash' given
     # ./spec/rakuten_web_service/books/genre_spec.rb:27:in `block (2 levels) in <top (required)>'

  2) RakutenWebService::Books::Genre.search has interfaces like hash
     Failure/Error: to_return(:body => expected_json)
     WebMock::Response::InvalidBody:
       must be one of: [Proc, IO, Pathname, String, Array]. 'Hash' given
     # ./spec/rakuten_web_service/books/genre_spec.rb:27:in `block (2 levels) in <top (required)>'

  3) RakutenWebService::Books::Genre.search has interfaces like hash with snake case key
     Failure/Error: to_return(:body => expected_json)
     WebMock::Response::InvalidBody:
       must be one of: [Proc, IO, Pathname, String, Array]. 'Hash' given
     # ./spec/rakuten_web_service/books/genre_spec.rb:27:in `block (2 levels) in <top (required)>'

  4) RakutenWebService::Books::Genre.search has interfaces to get each attribute
     Failure/Error: to_return(:body => expected_json)
     WebMock::Response::InvalidBody:
       must be one of: [Proc, IO, Pathname, String, Array]. 'Hash' given
     # ./spec/rakuten_web_service/books/genre_spec.rb:27:in `block (2 levels) in <top (required)>'

it fails

RakutenWebService::Kobo::Genreのテストが通らない

  2) RakutenWebService::Kobo::Genre.search call the endpoint once
     Failure/Error: to_return(:body => expected_json)
     WebMock::Response::InvalidBody:
       must be one of: [Proc, IO, Pathname, String, Array]. 'Hash' given
     # ./spec/rakuten_web_service/kobo/genre_spec.rb:23:in `block (2 levels) in <top (required)>'

  3) RakutenWebService::Kobo::Genre#search Without arguments should call RWS::Kobo::Ebook.search with specifying genre id
     Failure/Error: to_return(:body => expected_json)
     WebMock::Response::InvalidBody:
       must be one of: [Proc, IO, Pathname, String, Array]. 'Hash' given
     # ./spec/rakuten_web_service/kobo/genre_spec.rb:23:in `block (2 levels) in <top (required)>'

  4) RakutenWebService::Kobo::Genre#search With arguments should call RWS::Kobo::Ebook.search with given arguments and genre id
     Failure/Error: to_return(:body => expected_json)
     WebMock::Response::InvalidBody:
       must be one of: [Proc, IO, Pathname, String, Array]. 'Hash' given
     # ./spec/rakuten_web_service/kobo/genre_spec.rb:23:in `block (2 levels) in <top (required)>'

#7 と同様の解決方法で行けた

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.