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
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+ require 'rakuten_web_service'
3
+
4
+ describe RakutenWebService::Books::DVD do
5
+ let(:endpoint) { 'https://app.rakuten.co.jp/services/api/BooksDVD/Search/20130522' }
6
+ let(:affiliate_id) { 'dummy_affiliate_id' }
7
+ let(:application_id) { 'dummy_application_id' }
8
+ let(:expected_query) do
9
+ {
10
+ :affiliateId => affiliate_id,
11
+ :applicationId => application_id,
12
+ :keyword => 'Ruby'
13
+ }
14
+ end
15
+
16
+ before do
17
+ RakutenWebService.configuration do |c|
18
+ c.affiliate_id = affiliate_id
19
+ c.application_id = application_id
20
+ end
21
+ end
22
+
23
+ describe '.search' do
24
+ before do
25
+ response = JSON.parse(fixture('books/dvd_search_with_keyword_Ruby.json'))
26
+ @expected_request = stub_request(:get, endpoint).
27
+ with(:query => expected_query).to_return(:body => response.to_json)
28
+
29
+ response['page'] = 2
30
+ response['first'] = 31
31
+ response['last'] = 60
32
+ @second_request = stub_request(:get, endpoint).
33
+ with(:query => expected_query.merge(:page => 2)).
34
+ to_return(:body => response.to_json)
35
+ end
36
+
37
+ specify 'call endpoint when accessing results' do
38
+ dvds = RakutenWebService::Books::DVD.search(:keyword => 'Ruby')
39
+ expect(@expected_request).to_not have_been_made
40
+
41
+ dvd = dvds.first
42
+ expect(@expected_request).to have_been_made.once
43
+ expect(dvd).to be_a(RWS::Books::DVD)
44
+ end
45
+ end
46
+
47
+ context 'When using Books::Total.search' do
48
+ let(:dvd) do
49
+ RWS::Books::DVD.new(:jan => '12345')
50
+ end
51
+
52
+ before do
53
+ @expected_request = stub_request(:get, endpoint).
54
+ with(:query => { :affiliateId => affiliate_id, :applicationId => application_id, :jan => '12345' }).
55
+ to_return(:body => { :Items => [ { :Item => { :title => 'foo' } } ] }.to_json)
56
+ end
57
+
58
+ specify 'retrieves automatically if accessing the value of lack attribute' do
59
+ expect(dvd.title).to eq('foo')
60
+ expect(@expected_request).to have_been_made.once
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+ require 'rakuten_web_service'
3
+
4
+ describe RakutenWebService::Books::ForeignBook do
5
+ let(:endpoint) { 'https://app.rakuten.co.jp/services/api/BooksForeignBook/Search/20130522' }
6
+ let(:affiliate_id) { 'dummy_affiliate_id' }
7
+ let(:application_id) { 'dummy_application_id' }
8
+ let(:expected_query) do
9
+ {
10
+ :affiliateId => affiliate_id,
11
+ :applicationId => application_id,
12
+ :keyword => 'Ruby'
13
+ }
14
+ end
15
+
16
+ before do
17
+ RakutenWebService.configuration do |c|
18
+ c.affiliate_id = affiliate_id
19
+ c.application_id = application_id
20
+ end
21
+ end
22
+
23
+ describe '.search' do
24
+ before do
25
+ response = JSON.parse(fixture('books/foreign_book_search_with_keyword_Ruby.json'))
26
+ @expected_request = stub_request(:get, endpoint).
27
+ with(:query => expected_query).to_return(:body => response.to_json)
28
+
29
+ response['page'] = 2
30
+ response['first'] = 31
31
+ response['last'] = 60
32
+ @second_request = stub_request(:get, endpoint).
33
+ with(:query => expected_query.merge(:page => 2)).
34
+ to_return(:body => response.to_json)
35
+ end
36
+
37
+ specify 'call endpoint when accessing results' do
38
+ books = RakutenWebService::Books::ForeignBook.search(:keyword => 'Ruby')
39
+ expect(@expected_request).to_not have_been_made
40
+
41
+ books.first
42
+ expect(@expected_request).to have_been_made.once
43
+ end
44
+ end
45
+
46
+ context 'When using Books::Total.search' do
47
+ let(:book) do
48
+ RWS::Books::ForeignBook.new(:isbn => '12345')
49
+ end
50
+
51
+ before do
52
+ @expected_request = stub_request(:get, endpoint).
53
+ with(:query => { :affiliateId => affiliate_id, :applicationId => application_id, :isbn => '12345' }).
54
+ to_return(:body => { :Items => [ { :Item => { :title => 'foo' } } ] }.to_json)
55
+ end
56
+
57
+ specify 'retrieves automatically if accessing the value of lack attribute' do
58
+ expect(book.title).to eq('foo')
59
+ expect(@expected_request).to have_been_made.once
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+ require 'rakuten_web_service'
3
+
4
+ describe RakutenWebService::Books::Game do
5
+ let(:endpoint) { 'https://app.rakuten.co.jp/services/api/BooksGame/Search/20130522' }
6
+ let(:affiliate_id) { 'dummy_affiliate_id' }
7
+ let(:application_id) { 'dummy_application_id' }
8
+ let(:expected_query) do
9
+ {
10
+ :affiliateId => affiliate_id,
11
+ :applicationId => application_id,
12
+ :keyword => 'Ruby'
13
+ }
14
+ end
15
+
16
+ before do
17
+ RakutenWebService.configuration do |c|
18
+ c.affiliate_id = affiliate_id
19
+ c.application_id = application_id
20
+ end
21
+ end
22
+
23
+ describe '.search' do
24
+ before do
25
+ response = JSON.parse(fixture('books/game_search_with_keyword_Ruby.json'))
26
+ @expected_request = stub_request(:get, endpoint).
27
+ with(:query => expected_query).to_return(:body => response.to_json)
28
+ end
29
+
30
+ specify 'call endpoint when accessing results' do
31
+ games = RakutenWebService::Books::Game.search(:keyword => 'Ruby')
32
+ expect(@expected_request).to_not have_been_made
33
+
34
+ game = games.first
35
+ expect(@expected_request).to have_been_made.once
36
+ expect(game).to be_a(RWS::Books::Game)
37
+ end
38
+ end
39
+
40
+ context 'When using Books::Total.search' do
41
+ let(:game) do
42
+ RWS::Books::Game.new(:jan => '12345')
43
+ end
44
+
45
+ before do
46
+ @expected_request = stub_request(:get, endpoint).
47
+ with(:query => { :affiliateId => affiliate_id, :applicationId => application_id, :jan => '12345' }).
48
+ to_return(:body => { :Items => [ { :Item => { :title => 'foo' } } ] }.to_json)
49
+ end
50
+
51
+ specify 'retrieves automatically if accessing the value of lack attribute' do
52
+ expect(game.title).to eq('foo')
53
+ expect(@expected_request).to have_been_made.once
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,187 @@
1
+ require 'spec_helper'
2
+ require 'rakuten_web_service'
3
+
4
+ describe RWS::Books::Genre do
5
+ let(:endpoint) { 'https://app.rakuten.co.jp/services/api/BooksGenre/Search/20121128' }
6
+ let(:affiliate_id) { 'dummy_affiliate_id' }
7
+ let(:application_id) { 'dummy_application_id' }
8
+ let(:genre_id) { '000' }
9
+ let(:expected_query) do
10
+ {
11
+ :affiliateId => affiliate_id,
12
+ :applicationId => application_id,
13
+ :booksGenreId => genre_id
14
+ }
15
+ end
16
+ let(:expected_json) do
17
+ JSON.parse(fixture('books/genre_search.json'))
18
+ end
19
+
20
+ before do
21
+ @expected_request = stub_request(:get, endpoint).
22
+ with(:query => expected_query).
23
+ to_return(:body => expected_json)
24
+
25
+ RakutenWebService.configuration do |c|
26
+ c.affiliate_id = affiliate_id
27
+ c.application_id = application_id
28
+ end
29
+ end
30
+
31
+ describe '.search' do
32
+ before do
33
+ @genre = RWS::Books::Genre.search(:booksGenreId => genre_id).first
34
+ end
35
+
36
+ specify 'call the endpoint once' do
37
+ expect(@expected_request).to have_been_made.once
38
+ end
39
+ specify 'has interfaces like hash' do
40
+ expect(@genre['booksGenreName']).to eq(expected_json['current']['booksGenreName'])
41
+ expect(@genre['genreLevel']).to eq(expected_json['current']['genreLevel'])
42
+ end
43
+ specify 'has interfaces like hash with snake case key' do
44
+ expect(@genre['books_genre_name']).to eq(expected_json['current']['booksGenreName'])
45
+ expect(@genre['genre_level']).to eq(expected_json['current']['genreLevel'])
46
+ end
47
+ specify 'has interfaces to get each attribute' do
48
+ expect(@genre.id).to eq(expected_json['current']['booksGenreId'])
49
+ expect(@genre.name).to eq(expected_json['current']['booksGenreName'])
50
+ end
51
+ end
52
+
53
+ describe '.new' do
54
+ let(:genre_id) { '007' }
55
+ let(:expected_json) do
56
+ {
57
+ :current => {
58
+ :booksGenreId => genre_id,
59
+ :booksGenreName => 'DummyGenre',
60
+ :genreLevel => '2'
61
+ }
62
+ }.to_json
63
+ end
64
+
65
+ before do
66
+ @genre = RWS::Books::Genre.new(param)
67
+ end
68
+
69
+ context 'given a genre id' do
70
+ let(:param) { genre_id }
71
+
72
+ specify 'only call endpint only at the first time to initialize' do
73
+ RWS::Books::Genre.new(param)
74
+
75
+ expect(@expected_request).to have_been_made.once
76
+ end
77
+ end
78
+ end
79
+
80
+ describe '.root' do
81
+ specify 'alias of constructor with the root genre id "000"' do
82
+ RWS::Books::Genre.should_receive(:new).with('000')
83
+
84
+ RWS::Books::Genre.root
85
+ end
86
+ end
87
+
88
+ describe '#children' do
89
+ context 'When get search method' do
90
+ before do
91
+ @genre = RWS::Books::Genre.search(:booksGenreId => genre_id).first
92
+ end
93
+
94
+ specify 'are Books::Genre objects' do
95
+ expect(@genre.children).to be_all { |child| child.is_a? RWS::Books::Genre }
96
+ expect(@genre.children).to be_all do |child|
97
+ expected_json['children'].is_any? { |c| c['booksGenreId'] == child['booksGenreId'] }
98
+ end
99
+ end
100
+ end
101
+
102
+ context 'when the genre object has no children information' do
103
+ specify 'call the endpoint to get children' do
104
+ genre = RWS::Books::Genre.new(:booksGenreId => genre_id)
105
+ genre.children
106
+
107
+ expect(@expected_request).to have_been_made.once
108
+ end
109
+ end
110
+ end
111
+
112
+ describe '#search' do
113
+ before do
114
+ @genre = RWS::Books::Genre.new(:booksGenreId => genre_id)
115
+ end
116
+
117
+ context 'if the genre_id starts with "001"' do
118
+ let(:genre_id) { '001001' }
119
+
120
+ specify 'delegate Books::Book.search' do
121
+ RWS::Books::Book.should_receive(:search).with(:booksGenreId => genre_id)
122
+
123
+ @genre.search
124
+ end
125
+ end
126
+
127
+ context 'if the genre_id starts with "002"' do
128
+ let(:genre_id) { '002101' }
129
+
130
+ specify 'delegate Books::CD.search' do
131
+ RWS::Books::CD.should_receive(:search).with(:booksGenreId => genre_id)
132
+
133
+ @genre.search
134
+ end
135
+ end
136
+
137
+ context 'if the genre_id starts with "003"' do
138
+ let(:genre_id) { '003201' }
139
+
140
+ specify 'delegate Books::DVD.search' do
141
+ RWS::Books::DVD.should_receive(:search).with(:booksGenreId => genre_id)
142
+
143
+ @genre.search
144
+ end
145
+ end
146
+
147
+ context 'if the genre_id starts with "004"' do
148
+ let(:genre_id) { '004301' }
149
+
150
+ specify 'delegate Books::Software.search' do
151
+ RWS::Books::Software.should_receive(:search).with(:booksGenreId => genre_id)
152
+
153
+ @genre.search
154
+ end
155
+ end
156
+
157
+ context 'if the genre_id starts with "005"' do
158
+ let(:genre_id) { '005401' }
159
+
160
+ specify 'delegate Books::ForeignBook.search' do
161
+ RWS::Books::ForeignBook.should_receive(:search).with(:booksGenreId => genre_id)
162
+
163
+ @genre.search
164
+ end
165
+ end
166
+
167
+ context 'if the genre_id starts with "006"' do
168
+ let(:genre_id) { '006501' }
169
+
170
+ specify 'delegate Books::Game.search' do
171
+ RWS::Books::Game.should_receive(:search).with(:booksGenreId => genre_id)
172
+
173
+ @genre.search
174
+ end
175
+ end
176
+
177
+ context 'if the genre_id starts with "007"' do
178
+ let(:genre_id) { '007601' }
179
+
180
+ specify 'delegate Books::Magazine.search' do
181
+ RWS::Books::Magazine.should_receive(:search).with(:booksGenreId => genre_id)
182
+
183
+ @genre.search
184
+ end
185
+ end
186
+ end
187
+ end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+ require 'rakuten_web_service'
3
+
4
+ describe RakutenWebService::Books::Magazine do
5
+ let(:endpoint) { 'https://app.rakuten.co.jp/services/api/BooksMagazine/Search/20130522' }
6
+ let(:affiliate_id) { 'dummy_affiliate_id' }
7
+ let(:application_id) { 'dummy_application_id' }
8
+ let(:expected_query) do
9
+ {
10
+ :affiliateId => affiliate_id,
11
+ :applicationId => application_id,
12
+ :keyword => 'Ruby'
13
+ }
14
+ end
15
+
16
+ before do
17
+ RakutenWebService.configuration do |c|
18
+ c.affiliate_id = affiliate_id
19
+ c.application_id = application_id
20
+ end
21
+ end
22
+
23
+ describe '.search' do
24
+ before do
25
+ response = JSON.parse(fixture('books/magazine_search_with_keyword_Ruby.json'))
26
+ @expected_request = stub_request(:get, endpoint).
27
+ with(:query => expected_query).to_return(:body => response.to_json)
28
+ end
29
+
30
+ specify 'call endpoint when accessing results' do
31
+ magazines = RakutenWebService::Books::Magazine.search(:keyword => 'Ruby')
32
+ expect(@expected_request).to_not have_been_made
33
+
34
+ magazine = magazines.first
35
+ expect(@expected_request).to have_been_made.once
36
+ expect(magazine).to be_a(RWS::Books::Magazine)
37
+ end
38
+ end
39
+
40
+ context 'When using Books::Total.search' do
41
+ let(:magazine) do
42
+ RWS::Books::Magazine.new(:jan => '12345')
43
+ end
44
+
45
+ before do
46
+ @expected_request = stub_request(:get, endpoint).
47
+ with(:query => { :affiliateId => affiliate_id, :applicationId => application_id, :jan => '12345' }).
48
+ to_return(:body => { :Items => [ { :Item => { :title => 'foo' } } ] }.to_json)
49
+ end
50
+
51
+ specify 'retrieves automatically if accessing the value of lack attribute' do
52
+ expect(magazine.title).to eq('foo')
53
+ expect(@expected_request).to have_been_made.once
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+ require 'rakuten_web_service'
3
+
4
+ describe RakutenWebService::Books::Software do
5
+ let(:endpoint) { 'https://app.rakuten.co.jp/services/api/BooksSoftware/Search/20130522' }
6
+ let(:affiliate_id) { 'dummy_affiliate_id' }
7
+ let(:application_id) { 'dummy_application_id' }
8
+ let(:expected_query) do
9
+ {
10
+ :affiliateId => affiliate_id,
11
+ :applicationId => application_id,
12
+ :keyword => 'Ruby'
13
+ }
14
+ end
15
+
16
+ before do
17
+ RakutenWebService.configuration do |c|
18
+ c.affiliate_id = affiliate_id
19
+ c.application_id = application_id
20
+ end
21
+ end
22
+
23
+ describe '.search' do
24
+ before do
25
+ response = JSON.parse(fixture('books/software_search_with_keyword_Ruby.json'))
26
+ @expected_request = stub_request(:get, endpoint).
27
+ with(:query => expected_query).to_return(:body => response.to_json)
28
+ end
29
+
30
+ specify 'call endpoint when accessing results' do
31
+ softwares = RakutenWebService::Books::Software.search(:keyword => 'Ruby')
32
+ expect(@expected_request).to_not have_been_made
33
+
34
+ software = softwares.first
35
+ expect(@expected_request).to have_been_made.once
36
+ expect(software).to be_a(RWS::Books::Software)
37
+ end
38
+ end
39
+
40
+ context 'When using Books::Total.search' do
41
+ let(:software) do
42
+ RWS::Books::Software.new(:jan => '12345')
43
+ end
44
+
45
+ before do
46
+ @expected_request = stub_request(:get, endpoint).
47
+ with(:query => { :affiliateId => affiliate_id, :applicationId => application_id, :jan => '12345' }).
48
+ to_return(:body => { :Items => [ { :Item => { :title => 'foo' } } ] }.to_json)
49
+ end
50
+
51
+ specify 'retrieves automatically if accessing the value of lack attribute' do
52
+ expect(software.title).to eq('foo')
53
+ expect(@expected_request).to have_been_made.once
54
+ end
55
+ end
56
+ end