rakuten_web_service 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +6 -14
  2. data/.gitignore +1 -0
  3. data/.travis.yml +0 -4
  4. data/README.en.md +19 -2
  5. data/README.md +18 -3
  6. data/lib/rakuten_web_service.rb +4 -13
  7. data/lib/rakuten_web_service/books.rb +11 -0
  8. data/lib/rakuten_web_service/books/book.rb +29 -0
  9. data/lib/rakuten_web_service/books/cd.rb +25 -0
  10. data/lib/rakuten_web_service/books/dvd.rb +25 -0
  11. data/lib/rakuten_web_service/books/foreign_book.rb +24 -0
  12. data/lib/rakuten_web_service/books/game.rb +25 -0
  13. data/lib/rakuten_web_service/books/genre.rb +66 -0
  14. data/lib/rakuten_web_service/books/magazine.rb +26 -0
  15. data/lib/rakuten_web_service/books/resource.rb +52 -0
  16. data/lib/rakuten_web_service/books/software.rb +25 -0
  17. data/lib/rakuten_web_service/books/total.rb +16 -0
  18. data/lib/rakuten_web_service/ichiba.rb +7 -0
  19. data/lib/rakuten_web_service/ichiba/genre.rb +27 -20
  20. data/lib/rakuten_web_service/ichiba/item.rb +6 -4
  21. data/lib/rakuten_web_service/ichiba/ranking.rb +3 -2
  22. data/lib/rakuten_web_service/ichiba/shop.rb +3 -0
  23. data/lib/rakuten_web_service/resource.rb +29 -6
  24. data/lib/rakuten_web_service/search_result.rb +34 -1
  25. data/lib/rakuten_web_service/version.rb +1 -1
  26. data/rakuten_web_service.gemspec +1 -0
  27. data/spec/fixtures/books/book_search_with_keyword_Ruby.json +1 -0
  28. data/spec/fixtures/books/cd_search_with_keyword_Ruby.json +1 -0
  29. data/spec/fixtures/books/dvd_search_with_keyword_Ruby.json +1 -0
  30. data/spec/fixtures/books/foreign_book_search_with_keyword_Ruby.json +1 -0
  31. data/spec/fixtures/books/game_search_with_keyword_Ruby.json +1 -0
  32. data/spec/fixtures/books/genre_search.json +1 -0
  33. data/spec/fixtures/books/magazine_search_with_keyword_Ruby.json +1 -0
  34. data/spec/fixtures/books/software_search_with_keyword_Ruby.json +1 -0
  35. data/spec/fixtures/books/total_search_with_keyword_Ruby.json +1 -0
  36. data/spec/rakuten_web_service/books/book_spec.rb +93 -0
  37. data/spec/rakuten_web_service/books/cd_spec.rb +63 -0
  38. data/spec/rakuten_web_service/books/dvd_spec.rb +63 -0
  39. data/spec/rakuten_web_service/books/foreign_book_spec.rb +62 -0
  40. data/spec/rakuten_web_service/books/game_spec.rb +56 -0
  41. data/spec/rakuten_web_service/books/genre_spec.rb +187 -0
  42. data/spec/rakuten_web_service/books/magazine_spec.rb +56 -0
  43. data/spec/rakuten_web_service/books/software_spec.rb +56 -0
  44. data/spec/rakuten_web_service/books/total_spec.rb +38 -0
  45. data/spec/rakuten_web_service/ichiba/item_spec.rb +19 -0
  46. metadata +64 -16
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MTJhM2YwOGVjMzRkZTUyNmQyMjhiZTVjZWNiNzE4NmNmN2FkMzI2Mw==
5
- data.tar.gz: !binary |-
6
- YWRlNjc0MDE4NjI2OWE3YzQxNTM2MGRlZGRmNDQ4ZGU1NDZmNDU3Yw==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- YmY2NWI2NzcwZDhkMTBhMDMwNmUzNTc5YTFjNDcyMmEyN2I2ZmQyMjI1ZDg1
10
- YWI1NjhlNjc5NTAxM2M2ZGI5MjkwN2MzMjZhYjY4ZWZlMzhlNGM5YzBhZDk3
11
- MjRjOTc0YWMwMjFjMDU3M2Q0NDhjYzMwNDU0YmU1YzA5NGFjNWQ=
12
- data.tar.gz: !binary |-
13
- ZjQxMjk4MGRjNzZiNzRhZWRiMDE0ZThiYWZiYmMyNzQwNjg3YTYxOTcxZWE3
14
- ZmViYmIwY2YxNGFmMGM3MzJkYjc0MWM2MmQ5YTgxM2I3MDU2ZGVmNzc1ZWNj
15
- ZGUwZDhmMTJiZTJlOGM2MzJjZTYyODZiMWM5NzIwNDUxMmE0OGM=
2
+ SHA1:
3
+ metadata.gz: ea05eb23e2ac23b7a3498d463d5ad258e83a02ac
4
+ data.tar.gz: bdcbfbceb2961c96a35bc83d4bf692b1ff40678a
5
+ SHA512:
6
+ metadata.gz: 319d83fdfd80b0510cb23c6a6003bcb32b57f30e886a7af6a58b4cb8309e91ef5caa637339842d6a2d45566d971ad24f6211df088d513fe3fa3936b2aa742963
7
+ data.tar.gz: 259b56dd3e38712a54ccc88a32c90eaf2de3f40e7f84e6e614f025eb76d4ebbc6932db664f53ccf08e8c6f357934a7e93797b0f5d44d4be78865018a4ef821d6
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ spec/reports
16
16
  test/tmp
