base-api-client 0.1.beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.bundle/config +3 -0
- data/.gitignore +8 -0
- data/.rspec +3 -0
- data/Gemfile +13 -0
- data/Guardfile +71 -0
- data/LICENSE +201 -0
- data/base-api-client.gemspec +18 -0
- data/config/client_secret.json +10 -0
- data/lib/base/api_client/client_secret.rb +134 -0
- data/lib/base/apis/category.rb +21 -0
- data/lib/base/apis/delivery_company.rb +21 -0
- data/lib/base/apis/item_category/detail.rb +27 -0
- data/lib/base/apis/order.rb +36 -0
- data/lib/base/apis/saving.rb +36 -0
- data/lib/base/apis/search.rb +55 -0
- data/lib/base/apis.rb +20 -0
- data/spec/base/api_client/client_secret_spec.rb +321 -0
- data/spec/base/apis/category_spec.rb +22 -0
- data/spec/base/apis/delivery_company_spec.rb +26 -0
- data/spec/base/apis/item_category/detail_spec.rb +24 -0
- data/spec/base/apis/order_spec.rb +22 -0
- data/spec/base/apis/saving_spec.rb +22 -0
- data/spec/base/apis/search_spec.rb +81 -0
- data/spec/fixtures/files/client_secret.json +10 -0
- data/spec/fixtures/vcr_cassettes/Category_request.yml +81 -0
- data/spec/fixtures/vcr_cassettes/ClientSecret_my_info.yml +42 -0
- data/spec/fixtures/vcr_cassettes/ClientSecret_my_items.yml +43 -0
- data/spec/fixtures/vcr_cassettes/DeliveryCompany_request.yml +85 -0
- data/spec/fixtures/vcr_cassettes/Detail_request.yml +81 -0
- data/spec/fixtures/vcr_cassettes/Order_request.yml +81 -0
- data/spec/fixtures/vcr_cassettes/Saving_request.yml +81 -0
- data/spec/fixtures/vcr_cassettes/Search_request.yml +116 -0
- data/spec/spec_helper.rb +34 -0
- data/spec/support/shared_examples_spec.rb +11 -0
- metadata +111 -0
data/lib/base/apis.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'pathname'
|
4
|
+
require 'multi_json'
|
5
|
+
require 'os'
|
6
|
+
|
7
|
+
module Base
|
8
|
+
module Apis
|
9
|
+
ROOT = Pathname(File.expand_path('.'))
|
10
|
+
API_HOST = Pathname('https://api.thebase.in')
|
11
|
+
API_VERSION = '1'.freeze
|
12
|
+
|
13
|
+
CONFIG =
|
14
|
+
{ DEFAULT:
|
15
|
+
{ CLIENT_SECRET:
|
16
|
+
{ PATH: ROOT / 'config/client_secret.json' } } }.freeze
|
17
|
+
|
18
|
+
Dir.glob(ROOT / 'lib/base/api*/**/*.rb').each { |file| require file }
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,321 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Base::APIClient::ClientSecret do
|
4
|
+
subject { Base::APIClient::ClientSecret.new }
|
5
|
+
let(:secret_file) { FIXTURES_PATH / 'files' / 'client_secret.json' }
|
6
|
+
let(:data) { MultiJson.load(File.open(secret_file, 'r').read) }
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
allow_any_instance_of(Base::APIClient::ClientSecret)
|
10
|
+
.to receive(:fetch_token) do
|
11
|
+
{ access_token: 'fake_access_token',
|
12
|
+
refresh_token: 'fake_refresh_token' }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#load_file' do
|
17
|
+
it 'reads client_secret.json' do
|
18
|
+
obj = instance_double('ClientSecret')
|
19
|
+
allow(obj).to receive(:load_file) { data }
|
20
|
+
expect(obj.send(:load_file)).to eq data
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '::new' do
|
25
|
+
describe 'existence of instance variables' do
|
26
|
+
it 'has @client_id' do
|
27
|
+
expect(subject).to respond_to(:client_id)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'has @client_secret' do
|
31
|
+
expect(subject).to respond_to(:client_secret)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'has @code' do
|
35
|
+
expect(subject).to respond_to(:code)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'has @redirect_uri' do
|
39
|
+
expect(subject).to respond_to(:redirect_uri)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'has @search_client_id' do
|
43
|
+
expect(subject).to respond_to(:search_client_id)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'has @search_client_secret' do
|
47
|
+
expect(subject).to respond_to(:search_client_secret)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe 'without parameters' do
|
52
|
+
it 'instance variables have correct values' do
|
53
|
+
expect(subject.client_id).to eq 'fake_client_id'
|
54
|
+
expect(subject.client_secret).to eq 'fake_client_secret'
|
55
|
+
expect(subject.code).to eq 'fake_code'
|
56
|
+
expect(subject.redirect_uri).to eq 'http://fake_redirect_uri.com'
|
57
|
+
expect(subject.search_client_id).to eq 'fake_search_client_id'
|
58
|
+
expect(subject.search_client_secret).to eq 'fake_search_client_secret'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe 'with parameters' do
|
63
|
+
subject do
|
64
|
+
Base::APIClient::ClientSecret.new do |zelf|
|
65
|
+
zelf.client_id = 'optional_client_id'
|
66
|
+
zelf.client_secret = 'optional_client_secret'
|
67
|
+
zelf.code = 'optional_code'
|
68
|
+
zelf.redirect_uri = 'optional_redirect_uri'
|
69
|
+
zelf.search_client_id = 'optional_search_client_id'
|
70
|
+
zelf.search_client_secret = 'optional_search_client_secret'
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe 'content of variables' do
|
75
|
+
it 'set the variable by given value' do
|
76
|
+
expect(subject.client_id).to eq 'optional_client_id'
|
77
|
+
expect(subject.client_secret).to eq 'optional_client_secret'
|
78
|
+
expect(subject.code).to eq 'optional_code'
|
79
|
+
expect(subject.redirect_uri).to eq 'optional_redirect_uri'
|
80
|
+
expect(subject.search_client_id).to eq 'optional_search_client_id'
|
81
|
+
expect(subject.search_client_secret).to eq \
|
82
|
+
'optional_search_client_secret'
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe '#update' do
|
89
|
+
it 'update attributes of the instance' do
|
90
|
+
subject.update! do |zelf|
|
91
|
+
zelf.client_id = 'updated_client_id'
|
92
|
+
zelf.client_secret = 'updated_client_secret'
|
93
|
+
zelf.code = 'updated_code'
|
94
|
+
zelf.redirect_uri = 'updated_redirect_uri'
|
95
|
+
zelf.search_client_id = 'updated_search_client_id'
|
96
|
+
zelf.search_client_secret = 'updated_search_client_secret'
|
97
|
+
end
|
98
|
+
|
99
|
+
expect(subject.client_id).to eq 'updated_client_id'
|
100
|
+
expect(subject.client_secret).to eq 'updated_client_secret'
|
101
|
+
expect(subject.code).to eq 'updated_code'
|
102
|
+
expect(subject.redirect_uri).to eq 'updated_redirect_uri'
|
103
|
+
expect(subject.search_client_id).to eq 'updated_search_client_id'
|
104
|
+
expect(subject.search_client_secret).to eq 'updated_search_client_secret'
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe '#header_parameter' do
|
109
|
+
it 'returns correct parameter' do
|
110
|
+
subject.instance_variable_set(:@access_token, 'fake_access_token')
|
111
|
+
expect(subject.header_parameter).to eq(
|
112
|
+
'Authorization' => 'Bearer fake_access_token')
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe '#to_hash' do
|
117
|
+
it 'returns values of instance variables in hash' do
|
118
|
+
expect(subject.send(:to_hash)).to eq(
|
119
|
+
client_id: 'fake_client_id',
|
120
|
+
client_secret: 'fake_client_secret',
|
121
|
+
code: 'fake_code',
|
122
|
+
redirect_uri: 'http://fake_redirect_uri.com',
|
123
|
+
refresh_token: nil,
|
124
|
+
search_client_id: 'fake_search_client_id',
|
125
|
+
search_client_secret: 'fake_search_client_secret')
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe '#to_json' do
|
130
|
+
it 'returns values of instance variables in json' do
|
131
|
+
expect(subject.send(:to_json)).to eq \
|
132
|
+
<<"EOS""{\"client_id\":\"fake_client_id\",\"client_secret\":\"fake_client_secret\",\"code\":\"fake_code\",\"redirect_uri\":\"http://fake_redirect_uri.com\",\"refresh_token\":null,\"search_client_id\":\"fake_search_client_id\",\"search_client_secret\":\"fake_search_client_secret\"}"
|
133
|
+
EOS
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe '#generate_authorize_parameters' do
|
138
|
+
it 'returns parameters' do
|
139
|
+
expect(subject.send(:generate_authorize_parameters)).to eq \
|
140
|
+
<<"EOS""?client_id=fake_client_id&redirect_uri=http://fake_redirect_uri.com&state=&response_type=code&scope=read_items read_orders read_savings read_users read_users_mail write_items write_orders"
|
141
|
+
EOS
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
describe '#command' do
|
146
|
+
context 'OS is Linux' do
|
147
|
+
it 'returns "sensible-browser"' do
|
148
|
+
allow(OS).to receive(:linux?) { true }
|
149
|
+
expect(subject.send(:command)).to eq 'sensible-browser'
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context 'OS is OSX' do
|
154
|
+
it 'returns "open"' do
|
155
|
+
allow(OS).to receive(:linux?) { false }
|
156
|
+
allow(OS).to receive(:mac?) { true }
|
157
|
+
expect(subject.send(:command)).to eq 'open'
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
describe '#generate_code' do
|
163
|
+
context 'OS is Linux' do
|
164
|
+
before(:each) do
|
165
|
+
allow(subject).to receive(:command) { 'sensible-browser' }
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'call sensible-browser' do
|
169
|
+
expect(subject).to receive(:system).with(
|
170
|
+
'sensible-browser',
|
171
|
+
'https://api.thebase.in/1/oauth/authorize?client_id=fake_client_id&redirect_uri=http://fake_redirect_uri.com&state=&response_type=code&scope=read_items read_orders read_savings read_users read_users_mail write_items write_orders')
|
172
|
+
|
173
|
+
subject.send(:generate_code)
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'returns ture' do
|
177
|
+
allow(subject).to receive(:generate_code) { true }
|
178
|
+
expect(subject.send(:generate_code)).to eq true
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
context 'OS is OSX' do
|
183
|
+
before(:each) do
|
184
|
+
allow(subject).to receive(:command) { 'open' }
|
185
|
+
end
|
186
|
+
|
187
|
+
it 'call open' do
|
188
|
+
expect(subject).to receive(:system).with(
|
189
|
+
'open',
|
190
|
+
'https://api.thebase.in/1/oauth/authorize?client_id=fake_client_id&redirect_uri=http://fake_redirect_uri.com&state=&response_type=code&scope=read_items read_orders read_savings read_users read_users_mail write_items write_orders')
|
191
|
+
|
192
|
+
subject.send(:generate_code)
|
193
|
+
end
|
194
|
+
|
195
|
+
it 'returns ture' do
|
196
|
+
allow(subject).to receive(:generate_code) { true }
|
197
|
+
expect(subject.send(:generate_code)).to eq true
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
describe '#fetch_token' do
|
203
|
+
context 'passed arg "refresh: false"' do
|
204
|
+
let(:arg) { { refresh: false } }
|
205
|
+
|
206
|
+
it 'returns access and refresh tokens' do
|
207
|
+
stub_request(
|
208
|
+
:post,
|
209
|
+
URI.parse(Base::APIClient::ClientSecret::TOKEN_URI.to_s))
|
210
|
+
.with(body:
|
211
|
+
subject
|
212
|
+
.send(:to_hash)
|
213
|
+
.merge(grant_type: 'authorization_code'))
|
214
|
+
|
215
|
+
expect(subject.send(:fetch_token, arg)).to eq(
|
216
|
+
access_token: 'fake_access_token',
|
217
|
+
refresh_token: 'fake_refresh_token')
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
context 'passed arg "refresh: true"' do
|
222
|
+
let(:arg) { { refresh: true } }
|
223
|
+
|
224
|
+
it 'returns access and refresh tokens' do
|
225
|
+
stub_request(
|
226
|
+
:post,
|
227
|
+
URI.parse(Base::APIClient::ClientSecret::TOKEN_URI.to_s))
|
228
|
+
.with(body:
|
229
|
+
subject
|
230
|
+
.send(:to_hash)
|
231
|
+
.merge(grant_type: 'refresh_token'))
|
232
|
+
|
233
|
+
expect(subject.send(:fetch_token, arg)).to eq(
|
234
|
+
access_token: 'fake_access_token',
|
235
|
+
refresh_token: 'fake_refresh_token')
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
describe '#set_tokens!' do
|
241
|
+
context 'passed arg "refresh: false"' do
|
242
|
+
let(:arg) { { refresh: false } }
|
243
|
+
|
244
|
+
it 'set access and refresh tokens' do
|
245
|
+
allow(subject).to receive(:fetch_token) do
|
246
|
+
{ 'access_token' => 'stubbed_access_token',
|
247
|
+
'refresh_token' => 'stubbed_refresh_token' }
|
248
|
+
end
|
249
|
+
|
250
|
+
subject.send(:set_tokens!, arg)
|
251
|
+
expect(subject.access_token).to eq 'stubbed_access_token'
|
252
|
+
expect(subject.refresh_token).to eq 'stubbed_refresh_token'
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
context 'passed arg "refresh: true"' do
|
257
|
+
let(:arg) { { refresh: true } }
|
258
|
+
|
259
|
+
it 'set access and refresh tokens' do
|
260
|
+
allow(subject).to receive(:fetch_token).with(arg) do
|
261
|
+
{ 'access_token' => 'stubbed_access_token',
|
262
|
+
'refresh_token' => 'stubbed_refresh_token' }
|
263
|
+
end
|
264
|
+
|
265
|
+
subject.send(:set_tokens!, arg)
|
266
|
+
expect(subject.access_token).to eq 'stubbed_access_token'
|
267
|
+
expect(subject.refresh_token).to eq 'stubbed_refresh_token'
|
268
|
+
end
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
describe '#my_info' do
|
273
|
+
let(:response) do
|
274
|
+
VCR.use_cassette('ClientSecret_my_info') { subject.my_info }
|
275
|
+
end
|
276
|
+
|
277
|
+
it 'contains code "200"' do
|
278
|
+
expect(response.code).to eq '200'
|
279
|
+
end
|
280
|
+
|
281
|
+
it '@body contains information of the user' do
|
282
|
+
expect(response.body).to match(/user/)
|
283
|
+
expect(response.body).to match(/shop_id/)
|
284
|
+
expect(response.body).to match(/shop_name/)
|
285
|
+
expect(response.body).to match(/shop_introduction/)
|
286
|
+
expect(response.body).to match(/shop_url/)
|
287
|
+
expect(response.body).to match(/twitter_id/)
|
288
|
+
expect(response.body).to match(/facebook_id/)
|
289
|
+
expect(response.body).to match(/ameba_id/)
|
290
|
+
expect(response.body).to match(/instagram_id/)
|
291
|
+
expect(response.body).to match(/background/)
|
292
|
+
expect(response.body).to match(/display_background/)
|
293
|
+
expect(response.body).to match(/repeat_background/)
|
294
|
+
expect(response.body).to match(/logo/)
|
295
|
+
expect(response.body).to match(/display_logo/)
|
296
|
+
expect(response.body).to match(/mail_address/)
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
describe '#my_items' do
|
301
|
+
let(:response) do
|
302
|
+
VCR.use_cassette('ClientSecret_my_items') { subject.my_items }
|
303
|
+
end
|
304
|
+
|
305
|
+
it 'contains code "200"' do
|
306
|
+
expect(response.code).to eq '200'
|
307
|
+
end
|
308
|
+
|
309
|
+
it '@body contains information of the items' do
|
310
|
+
expect(response.body).to match(/items/)
|
311
|
+
expect(response.body).to match(/item_id/)
|
312
|
+
expect(response.body).to match(/title/)
|
313
|
+
expect(response.body).to match(/detail/)
|
314
|
+
expect(response.body).to match(/price/)
|
315
|
+
expect(response.body).to match(/stock/)
|
316
|
+
expect(response.body).to match(/visible/)
|
317
|
+
expect(response.body).to match(/list_order/)
|
318
|
+
expect(response.body).to match(/identifier/)
|
319
|
+
end
|
320
|
+
end
|
321
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Base::Apis::Category do
|
4
|
+
let(:client_secret) { Base::APIClient::ClientSecret.new }
|
5
|
+
subject { Base::Apis::Category.new client_secret }
|
6
|
+
|
7
|
+
describe '::new' do
|
8
|
+
include_examples 'Base::Apis::Something.new'
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#request' do
|
12
|
+
let(:response) { VCR.use_cassette('Category_request') { subject.request } }
|
13
|
+
|
14
|
+
it 'contains code "200"' do
|
15
|
+
expect(response.code).to eq '200'
|
16
|
+
end
|
17
|
+
|
18
|
+
it '@body contains categories' do
|
19
|
+
expect(response.body).to match(/categories/)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Base::Apis::DeliveryCompany do
|
4
|
+
let(:client_secret) { Base::APIClient::ClientSecret.new }
|
5
|
+
subject { Base::Apis::DeliveryCompany.new client_secret }
|
6
|
+
|
7
|
+
describe '::new' do
|
8
|
+
include_examples 'Base::Apis::Something.new'
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#request' do
|
12
|
+
let(:response) do
|
13
|
+
VCR.use_cassette('DeliveryCompany_request') { subject.request }
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'contains code "200"' do
|
17
|
+
expect(response.code).to eq '200'
|
18
|
+
end
|
19
|
+
|
20
|
+
it '@body contains information of the delivery companies' do
|
21
|
+
expect(response.body).to match(/delivery_companies/)
|
22
|
+
expect(response.body).to match(/delivery_company_id/)
|
23
|
+
expect(response.body).to match(/name/)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Base::Apis::ItemCategory::Detail do
|
4
|
+
let(:client_secret) { Base::APIClient::ClientSecret.new }
|
5
|
+
subject { Base::Apis::ItemCategory::Detail.new client_secret }
|
6
|
+
|
7
|
+
describe '::new' do
|
8
|
+
include_examples('Base::Apis::Something.new')
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#request' do
|
12
|
+
let(:response) do
|
13
|
+
VCR.use_cassette('Detail_request') { subject.request(2453256) }
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'contains code "200"' do
|
17
|
+
expect(response.code).to eq '200'
|
18
|
+
end
|
19
|
+
|
20
|
+
it '@body contains categories' do
|
21
|
+
expect(response.body).to match(/item_categories/)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Base::Apis::Order do
|
4
|
+
let(:client_secret) { Base::APIClient::ClientSecret.new }
|
5
|
+
subject { Base::Apis::Order.new client_secret }
|
6
|
+
|
7
|
+
describe '::new' do
|
8
|
+
include_examples 'Base::Apis::Something.new'
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#request' do
|
12
|
+
let(:response) { VCR.use_cassette('Order_request') { subject.request } }
|
13
|
+
|
14
|
+
it 'contains code "200"' do
|
15
|
+
expect(response.code).to eq '200'
|
16
|
+
end
|
17
|
+
|
18
|
+
it '@body contains orders' do
|
19
|
+
expect(response.body).to match(/orders/)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Base::Apis::Saving do
|
4
|
+
let(:client_secret) { Base::APIClient::ClientSecret.new }
|
5
|
+
subject { Base::Apis::Saving.new client_secret }
|
6
|
+
|
7
|
+
describe '::new' do
|
8
|
+
include_examples 'Base::Apis::Something.new'
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#request' do
|
12
|
+
let(:response) { VCR.use_cassette('Saving_request') { subject.request } }
|
13
|
+
|
14
|
+
it 'contains code "200"' do
|
15
|
+
expect(response.code).to eq '200'
|
16
|
+
end
|
17
|
+
|
18
|
+
it '@body contains saving' do
|
19
|
+
expect(response.body).to match(/saving/)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Base::Apis::Search do
|
4
|
+
let(:client_secret) { Base::APIClient::ClientSecret.new }
|
5
|
+
subject { Base::Apis::Search.new client_secret }
|
6
|
+
let(:query) { '白 シャツ 綿' }
|
7
|
+
let(:request_parameters) do
|
8
|
+
{ client_id: '623f75000821c16163ec570ca6469539',
|
9
|
+
client_secret: 'e321f43620ac47bc92f83e766107d78c',
|
10
|
+
q: query }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '::new' do
|
14
|
+
include_examples 'Base::Apis::Something.new'
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#request' do
|
18
|
+
let(:response) do
|
19
|
+
VCR.use_cassette('Search_request') { subject.request(query) }
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'contains code "200"' do
|
23
|
+
expect(response.code).to eq '200'
|
24
|
+
end
|
25
|
+
|
26
|
+
it '@body contains searched items info' do
|
27
|
+
expect(response.body).to match(/found/)
|
28
|
+
expect(response.body).to match(/items/)
|
29
|
+
expect(response.body).to match(/item_id/)
|
30
|
+
expect(response.body).to match(/title/)
|
31
|
+
expect(response.body).to match(/detail/)
|
32
|
+
expect(response.body).to match(/price/)
|
33
|
+
expect(response.body).to match(/stock/)
|
34
|
+
expect(response.body).to match(/modified/)
|
35
|
+
expect(response.body).to match(/shop_id/)
|
36
|
+
expect(response.body).to match(/shop_name/)
|
37
|
+
expect(response.body).to match(/shop_url/)
|
38
|
+
expect(response.body).to match(/categories/)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#request_parameters=' do
|
43
|
+
it 'returns request_parameters' do
|
44
|
+
client_secret = instance_double('Base::Apis::ClientSecret')
|
45
|
+
|
46
|
+
client_secret.instance_variable_set(
|
47
|
+
:@search_client_id,
|
48
|
+
'623f75000821c16163ec570ca6469539')
|
49
|
+
|
50
|
+
client_secret.instance_variable_set(
|
51
|
+
:@search_client_secret,
|
52
|
+
'e321f43620ac47bc92f83e766107d78c')
|
53
|
+
|
54
|
+
allow(subject).to receive(:client_secret) { client_secret }
|
55
|
+
|
56
|
+
expect(subject).to respond_to(:request_parameters) do
|
57
|
+
{ client_id: '623f75000821c16163ec570ca6469539',
|
58
|
+
client_secret: 'e321f43620ac47bc92f83e766107d78c',
|
59
|
+
q: '白 シャツ 綿' }
|
60
|
+
end
|
61
|
+
|
62
|
+
subject.send(:request_parameters=, '白 シャツ 綿')
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '#uri=' do
|
67
|
+
it 'has instance variable @uri' do
|
68
|
+
expect(subject).to respond_to(:uri)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'returns an object of URI::HTTPS' do
|
72
|
+
expect(subject.send(:uri=, request_parameters)).to \
|
73
|
+
be_kind_of URI::HTTPS
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'return value to_s is uri like' do
|
77
|
+
expect(subject.send(:uri=, request_parameters).to_s).to eq \
|
78
|
+
'https://api.thebase.in/1/search?client_id=623f75000821c16163ec570ca6469539&client_secret=e321f43620ac47bc92f83e766107d78c&q=%E7%99%BD+%E3%82%B7%E3%83%A3%E3%83%84+%E7%B6%BF'
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://api.thebase.in/1/oauth/token
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: client_id=e0920d3fba627a5da4eaab4e8e9d43fc&client_secret=a7eae9a2903235465e9b43c1116e2046&code=614e48613d8f347eb00444a40fd9e47c&redirect_uri=http%3A%2F%2Flocalhost.local&refresh_token&search_client_id=623f75000821c16163ec570ca6469539&search_client_secret=a52ad8525921ca9a40fee47a38ca429d&grant_type=authorization_code
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- "*/*"
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
Host:
|
17
|
+
- api.thebase.in
|
18
|
+
Content-Type:
|
19
|
+
- application/x-www-form-urlencoded
|
20
|
+
response:
|
21
|
+
status:
|
22
|
+
code: 200
|
23
|
+
message: OK
|
24
|
+
headers:
|
25
|
+
Content-Type:
|
26
|
+
- application/json; charset=UTF-8
|
27
|
+
Date:
|
28
|
+
- Mon, 08 Feb 2016 13:51:52 GMT
|
29
|
+
Server:
|
30
|
+
- Apache
|
31
|
+
Vary:
|
32
|
+
- Accept-Encoding,User-Agent
|
33
|
+
Content-Length:
|
34
|
+
- '132'
|
35
|
+
Connection:
|
36
|
+
- keep-alive
|
37
|
+
body:
|
38
|
+
encoding: ASCII-8BIT
|
39
|
+
string: '{"access_token":"cb502f8cd62733e805182af85dc86f5d","token_type":"bearer","expires_in":3600,"refresh_token":"8aa0c1d633af7f25909c689e49aab0a1"}'
|
40
|
+
http_version:
|
41
|
+
recorded_at: Mon, 08 Feb 2016 13:51:53 GMT
|
42
|
+
- request:
|
43
|
+
method: get
|
44
|
+
uri: https://api.thebase.in/1/categories
|
45
|
+
body:
|
46
|
+
encoding: US-ASCII
|
47
|
+
string: ''
|
48
|
+
headers:
|
49
|
+
Authorization:
|
50
|
+
- Bearer cb502f8cd62733e805182af85dc86f5d
|
51
|
+
Accept-Encoding:
|
52
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
53
|
+
Accept:
|
54
|
+
- "*/*"
|
55
|
+
User-Agent:
|
56
|
+
- Ruby
|
57
|
+
Host:
|
58
|
+
- api.thebase.in
|
59
|
+
response:
|
60
|
+
status:
|
61
|
+
code: 200
|
62
|
+
message: OK
|
63
|
+
headers:
|
64
|
+
Content-Type:
|
65
|
+
- application/json; charset=UTF-8
|
66
|
+
Date:
|
67
|
+
- Mon, 08 Feb 2016 13:51:53 GMT
|
68
|
+
Server:
|
69
|
+
- Apache
|
70
|
+
Vary:
|
71
|
+
- Accept-Encoding,User-Agent
|
72
|
+
Content-Length:
|
73
|
+
- '37'
|
74
|
+
Connection:
|
75
|
+
- keep-alive
|
76
|
+
body:
|
77
|
+
encoding: ASCII-8BIT
|
78
|
+
string: '{"categories":[]}'
|
79
|
+
http_version:
|
80
|
+
recorded_at: Mon, 08 Feb 2016 13:51:53 GMT
|
81
|
+
recorded_with: VCR 3.0.1
|
@@ -0,0 +1,42 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api.thebase.in/1/users/me
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Authorization:
|
11
|
+
- Bearer d1347e05cf1441ec9770c2362580a5a5
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
14
|
+
Accept:
|
15
|
+
- "*/*"
|
16
|
+
User-Agent:
|
17
|
+
- Ruby
|
18
|
+
Host:
|
19
|
+
- api.thebase.in
|
20
|
+
response:
|
21
|
+
status:
|
22
|
+
code: 200
|
23
|
+
message: OK
|
24
|
+
headers:
|
25
|
+
Content-Type:
|
26
|
+
- application/json; charset=UTF-8
|
27
|
+
Date:
|
28
|
+
- Sun, 07 Feb 2016 13:39:44 GMT
|
29
|
+
Server:
|
30
|
+
- Apache
|
31
|
+
Vary:
|
32
|
+
- Accept-Encoding,User-Agent
|
33
|
+
Content-Length:
|
34
|
+
- '226'
|
35
|
+
Connection:
|
36
|
+
- keep-alive
|
37
|
+
body:
|
38
|
+
encoding: ASCII-8BIT
|
39
|
+
string: '{"user":{"shop_id":"ysksn-base-ec","shop_name":"ysksn","shop_introduction":"\u304f\u3058\u3089\u306e\u305b\u3064\u3081\u3044","shop_url":"http:\/\/ysksn.base.ec","twitter_id":"","facebook_id":"","ameba_id":"","instagram_id":"","background":null,"display_background":0,"repeat_background":1,"logo":null,"display_logo":0,"mail_address":"bluewhale1982@gmail.com"}}'
|
40
|
+
http_version:
|
41
|
+
recorded_at: Sun, 07 Feb 2016 13:39:44 GMT
|
42
|
+
recorded_with: VCR 3.0.1
|