rakuten_web_service 0.6.3 → 1.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.coveralls.yml +1 -0
- data/.travis.yml +19 -3
- data/CHANGELOG.md +14 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +5 -0
- data/README.ja.md +133 -0
- data/README.md +129 -48
- data/examples/books_item_search.rb +24 -0
- data/examples/gora_search.rb +48 -0
- data/examples/ichiba_item_search.rb +1 -3
- data/lib/rakuten_web_service.rb +2 -0
- data/lib/rakuten_web_service/all_proxy.rb +20 -0
- data/lib/rakuten_web_service/client.rb +6 -13
- data/lib/rakuten_web_service/configuration.rb +28 -4
- data/lib/rakuten_web_service/gora.rb +3 -0
- data/lib/rakuten_web_service/gora/course.rb +17 -0
- data/lib/rakuten_web_service/gora/course_detail.rb +55 -0
- data/lib/rakuten_web_service/gora/plan.rb +47 -0
- data/lib/rakuten_web_service/ichiba/item.rb +5 -4
- data/lib/rakuten_web_service/ichiba/shop.rb +1 -1
- data/lib/rakuten_web_service/kobo/ebook.rb +2 -2
- data/lib/rakuten_web_service/recipe.rb +28 -0
- data/lib/rakuten_web_service/recipe/category.rb +60 -0
- data/lib/rakuten_web_service/resource.rb +9 -1
- data/lib/rakuten_web_service/search_result.rb +43 -19
- data/lib/rakuten_web_service/version.rb +1 -1
- data/rakuten_web_service.gemspec +2 -2
- data/spec/fixtures/gora/course_detail_search.json +1 -0
- data/spec/fixtures/gora/course_search_with_Karuizawa.json +1 -0
- data/spec/fixtures/gora/plan_search_with_area_code.json +1 -0
- data/spec/fixtures/recipe/category.json +1 -0
- data/spec/fixtures/recipe/ranking.json +1 -0
- data/spec/rakuten_web_service/books/book_spec.rb +1 -2
- data/spec/rakuten_web_service/books/cd_spec.rb +1 -2
- data/spec/rakuten_web_service/books/dvd_spec.rb +1 -2
- data/spec/rakuten_web_service/books/foreign_book_spec.rb +1 -2
- data/spec/rakuten_web_service/books/game_spec.rb +1 -2
- data/spec/rakuten_web_service/books/genre_spec.rb +1 -2
- data/spec/rakuten_web_service/books/magazine_spec.rb +1 -2
- data/spec/rakuten_web_service/books/software_spec.rb +1 -2
- data/spec/rakuten_web_service/books/total_spec.rb +1 -2
- data/spec/rakuten_web_service/client_spec.rb +3 -3
- data/spec/rakuten_web_service/configuration_spec.rb +45 -4
- data/spec/rakuten_web_service/gora/course_detail_spec.rb +60 -0
- data/spec/rakuten_web_service/gora/course_spec.rb +108 -0
- data/spec/rakuten_web_service/gora/plan_spec.rb +62 -0
- data/spec/rakuten_web_service/ichiba/genre_spec.rb +1 -2
- data/spec/rakuten_web_service/ichiba/item_spec.rb +53 -8
- data/spec/rakuten_web_service/ichiba/product_search_spec.rb +2 -3
- data/spec/rakuten_web_service/ichiba/ranking_spec.rb +1 -1
- data/spec/rakuten_web_service/ichiba/shop_spec.rb +2 -3
- data/spec/rakuten_web_service/kobo/ebook_spec.rb +2 -3
- data/spec/rakuten_web_service/kobo/genre_spec.rb +1 -2
- data/spec/rakuten_web_service/recipe/category_spec.rb +185 -0
- data/spec/rakuten_web_service/recipe_spec.rb +50 -0
- data/spec/spec_helper.rb +16 -6
- metadata +42 -11
- data/README.en.md +0 -108
@@ -0,0 +1,108 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe RakutenWebService::Gora::Course do
|
6
|
+
let(:endpoint) { 'https://app.rakuten.co.jp/services/api/Gora/GoraGolfCourseSearch/20131113' }
|
7
|
+
let(:affiliate_id) { 'dummy_affiliate_id' }
|
8
|
+
let(:application_id) { 'dummy_application_id' }
|
9
|
+
let(:expected_query) do
|
10
|
+
{
|
11
|
+
:affiliateId => affiliate_id,
|
12
|
+
:applicationId => application_id,
|
13
|
+
:keyword => '軽井沢'
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
before do
|
18
|
+
RakutenWebService.configure do |c|
|
19
|
+
c.affiliate_id = affiliate_id
|
20
|
+
c.application_id = application_id
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '.search' do
|
25
|
+
before do
|
26
|
+
response = JSON.parse(fixture('gora/course_search_with_Karuizawa.json'))
|
27
|
+
@expected_request = stub_request(:get, endpoint).
|
28
|
+
with(:query => expected_query).to_return(:body => response.to_json)
|
29
|
+
|
30
|
+
response['page'] = 2
|
31
|
+
response['first'] = 31
|
32
|
+
response['last'] = 60
|
33
|
+
@second_request = stub_request(:get, endpoint).
|
34
|
+
with(:query => expected_query.merge(:page => 2)).
|
35
|
+
to_return(:body => response.to_json)
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'just call the search method' do
|
39
|
+
before do
|
40
|
+
@courses = RakutenWebService::Gora::Course.search(:keyword => '軽井沢')
|
41
|
+
end
|
42
|
+
|
43
|
+
specify 'endpoint should not be called' do
|
44
|
+
expect(@expected_request).to_not have_been_made
|
45
|
+
end
|
46
|
+
|
47
|
+
describe 'a respond object' do
|
48
|
+
let(:expected_json) do
|
49
|
+
response = JSON.parse(fixture('gora/course_search_with_Karuizawa.json'))
|
50
|
+
response['Items'][0]['Item']
|
51
|
+
end
|
52
|
+
|
53
|
+
subject { @courses.first }
|
54
|
+
|
55
|
+
it { should be_a RakutenWebService::Gora::Course }
|
56
|
+
specify 'should be accessed by key' do
|
57
|
+
expect(subject['golfCourseName']).to eq(expected_json['golfCourseName'])
|
58
|
+
expect(subject['golf_course_name']).to eq(expected_json['golfCourseName'])
|
59
|
+
end
|
60
|
+
its(:golf_course_name) { should eq(expected_json['golfCourseName']) }
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'after that, call each' do
|
64
|
+
before do
|
65
|
+
@courses.each { |i| i }
|
66
|
+
end
|
67
|
+
|
68
|
+
specify 'endpoint should be called' do
|
69
|
+
expect(@expected_request).to have_been_made.once
|
70
|
+
expect(@second_request).not_to have_been_made.once
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'after that, call fetch_result' do
|
75
|
+
before do
|
76
|
+
@courses.fetch_result
|
77
|
+
end
|
78
|
+
|
79
|
+
specify 'endpoint should be called' do
|
80
|
+
expect(@expected_request).to have_been_made.once
|
81
|
+
expect(@second_request).to_not have_been_made.once
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe '#all' do
|
86
|
+
before do
|
87
|
+
@courses.all
|
88
|
+
end
|
89
|
+
|
90
|
+
specify 'endpoint should not be called' do
|
91
|
+
expect(@expected_request).to_not have_been_made.once
|
92
|
+
expect(@second_request).to_not have_been_made.once
|
93
|
+
end
|
94
|
+
|
95
|
+
context 'call an enumerable method like each' do
|
96
|
+
before do
|
97
|
+
@courses.all.each { |i| i.to_s }
|
98
|
+
end
|
99
|
+
|
100
|
+
specify 'endpoint should be called' do
|
101
|
+
expect(@expected_request).to have_been_made.once
|
102
|
+
expect(@second_request).to have_been_made.once
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe RakutenWebService::Gora::Plan do
|
6
|
+
let(:endpoint) { 'https://app.rakuten.co.jp/services/api/Gora/GoraPlanSearch/20150706' }
|
7
|
+
let(:affiliate_id) { 'dummy_affiliate_id' }
|
8
|
+
let(:application_id) { 'dummy_application_id' }
|
9
|
+
let(:expected_query) do
|
10
|
+
{
|
11
|
+
:affiliateId => affiliate_id,
|
12
|
+
:applicationId => application_id,
|
13
|
+
:areaCode => '12,14',
|
14
|
+
:playDate => '2016-04-24',
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
before do
|
19
|
+
RakutenWebService.configure do |c|
|
20
|
+
c.affiliate_id = affiliate_id
|
21
|
+
c.application_id = application_id
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '.search' do
|
26
|
+
before do
|
27
|
+
response = JSON.parse(fixture('gora/plan_search_with_area_code.json'))
|
28
|
+
@expected_request = stub_request(:get, endpoint).
|
29
|
+
with(:query => expected_query).to_return(:body => response.to_json)
|
30
|
+
end
|
31
|
+
|
32
|
+
specify 'endpoint should not be called' do
|
33
|
+
expect(@expected_request).to_not have_been_made
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'just call the search method' do
|
37
|
+
before do
|
38
|
+
@plans = RakutenWebService::Gora::Plan.search(:areaCode => expected_query[:areaCode], :playDate => expected_query[:playDate])
|
39
|
+
end
|
40
|
+
|
41
|
+
specify 'endpoint should not be called' do
|
42
|
+
expect(@expected_request).to_not have_been_made
|
43
|
+
end
|
44
|
+
|
45
|
+
describe 'a respond object' do
|
46
|
+
let(:expected_json) do
|
47
|
+
response = JSON.parse(fixture('gora/plan_search_with_area_code.json'))
|
48
|
+
response['Items'][0]['Item']
|
49
|
+
end
|
50
|
+
|
51
|
+
subject { @plans.first }
|
52
|
+
|
53
|
+
it { should be_a RakutenWebService::Gora::Plan }
|
54
|
+
specify 'should be accessed by key' do
|
55
|
+
expect(subject['golfCourseId']).to eq(expected_json['golfCourseId'])
|
56
|
+
expect(subject['golf_course_id']).to eq(expected_json['golfCourseId'])
|
57
|
+
end
|
58
|
+
its(:golf_course_id) { should eq(expected_json['golfCourseId']) }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
|
-
require 'rakuten_web_service'
|
5
4
|
|
6
5
|
describe RakutenWebService::Ichiba::Genre do
|
7
6
|
let(:endpoint) { 'https://app.rakuten.co.jp/services/api/IchibaGenre/Search/20120723' }
|
@@ -24,7 +23,7 @@ describe RakutenWebService::Ichiba::Genre do
|
|
24
23
|
with(:query => expected_query).
|
25
24
|
to_return(:body => fixture('ichiba/genre_search.json'))
|
26
25
|
|
27
|
-
RakutenWebService.
|
26
|
+
RakutenWebService.configure do |c|
|
28
27
|
c.affiliate_id = affiliate_id
|
29
28
|
c.application_id = application_id
|
30
29
|
end
|
@@ -1,10 +1,9 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
|
-
require 'rakuten_web_service'
|
5
4
|
|
6
5
|
describe RakutenWebService::Ichiba::Item do
|
7
|
-
let(:endpoint) { 'https://app.rakuten.co.jp/services/api/IchibaItem/Search/
|
6
|
+
let(:endpoint) { 'https://app.rakuten.co.jp/services/api/IchibaItem/Search/20140222' }
|
8
7
|
let(:affiliate_id) { 'dummy_affiliate_id' }
|
9
8
|
let(:application_id) { 'dummy_application_id' }
|
10
9
|
let(:expected_query) do
|
@@ -16,7 +15,7 @@ describe RakutenWebService::Ichiba::Item do
|
|
16
15
|
end
|
17
16
|
|
18
17
|
before do
|
19
|
-
RakutenWebService.
|
18
|
+
RakutenWebService.configure do |c|
|
20
19
|
c.affiliate_id = affiliate_id
|
21
20
|
c.application_id = application_id
|
22
21
|
end
|
@@ -71,19 +70,41 @@ describe RakutenWebService::Ichiba::Item do
|
|
71
70
|
|
72
71
|
specify 'endpoint should be called' do
|
73
72
|
expect(@expected_request).to have_been_made.once
|
74
|
-
expect(@second_request).
|
73
|
+
expect(@second_request).to_not have_been_made
|
75
74
|
end
|
76
75
|
end
|
77
76
|
|
78
|
-
context '
|
77
|
+
context 'chain calling' do
|
79
78
|
before do
|
80
|
-
@items.
|
79
|
+
@items2 = @items.search(:keyword => 'Go')
|
81
80
|
end
|
82
81
|
|
83
|
-
specify
|
84
|
-
expect(@
|
82
|
+
specify "2 search resutls should be independent" do
|
83
|
+
expect(@items.params[:keyword]).to eq('Ruby')
|
84
|
+
expect(@items2.params[:keyword]).to eq('Go')
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe '#all' do
|
89
|
+
before do
|
90
|
+
@items.all
|
91
|
+
end
|
92
|
+
|
93
|
+
specify 'endpoint should not be called' do
|
94
|
+
expect(@expected_request).to_not have_been_made.once
|
85
95
|
expect(@second_request).to_not have_been_made.once
|
86
96
|
end
|
97
|
+
|
98
|
+
context 'call an enumerable method like each' do
|
99
|
+
before do
|
100
|
+
@items.all.each { |i| i.to_s }
|
101
|
+
end
|
102
|
+
|
103
|
+
specify 'endpoint should be called' do
|
104
|
+
expect(@expected_request).to have_been_made.once
|
105
|
+
expect(@second_request).to have_been_made.once
|
106
|
+
end
|
107
|
+
end
|
87
108
|
end
|
88
109
|
|
89
110
|
context 'When TooManyRequest error raised' do
|
@@ -105,6 +126,29 @@ describe RakutenWebService::Ichiba::Item do
|
|
105
126
|
end
|
106
127
|
end
|
107
128
|
|
129
|
+
describe '.all' do
|
130
|
+
before do
|
131
|
+
response = JSON.parse(fixture('ichiba/item_search_with_keyword_Ruby.json'))
|
132
|
+
@expected_request = stub_request(:get, endpoint).
|
133
|
+
with(:query => expected_query).to_return(:body => response.to_json)
|
134
|
+
|
135
|
+
response['page'] = 2
|
136
|
+
response['first'] = 31
|
137
|
+
response['last'] = 60
|
138
|
+
@second_request = stub_request(:get, endpoint).
|
139
|
+
with(:query => expected_query.merge(:page => 2)).
|
140
|
+
to_return(:body => response.to_json)
|
141
|
+
end
|
142
|
+
|
143
|
+
context 'When givne a block' do
|
144
|
+
specify '' do
|
145
|
+
expect { |b| RWS::Ichiba::Item.all({:keyword => 'Ruby'}, &b) }.to yield_control.exactly(60).times
|
146
|
+
|
147
|
+
expect { |b| RWS::Ichiba::Item.all({:keyword => 'Ruby'}, &b) }.to yield_successive_args(*([RakutenWebService::Ichiba::Item] * 60))
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
108
152
|
describe '.ranking' do
|
109
153
|
before do
|
110
154
|
RakutenWebService::Ichiba::RankingItem.should_receive(:search).with({})
|
@@ -150,6 +194,7 @@ describe RakutenWebService::Ichiba::Item do
|
|
150
194
|
expect(subject.name).to eq(expected_item['shopName'])
|
151
195
|
expect(subject.code).to eq(expected_item['shopCode'])
|
152
196
|
expect(subject.url).to eq(expected_item['shopUrl'])
|
197
|
+
expect(subject.affiliate_url).to eq(expected_item['shopAffiliateUrl'])
|
153
198
|
end
|
154
199
|
end
|
155
200
|
|
@@ -1,6 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
|
-
require 'rakuten_web_service'
|
4
3
|
|
5
4
|
describe RakutenWebService::Ichiba::Product do
|
6
5
|
let(:endpoint) { 'https://app.rakuten.co.jp/services/api/Product/Search/20140305' }
|
@@ -15,7 +14,7 @@ describe RakutenWebService::Ichiba::Product do
|
|
15
14
|
end
|
16
15
|
|
17
16
|
before do
|
18
|
-
RakutenWebService.
|
17
|
+
RakutenWebService.configure do |c|
|
19
18
|
c.affiliate_id = affiliate_id
|
20
19
|
c.application_id = application_id
|
21
20
|
end
|
@@ -39,7 +38,7 @@ describe RakutenWebService::Ichiba::Product do
|
|
39
38
|
subject { RakutenWebService::Ichiba::Product.search(:keyword => 'Ruby') }
|
40
39
|
|
41
40
|
specify '' do
|
42
|
-
expect(subject).to have(
|
41
|
+
expect(subject).to have(30).things
|
43
42
|
end
|
44
43
|
|
45
44
|
describe 'For an response' do
|
@@ -16,7 +16,7 @@ describe RakutenWebService::Ichiba::RankingItem do
|
|
16
16
|
@expected_request = stub_request(:get, endpoint).
|
17
17
|
with(:query => expected_query).to_return(:body => response.to_json)
|
18
18
|
|
19
|
-
RakutenWebService.
|
19
|
+
RakutenWebService.configure do |c|
|
20
20
|
c.affiliate_id = affiliate_id
|
21
21
|
c.application_id = application_id
|
22
22
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'rakuten_web_service'
|
3
2
|
|
4
3
|
describe RakutenWebService::Ichiba::Shop do
|
5
4
|
let(:params) do
|
@@ -8,7 +7,7 @@ describe RakutenWebService::Ichiba::Shop do
|
|
8
7
|
'shopUrl' => 'http://www.rakuten.co.jp/hogeshop' }
|
9
8
|
end
|
10
9
|
let(:shop) { RakutenWebService::Ichiba::Shop.new(params) }
|
11
|
-
let(:endpoint) { 'https://app.rakuten.co.jp/services/api/IchibaItem/Search/
|
10
|
+
let(:endpoint) { 'https://app.rakuten.co.jp/services/api/IchibaItem/Search/20140222' }
|
12
11
|
let(:affiliate_id) { 'dummy_affiliate_id' }
|
13
12
|
let(:application_id) { 'dummy_application_id' }
|
14
13
|
let(:expected_query) do
|
@@ -20,7 +19,7 @@ describe RakutenWebService::Ichiba::Shop do
|
|
20
19
|
end
|
21
20
|
|
22
21
|
before do
|
23
|
-
RakutenWebService.
|
22
|
+
RakutenWebService.configure do |c|
|
24
23
|
c.affiliate_id = affiliate_id
|
25
24
|
c.application_id = application_id
|
26
25
|
end
|
@@ -1,10 +1,9 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
|
-
require 'rakuten_web_service'
|
5
4
|
|
6
5
|
describe RakutenWebService::Kobo::Ebook do
|
7
|
-
let(:endpoint) { 'https://app.rakuten.co.jp/services/api/Kobo/EbookSearch/
|
6
|
+
let(:endpoint) { 'https://app.rakuten.co.jp/services/api/Kobo/EbookSearch/20140811' }
|
8
7
|
let(:affiliate_id) { 'dummy_affiliate_id' }
|
9
8
|
let(:application_id) { 'dummy_application_id' }
|
10
9
|
let(:expected_query) do
|
@@ -16,7 +15,7 @@ describe RakutenWebService::Kobo::Ebook do
|
|
16
15
|
end
|
17
16
|
|
18
17
|
before do
|
19
|
-
RakutenWebService.
|
18
|
+
RakutenWebService.configure do |c|
|
20
19
|
c.affiliate_id = affiliate_id
|
21
20
|
c.application_id = application_id
|
22
21
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'rakuten_web_service'
|
3
2
|
|
4
3
|
describe RWS::Kobo::Genre do
|
5
4
|
let(:endpoint) { 'https://app.rakuten.co.jp/services/api/Kobo/GenreSearch/20131010' }
|
@@ -22,7 +21,7 @@ describe RWS::Kobo::Genre do
|
|
22
21
|
with(:query => expected_query).
|
23
22
|
to_return(:body => expected_json.to_json)
|
24
23
|
|
25
|
-
RakutenWebService.
|
24
|
+
RakutenWebService.configure do |c|
|
26
25
|
c.affiliate_id = affiliate_id
|
27
26
|
c.application_id = application_id
|
28
27
|
end
|
@@ -0,0 +1,185 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RakutenWebService::Recipe::Category do
|
4
|
+
let(:endpoint) { 'https://app.rakuten.co.jp/services/api/Recipe/CategoryList/20121121' }
|
5
|
+
let(:affiliate_id) { 'dummy_affiliate_id' }
|
6
|
+
let(:application_id) { 'dummy_application_id' }
|
7
|
+
let(:expected_query) do
|
8
|
+
{
|
9
|
+
:affiliateId => affiliate_id,
|
10
|
+
:applicationId => application_id,
|
11
|
+
:categoryType => category_type
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
before do
|
16
|
+
RakutenWebService.configure do |c|
|
17
|
+
c.affiliate_id = affiliate_id
|
18
|
+
c.application_id = application_id
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '.large_categories' do
|
23
|
+
let(:category_type) { 'large' }
|
24
|
+
|
25
|
+
before do
|
26
|
+
response = JSON.parse(fixture('recipe/category.json'))
|
27
|
+
|
28
|
+
@expected_request = stub_request(:get, endpoint).
|
29
|
+
with(query: expected_query).to_return(body: response.to_json)
|
30
|
+
end
|
31
|
+
|
32
|
+
after do
|
33
|
+
RWS::Recipe.instance_variable_set(:@categories, nil)
|
34
|
+
end
|
35
|
+
|
36
|
+
subject { RakutenWebService::Recipe.large_categories }
|
37
|
+
|
38
|
+
it 'should return' do
|
39
|
+
expect(subject).to be_a(Array)
|
40
|
+
end
|
41
|
+
it 'should call the endpoint once' do
|
42
|
+
subject.first
|
43
|
+
|
44
|
+
expect(@expected_request).to have_been_made.once
|
45
|
+
end
|
46
|
+
it 'should be Category resources' do
|
47
|
+
expect(subject).to be_all { |c| c.is_a?(RakutenWebService::Recipe::Category) }
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'When called twice or more' do
|
51
|
+
specify 'should call the endpoint only once' do
|
52
|
+
2.times { RakutenWebService::Recipe.large_categories }
|
53
|
+
|
54
|
+
expect(@expected_request).to have_been_made.once
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '.medium_categories' do
|
60
|
+
it 'should call categories' do
|
61
|
+
expect(RWS::Recipe).to receive(:categories).with('medium')
|
62
|
+
|
63
|
+
RakutenWebService::Recipe.medium_categories
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe '.small_categories' do
|
68
|
+
it 'should call categories' do
|
69
|
+
expect(RWS::Recipe).to receive(:categories).with('small')
|
70
|
+
|
71
|
+
RakutenWebService::Recipe.small_categories
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "#parent_category" do
|
77
|
+
let(:category) do
|
78
|
+
RWS::Recipe::Category.new \
|
79
|
+
categoryId: 2007,
|
80
|
+
categoryName: 'もち麦',
|
81
|
+
categoryType: 'small',
|
82
|
+
parentCategoryId: '706'
|
83
|
+
end
|
84
|
+
let(:category_type) { 'medium' }
|
85
|
+
|
86
|
+
before do
|
87
|
+
response = JSON.parse(fixture('recipe/category.json'))
|
88
|
+
|
89
|
+
@expected_request = stub_request(:get, endpoint).
|
90
|
+
with(query: expected_query).to_return(body: response.to_json)
|
91
|
+
end
|
92
|
+
|
93
|
+
after do
|
94
|
+
RakutenWebService::Recipe.instance_variable_set(:@categories, nil)
|
95
|
+
end
|
96
|
+
|
97
|
+
subject { category.parent_category }
|
98
|
+
|
99
|
+
it "should be a Category" do
|
100
|
+
expect(subject).to be_a(RWS::Recipe::Category)
|
101
|
+
end
|
102
|
+
it "should call the endpoint once to get medium categories" do
|
103
|
+
subject
|
104
|
+
expect(@expected_request).to have_been_made.once
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe '#absolute_category_id' do
|
109
|
+
let(:category) do
|
110
|
+
RWS::Recipe::Category.new \
|
111
|
+
categoryId: 706,
|
112
|
+
categoryName: 'もち麦',
|
113
|
+
categoryType: 'medium',
|
114
|
+
parentCategoryId: '13'
|
115
|
+
end
|
116
|
+
let(:category_type) { 'large' }
|
117
|
+
|
118
|
+
before do
|
119
|
+
response = JSON.parse(fixture('recipe/category.json'))
|
120
|
+
|
121
|
+
@expected_request = stub_request(:get, endpoint).
|
122
|
+
with(query: expected_query).to_return(body: response.to_json)
|
123
|
+
end
|
124
|
+
|
125
|
+
after do
|
126
|
+
RakutenWebService::Recipe.instance_variable_set(:@categories, nil)
|
127
|
+
end
|
128
|
+
|
129
|
+
subject { category.absolute_category_id }
|
130
|
+
|
131
|
+
it "should be concatinations with parent category ids" do
|
132
|
+
expect(subject).to be_eql("13-706")
|
133
|
+
end
|
134
|
+
|
135
|
+
context 'for small category' do
|
136
|
+
let(:category) do
|
137
|
+
RWS::Recipe::Category.new \
|
138
|
+
categoryId: 2007,
|
139
|
+
categoryName: 'もち麦',
|
140
|
+
categoryType: 'small',
|
141
|
+
parentCategoryId: '706'
|
142
|
+
end
|
143
|
+
|
144
|
+
before do
|
145
|
+
response = JSON.parse(fixture('recipe/category.json'))
|
146
|
+
|
147
|
+
stub_request(:get, endpoint).
|
148
|
+
with(query: expected_query.merge(categoryType: 'medium')).
|
149
|
+
to_return(body: response.to_json)
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'should concatinations with parent category ids' do
|
153
|
+
expect(subject).to be_eql("13-706-2007")
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe '#ranking' do
|
159
|
+
let(:category) do
|
160
|
+
RWS::Recipe::Category.new \
|
161
|
+
categoryId: 706,
|
162
|
+
categoryName: 'もち麦',
|
163
|
+
categoryType: 'medium',
|
164
|
+
parentCategoryId: '13'
|
165
|
+
end
|
166
|
+
let(:category_type) { 'large' }
|
167
|
+
|
168
|
+
before do
|
169
|
+
response = JSON.parse(fixture('recipe/category.json'))
|
170
|
+
|
171
|
+
@expected_request = stub_request(:get, endpoint).
|
172
|
+
with(query: expected_query).to_return(body: response.to_json)
|
173
|
+
end
|
174
|
+
|
175
|
+
after do
|
176
|
+
RakutenWebService::Recipe.instance_variable_set(:@categories, nil)
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'should call ranking method with category codes' do
|
180
|
+
expect(RakutenWebService::Recipe).to receive(:ranking).with('13-706')
|
181
|
+
|
182
|
+
category.ranking
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|