17
17
  test/version_tmp
18
18
  tmp
19
+ .ruby-version
data/.travis.yml CHANGED
@@ -1,8 +1,4 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.2
4
3
  - 1.9.3
5
4
  - 2.0.0
6
- branches:
7
- only:
8
- - master
data/README.en.md CHANGED
@@ -19,14 +19,31 @@ Or install it yourself as:
19
19
 
20
20
  $ gem install rakuten_web_service
21
21
 
22
- ## Usage
23
22
 
24
- Now rakuten\_web\_service is supporting the following APIs:
23
+ Now rakuten\_web\_service is supporting the following APIs:
24
+
25
+ ### Rakuten Ichiba APIs
25
26
 
26
27
  * [Rakuten Ichiba Item Search API](http://webservice.rakuten.co.jp/api/ichibaitemsearch/)
27
28
  * [Rakuten Ichiba Genre Search API](http://webservice.rakuten.co.jp/api/ichibagenresearch/)
28
29
  * [Rakuten Ichiba Ranking API](http://webservice.rakuten.co.jp/api/ichibaitemranking/)
29
30
 
31
+
32
+ ### Rakuten Books APIs
33
+
34
+ * [Rakuten Books Total Search API](http://webservice.rakuten.co.jp/api/bookstotalsearch/)
35
+ * [Rakuten Books Book Search API](http://webservice.rakuten.co.jp/api/booksbooksearch/)
36
+ * [Rakuten Books CD Search API](http://webservice.rakuten.co.jp/api/bookscdsearch/)
37
+ * [Rakuten Books DVD/Blu-ray Search API](http://webservice.rakuten.co.jp/api/booksdvdsearch/)
38
+ * [Rakuten Books ForeignBook Search API](http://webservice.rakuten.co.jp/api/booksforeignbooksearch/)
39
+ * [Rakuten Books Magazine Search API](http://webservice.rakuten.co.jp/api/booksmagazinesearch/)
40
+ * [Rakuten Books Game Search API](http://webservice.rakuten.co.jp/api/booksgamesearch/)
41
+ * [Rakuten Books Software Search API](http://webservice.rakuten.co.jp/api/bookssoftwaresearch/)
42
+ * [Rakuten Books Genre Search API](http://webservice.rakuten.co.jp/api/booksgenresearch/)
43
+
44
+
45
+ ## Usage
46
+
30
47
  ### Configuration
31
48
 
32
49
  `RakutenWebService.configuration` allows you to specify your application's key called application\_id and your affiliate id(optional).
data/README.md CHANGED
@@ -24,15 +24,30 @@ bundlerを利用したアプリケーションの場合、Gemfileに以下の1
24
24
 
25
25
  とすることでインストールできます。
26
26
 
27
- ## 使用方法
28
-
29
- Now rakuten\_web\_service is supporting the following APIs:
30
27
  現在rakuten\_web\_serviceは下記のAPIをサポートしています。
31
28
 
29
+ ### 楽天市場API
30
+
32
31
  * [Rakuten Ichiba Item Search API](http://webservice.rakuten.co.jp/api/ichibaitemsearch/)
33
32
  * [Rakuten Ichiba Genre Search API](http://webservice.rakuten.co.jp/api/ichibagenresearch/)
34
33
  * [Rakuten Ichiba Ranking API](http://webservice.rakuten.co.jp/api/ichibaitemranking/)
35
34
 
35
+
36
+ ### 楽天ブックス系API
37
+
38
+ * [Rakuten Books Total Search API](http://webservice.rakuten.co.jp/api/bookstotalsearch/)
39
+ * [Rakuten Books Book Search API](http://webservice.rakuten.co.jp/api/booksbooksearch/)
40
+ * [Rakuten Books CD Search API](http://webservice.rakuten.co.jp/api/bookscdsearch/)
41
+ * [Rakuten Books DVD/Blu-ray Search API](http://webservice.rakuten.co.jp/api/booksdvdsearch/)
42
+ * [Rakuten Books ForeignBook Search API](http://webservice.rakuten.co.jp/api/booksforeignbooksearch/)
43
+ * [Rakuten Books Magazine Search API](http://webservice.rakuten.co.jp/api/booksmagazinesearch/)
44
+ * [Rakuten Books Game Search API](http://webservice.rakuten.co.jp/api/booksgamesearch/)
45
+ * [Rakuten Books Software Search API](http://webservice.rakuten.co.jp/api/bookssoftwaresearch/)
46
+ * [Rakuten Books Genre Search API](http://webservice.rakuten.co.jp/api/booksgenresearch/)
47
+
48
+
49
+ ## 使用方法
50
+
36
51
  ### 設定
37
52
 
38
53
  `RakutenWebService.configuration` メソッドを使い、Application IDとAffiliate ID(オプション)を指定することができます。
@@ -1,14 +1,5 @@
1
- require 'rakuten_web_service/version'
2
- require 'rakuten_web_service/configuration'
3
- require 'rakuten_web_service/client'
4
- require 'rakuten_web_service/search_result'
5
- require 'rakuten_web_service/resource'
6
- require 'rakuten_web_service/ichiba/shop'
7
- require 'rakuten_web_service/ichiba/item'
8
- require 'rakuten_web_service/ichiba/genre'
9
- require 'rakuten_web_service/ichiba/ranking'
10
-
11
- module RakutenWebService
12
- end
13
-
1
+ module RakutenWebService; end
14
2
  RWS = RakutenWebService
3
+
4
+ require 'rakuten_web_service/ichiba'
5
+ require 'rakuten_web_service/books'
@@ -0,0 +1,11 @@
1
+ require 'rakuten_web_service/version'
2
+ require 'rakuten_web_service/configuration'
3
+
4
+ require 'rakuten_web_service/books/book'
5
+ require 'rakuten_web_service/books/cd'
6
+ require 'rakuten_web_service/books/dvd'
7
+ require 'rakuten_web_service/books/foreign_book'
8
+ require 'rakuten_web_service/books/magazine'
9
+ require 'rakuten_web_service/books/game'
10
+ require 'rakuten_web_service/books/software'
11
+ require 'rakuten_web_service/books/total'
@@ -0,0 +1,29 @@
1
+ require 'rakuten_web_service/books/resource'
2
+
3
+ module RakutenWebService
4
+ module Books
5
+ class Book < Books::Resource
6
+ endpoint 'https://app.rakuten.co.jp/services/api/BooksBook/Search/20130522'
7
+
8
+ attribute :title, :titleKana, :subTitle, :subTitleKana,
9
+ :seriesName, :seriesNameKana,
10
+ :contents, :contentsKana,
11
+ :author, :authorKana, :publisherName,
12
+ :size, :isbn,
13
+ :itemCaption, :itemPrice, :listPrice,
14
+ :discountRate, :discountPrice,
15
+ :salesDate,
16
+ :itemUrl, :affiliateUrl,
17
+ :smallImageUrl, :mediumImageUrl, :largeImageUrl,
18
+ :chirayomiUrl,
19
+ :availability,
20
+ :postageFlag, :limitedFlag,
21
+ :reviewCount, :reviewAverage,
22
+ :booksGenreId
23
+
24
+ def update_key
25
+ 'isbn'
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,25 @@
1
+ require 'rakuten_web_service/books/resource'
2
+
3
+ module RakutenWebService
4
+ module Books
5
+ class CD < Books::Resource
6
+ endpoint 'https://app.rakuten.co.jp/services/api/BooksCD/Search/20130522'
7
+
8
+ attribute :title, :titleKana, :artistName, :artistNameKana,
9
+ :label, :jan, :makerCode,
10
+ :itemCaption, :playList, :salesDate,
11
+ :itemPrice, :listPrice,
12
+ :discountRate, :discountPrice,
13
+ :itemUrl, :affiliateUrl,
14
+ :smallImageUrl, :mediumImageUrl, :largeImageUrl,
15
+ :availability,
16
+ :postageFlag, :limitedFlag,
17
+ :reviewCount, :reviewAverage,
18
+ :booksGenreId
19
+
20
+ def update_key
21
+ 'jan'
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ require 'rakuten_web_service/books/resource'
2
+
3
+ module RakutenWebService
4
+ module Books
5
+ class DVD < Books::Resource
6
+ endpoint 'https://app.rakuten.co.jp/services/api/BooksDVD/Search/20130522'
7
+
8
+ attribute :title, :titleKana, :artistName, :artistNameKana,
9
+ :label, :jan, :makerCode,
10
+ :itemCaption, :salesDate,
11
+ :itemPrice, :listPrice,
12
+ :discountRate, :discountPrice,
13
+ :itemUrl, :affiliateUrl,
14
+ :smallImageUrl, :mediumImageUrl, :largeImageUrl,
15
+ :availability,
16
+ :postageFlag, :limitedFlag,
17
+ :reviewCount, :reviewAverage,
18
+ :booksGenreId
19
+
20
+ def update_key
21
+ 'jan'
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,24 @@
1
+ require 'rakuten_web_service/resource'
2
+
3
+ module RakutenWebService
4
+ module Books
5
+ class ForeignBook < Books::Resource
6
+ endpoint 'https://app.rakuten.co.jp/services/api/BooksForeignBook/Search/20130522'
7
+
8
+ attribute :title, :titleKana, :japaneseTitle,
9
+ :author, :authorKana,
10
+ :publishName, :isbn, :itemCaption, :salesDate,
11
+ :itemPrice, :listPrice,
12
+ :discountRate, :discountPrice,
13
+ :itemUrl, :affiliateUrl,
14
+ :smallImageUrl, :mediumImageUrl, :largeImageUrl,
15
+ :availability, :postageFlag, :limitedFlag,
16
+ :reviewCount, :reviewAverage,
17
+ :booksGenreId
18
+
19
+ def update_key
20
+ 'isbn'
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,25 @@
1
+ require 'rakuten_web_service/books/resource'
2
+
3
+ module RakutenWebService
4
+ module Books
5
+ class Game < Books::Resource
6
+ endpoint 'https://app.rakuten.co.jp/services/api/BooksGame/Search/20130522'
7
+
8
+ attribute :title, :titleKana, :hardware, :jan, :makerCode,
9
+ :itemCaption,
10
+ :salesDate,
11
+ :itemPrice, :listPrice, :discountRate, :discountPrice,
12
+ :itemUrl, :affiliateUrl,
13
+ :contents, :contentsKana,
14
+ :smallImageUrl, :mediumImageUrl, :largeImageUrl,
15
+ :availability,
16
+ :postageFlag, :limitedFlag,
17
+ :reviewCount, :reviewAverage,
18
+ :booksGenreId
19
+
20
+ def update_key
21
+ 'jan'
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,66 @@
1
+ require 'rakuten_web_service/resource'
2
+
3
+ module RakutenWebService
4
+ module Books
5
+ class Genre < Resource
6
+ set_resource_name 'books_genre'
7
+
8
+ endpoint 'https://app.rakuten.co.jp/services/api/BooksGenre/Search/20121128'
9
+
10
+ set_parser do |response|
11
+ current = response['current']
12
+ if children = response['children']
13
+ children = children.map { |child| Books::Genre.new(child['child']) }
14
+ current.merge!('children' => children)
15
+ end
16
+ if parents = response['parents']
17
+ parents = parents.map { |parent| Books::Genre.new(parent['parent']) }
18
+ current.merge!('parents' => parents)
19
+ end
20
+
21
+ genre = Books::Genre.new(current)
22
+ [genre]
23
+ end
24
+
25
+ attribute :booksGenreId, :booksGenreName, :genreLevel
26
+
27
+ def self.root
28
+ new('000')
29
+ end
30
+
31
+ def self.new(params)
32
+ case params
33
+ when String
34
+ Genre[params] ||= self.search(:booksGenreId => params).first
35
+ when Hash
36
+ super
37
+ else
38
+ raise ArgumentError, 'Invalid parameter for initializing Books::Genre'
39
+ end
40
+ end
41
+
42
+ def self.[](id)
43
+ repository[id]
44
+ end
45
+
46
+ def self.[]=(id, genre)
47
+ repository[id] = genre
48
+ end
49
+
50
+ def children
51
+ @params['children'] ||= RWS::Books::Genre.search(:booksGenreId => self.id).first.children
52
+ end
53
+
54
+ def search(params={})
55
+ params = params.merge(:booksGenreId => self.id)
56
+ resource = Books::Resource.find_resource_by_genre_id(self.id)
57
+ resource.search(params)
58
+ end
59
+
60
+ private
61
+ def self.repository
62
+ @repository ||= {}
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,26 @@
1
+ require 'rakuten_web_service/books/resource'
2
+
3
+ module RakutenWebService
4
+ module Books
5
+ class Magazine < Books::Resource
6
+ endpoint 'https://app.rakuten.co.jp/services/api/BooksMagazine/Search/20130522'
7
+
8
+ attribute :title, :titleKana, :publisherName, :jan,
9
+ :itemCaption,
10
+ :salesDate, :cycle,
11
+ :itemPrice, :listPrice, :discountRate, :discountPrice,
12
+ :itemUrl, :affiliateUrl,
13
+ :contents, :contentsKana,
14
+ :smallImageUrl, :mediumImageUrl, :largeImageUrl,
15
+ :chirayomiUrl,
16
+ :availability,
17
+ :postageFlag, :limitedFlag,
18
+ :reviewCount, :reviewAverage,
19
+ :booksGenreId
20
+
21
+ def update_key
22
+ 'jan'
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,52 @@
1
+ require 'rakuten_web_service/resource'
2
+ require 'rakuten_web_service/books/genre'
3
+
4
+ module RakutenWebService
5
+ module Books
6
+ class Resource < RakutenWebService::Resource
7
+ set_parser do |response|
8
+ response['Items'].map { |item| self.new(item['Item']) }
9
+ end
10
+
11
+ def self.find_resource_by_genre_id(genre_id)
12
+ case genre_id
13
+ when /^001/ then RWS::Books::Book
14
+ when /^002/ then RWS::Books::CD
15
+ when /^003/ then RWS::Books::DVD
16
+ when /^004/ then RWS::Books::Software
17
+ when /^005/ then RWS::Books::ForeignBook
18
+ when /^006/ then RWS::Books::Game
19
+ when /^007/ then RWS::Books::Magazine
20
+ end
21
+ end
22
+
23
+ def genre
24
+ @genre ||= self.books_genre_id.split('/').map do |id|
25
+ Books::Genre.new(id)
26
+ end
27
+ end
28
+ alias genres genre
29
+
30
+ def get_attribute(name)
31
+ name = name.to_s
32
+ update_params unless @params[name]
33
+ @params[name]
34
+ end
35
+
36
+ private
37
+ def update_params
38
+ item = self.class.search(update_key => self[update_key]).first
39
+ @params = item.params
40
+ end
41
+
42
+ def update_key
43
+ raise 'This method is required to be overwritten in subclasses.'
44
+ end
45
+
46
+ protected
47
+ def params
48
+ @params.dup
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,25 @@
1
+ require 'rakuten_web_service/books/resource'
2
+
3
+ module RakutenWebService
4
+ module Books
5
+ class Software < Books::Resource
6
+ endpoint 'https://app.rakuten.co.jp/services/api/BooksSoftware/Search/20130522'
7
+
8
+ attribute :title, :titleKana, :os, :jan, :makerCode,
9
+ :itemCaption,
10
+ :salesDate,
11
+ :itemPrice, :listPrice, :discountRate, :discountPrice,
12
+ :itemUrl, :affiliateUrl,
13
+ :contents, :contentsKana,
14
+ :smallImageUrl, :mediumImageUrl, :largeImageUrl,
15
+ :availability,
16
+ :postageFlag, :limitedFlag,
17
+ :reviewCount, :reviewAverage,
18
+ :booksGenreId
19
+
20
+ def update_key
21
+ 'jan'
22
+ end
23
+ end
24
+ end
25
+ end