kintone_rb 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/dependabot.yml +7 -0
- data/.github/workflows/rspec.yml +28 -0
- data/.gitignore +20 -0
- data/.rspec +1 -0
- data/.rubocop.yml +47 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +361 -0
- data/Rakefile +6 -0
- data/kintone.gemspec +30 -0
- data/lib/kintone/api/guest.rb +44 -0
- data/lib/kintone/api.rb +121 -0
- data/lib/kintone/command/accessor.rb +109 -0
- data/lib/kintone/command/apis.rb +22 -0
- data/lib/kintone/command/app.rb +11 -0
- data/lib/kintone/command/app_acl.rb +11 -0
- data/lib/kintone/command/apps.rb +12 -0
- data/lib/kintone/command/bulk_request.rb +12 -0
- data/lib/kintone/command/field_acl.rb +11 -0
- data/lib/kintone/command/file.rb +15 -0
- data/lib/kintone/command/form.rb +11 -0
- data/lib/kintone/command/guests.rb +17 -0
- data/lib/kintone/command/preview_form.rb +11 -0
- data/lib/kintone/command/record.rb +23 -0
- data/lib/kintone/command/record_acl.rb +11 -0
- data/lib/kintone/command/records.rb +29 -0
- data/lib/kintone/command/space.rb +15 -0
- data/lib/kintone/command/space_body.rb +11 -0
- data/lib/kintone/command/space_guests.rb +11 -0
- data/lib/kintone/command/space_members.rb +16 -0
- data/lib/kintone/command/space_thread.rb +14 -0
- data/lib/kintone/command/template_space.rb +12 -0
- data/lib/kintone/command.rb +12 -0
- data/lib/kintone/kintone_error.rb +12 -0
- data/lib/kintone/query/extension.rb +23 -0
- data/lib/kintone/query.rb +152 -0
- data/lib/kintone/type/extension/enumerable.rb +5 -0
- data/lib/kintone/type/extension/hash.rb +5 -0
- data/lib/kintone/type/extension/object.rb +5 -0
- data/lib/kintone/type/record.rb +11 -0
- data/lib/kintone/type.rb +6 -0
- data/lib/kintone/version.rb +3 -0
- data/lib/kintone_rb.rb +7 -0
- data/spec/kintone/api/guest_spec.rb +289 -0
- data/spec/kintone/api_spec.rb +566 -0
- data/spec/kintone/command/apis_spec.rb +179 -0
- data/spec/kintone/command/app_acl_spec.rb +43 -0
- data/spec/kintone/command/app_spec.rb +54 -0
- data/spec/kintone/command/apps_spec.rb +90 -0
- data/spec/kintone/command/bulk_request_spec.rb +92 -0
- data/spec/kintone/command/field_acl_spec.rb +47 -0
- data/spec/kintone/command/file_spec.rb +65 -0
- data/spec/kintone/command/form_spec.rb +47 -0
- data/spec/kintone/command/guests_spec.rb +107 -0
- data/spec/kintone/command/preview_form_spec.rb +30 -0
- data/spec/kintone/command/record_acl_spec.rb +48 -0
- data/spec/kintone/command/record_spec.rb +210 -0
- data/spec/kintone/command/records_spec.rb +463 -0
- data/spec/kintone/command/space_body_spec.rb +47 -0
- data/spec/kintone/command/space_guests_spec.rb +55 -0
- data/spec/kintone/command/space_members_spec.rb +117 -0
- data/spec/kintone/command/space_spec.rb +86 -0
- data/spec/kintone/command/space_thread_spec.rb +77 -0
- data/spec/kintone/command/template_space_spec.rb +59 -0
- data/spec/kintone/kintone_error_spec.rb +93 -0
- data/spec/kintone/query_spec.rb +506 -0
- data/spec/kintone/type/record_spec.rb +38 -0
- data/spec/spec_helper.rb +4 -0
- metadata +250 -0
@@ -0,0 +1,566 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'kintone/api'
|
3
|
+
require 'kintone/api/guest'
|
4
|
+
require 'kintone/command/record'
|
5
|
+
require 'kintone/command/records'
|
6
|
+
|
7
|
+
describe Kintone::Api do
|
8
|
+
let(:target) { Kintone::Api.new(domain, user, password) }
|
9
|
+
let(:domain) { 'www.example.com' }
|
10
|
+
|
11
|
+
context 'ユーザー認証の時' do
|
12
|
+
let(:user) { 'Administrator' }
|
13
|
+
let(:password) { 'cybozu' }
|
14
|
+
|
15
|
+
describe '#get_url' do
|
16
|
+
subject { target.get_url(command) }
|
17
|
+
|
18
|
+
let(:command) { 'path' }
|
19
|
+
|
20
|
+
it { is_expected.to eq('/k/v1/path.json') }
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#guest' do
|
24
|
+
subject { target.guest(space) }
|
25
|
+
|
26
|
+
context '引数が数値の1の時' do
|
27
|
+
let(:space) { 1 }
|
28
|
+
|
29
|
+
it { is_expected.to be_a_kind_of(Kintone::Api::Guest) }
|
30
|
+
it { expect(subject.instance_variable_get(:@guest_path)).to eq('/k/guest/1/v1/') }
|
31
|
+
end
|
32
|
+
|
33
|
+
context '引数がnilの時' do
|
34
|
+
let(:space) { nil }
|
35
|
+
it { expect(subject.instance_variable_get(:@guest_path)).to eq('/k/guest/0/v1/') }
|
36
|
+
end
|
37
|
+
|
38
|
+
context '引数が数字の時' do
|
39
|
+
let(:space) { '2.1' }
|
40
|
+
it { expect(subject.instance_variable_get(:@guest_path)).to eq('/k/guest/2/v1/') }
|
41
|
+
end
|
42
|
+
|
43
|
+
context '引数が数値に変換できる文字列の時' do
|
44
|
+
let(:space) { '21No' }
|
45
|
+
it { expect(subject.instance_variable_get(:@guest_path)).to eq('/k/guest/21/v1/') }
|
46
|
+
end
|
47
|
+
|
48
|
+
context '引数が数値に変換できる文字列でないとき時' do
|
49
|
+
let(:space) { 'No21' }
|
50
|
+
it { expect(subject.instance_variable_get(:@guest_path)).to eq('/k/guest/0/v1/') }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#get' do
|
55
|
+
before(:each) do
|
56
|
+
stub_request(
|
57
|
+
:get,
|
58
|
+
'https://www.example.com/k/v1/path'
|
59
|
+
)
|
60
|
+
.with(
|
61
|
+
body: params.to_h.to_json,
|
62
|
+
headers: { 'X-Cybozu-Authorization' => 'QWRtaW5pc3RyYXRvcjpjeWJvenU=' }
|
63
|
+
)
|
64
|
+
.to_return(
|
65
|
+
body: '{"abc":"def"}',
|
66
|
+
status: 200,
|
67
|
+
headers: { 'Content-type' => 'application/json' }
|
68
|
+
)
|
69
|
+
end
|
70
|
+
|
71
|
+
subject { target.get(path, params) }
|
72
|
+
|
73
|
+
let(:path) { '/k/v1/path' }
|
74
|
+
|
75
|
+
context 'with some params' do
|
76
|
+
let(:params) { { 'p1' => 'abc', 'p2' => 'def' } }
|
77
|
+
|
78
|
+
it { is_expected.to eq 'abc' => 'def' }
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'with empty params' do
|
82
|
+
let(:params) { {} }
|
83
|
+
|
84
|
+
it { is_expected.to eq 'abc' => 'def' }
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'with nil' do
|
88
|
+
let(:params) { nil }
|
89
|
+
|
90
|
+
it { is_expected.to eq 'abc' => 'def' }
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'fail to request' do
|
94
|
+
before(:each) do
|
95
|
+
stub_request(
|
96
|
+
:get,
|
97
|
+
'https://www.example.com/k/v1/path'
|
98
|
+
)
|
99
|
+
.with(
|
100
|
+
body: params.to_json,
|
101
|
+
headers: { 'X-Cybozu-Authorization' => 'QWRtaW5pc3RyYXRvcjpjeWJvenU=' }
|
102
|
+
)
|
103
|
+
.to_return(
|
104
|
+
body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
|
105
|
+
status: 500
|
106
|
+
)
|
107
|
+
end
|
108
|
+
|
109
|
+
let(:params) { {} }
|
110
|
+
|
111
|
+
it { expect { subject }.to raise_error Kintone::KintoneError }
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe '#post' do
|
116
|
+
before(:each) do
|
117
|
+
stub_request(
|
118
|
+
:post,
|
119
|
+
'https://www.example.com/k/v1/path'
|
120
|
+
)
|
121
|
+
.with(
|
122
|
+
headers: {
|
123
|
+
'X-Cybozu-Authorization' => 'QWRtaW5pc3RyYXRvcjpjeWJvenU=',
|
124
|
+
'Content-Type' => 'application/json'
|
125
|
+
},
|
126
|
+
body: '{"p1":"abc","p2":"def"}'
|
127
|
+
)
|
128
|
+
.to_return(
|
129
|
+
body: '{"abc":"def"}',
|
130
|
+
status: 200,
|
131
|
+
headers: { 'Content-type' => 'application/json' }
|
132
|
+
)
|
133
|
+
end
|
134
|
+
|
135
|
+
subject { target.post(path, body) }
|
136
|
+
let(:path) { '/k/v1/path' }
|
137
|
+
let(:body) { { 'p1' => 'abc', 'p2' => 'def' } }
|
138
|
+
|
139
|
+
it { is_expected.to eq 'abc' => 'def' }
|
140
|
+
|
141
|
+
context 'fail to request' do
|
142
|
+
before(:each) do
|
143
|
+
stub_request(
|
144
|
+
:post,
|
145
|
+
'https://www.example.com/k/v1/path'
|
146
|
+
)
|
147
|
+
.with(
|
148
|
+
headers: {
|
149
|
+
'X-Cybozu-Authorization' => 'QWRtaW5pc3RyYXRvcjpjeWJvenU=',
|
150
|
+
'Content-Type' => 'application/json'
|
151
|
+
},
|
152
|
+
body: '{"p1":"abc","p2":"def"}'
|
153
|
+
)
|
154
|
+
.to_return(
|
155
|
+
body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
|
156
|
+
status: 500
|
157
|
+
)
|
158
|
+
end
|
159
|
+
|
160
|
+
it { expect { subject }.to raise_error Kintone::KintoneError }
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
describe '#put' do
|
165
|
+
before(:each) do
|
166
|
+
stub_request(
|
167
|
+
:put,
|
168
|
+
'https://www.example.com/k/v1/path'
|
169
|
+
)
|
170
|
+
.with(
|
171
|
+
headers: {
|
172
|
+
'X-Cybozu-Authorization' => 'QWRtaW5pc3RyYXRvcjpjeWJvenU=',
|
173
|
+
'Content-Type' => 'application/json'
|
174
|
+
},
|
175
|
+
body: '{"p1":"abc","p2":"def"}'
|
176
|
+
)
|
177
|
+
.to_return(
|
178
|
+
body: '{"abc":"def"}',
|
179
|
+
status: 200,
|
180
|
+
headers: { 'Content-type' => 'application/json' }
|
181
|
+
)
|
182
|
+
end
|
183
|
+
|
184
|
+
subject { target.put(path, body) }
|
185
|
+
let(:path) { '/k/v1/path' }
|
186
|
+
let(:body) { { 'p1' => 'abc', 'p2' => 'def' } }
|
187
|
+
|
188
|
+
it { is_expected.to eq 'abc' => 'def' }
|
189
|
+
|
190
|
+
context 'fail to request' do
|
191
|
+
before(:each) do
|
192
|
+
stub_request(
|
193
|
+
:put,
|
194
|
+
'https://www.example.com/k/v1/path'
|
195
|
+
)
|
196
|
+
.with(
|
197
|
+
headers: {
|
198
|
+
'X-Cybozu-Authorization' => 'QWRtaW5pc3RyYXRvcjpjeWJvenU=',
|
199
|
+
'Content-Type' => 'application/json'
|
200
|
+
},
|
201
|
+
body: '{"p1":"abc","p2":"def"}'
|
202
|
+
)
|
203
|
+
.to_return(
|
204
|
+
body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
|
205
|
+
status: 500
|
206
|
+
)
|
207
|
+
end
|
208
|
+
|
209
|
+
it { expect { subject }.to raise_error Kintone::KintoneError }
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
describe '#delete' do
|
214
|
+
before(:each) do
|
215
|
+
stub_request(
|
216
|
+
:delete,
|
217
|
+
'https://www.example.com/k/v1/path'
|
218
|
+
)
|
219
|
+
.with(
|
220
|
+
body: { 'p1' => 'abc', 'p2' => 'def' }.to_json,
|
221
|
+
headers: { 'X-Cybozu-Authorization' => 'QWRtaW5pc3RyYXRvcjpjeWJvenU=' }
|
222
|
+
)
|
223
|
+
.to_return(
|
224
|
+
body: '{"abc":"def"}',
|
225
|
+
status: 200,
|
226
|
+
headers: { 'Content-type' => 'application/json' }
|
227
|
+
)
|
228
|
+
end
|
229
|
+
|
230
|
+
subject { target.delete(path, params) }
|
231
|
+
let(:path) { '/k/v1/path' }
|
232
|
+
let(:params) { { 'p1' => 'abc', 'p2' => 'def' } }
|
233
|
+
|
234
|
+
it { is_expected.to eq 'abc' => 'def' }
|
235
|
+
|
236
|
+
context 'fail to request' do
|
237
|
+
before(:each) do
|
238
|
+
stub_request(
|
239
|
+
:delete,
|
240
|
+
'https://www.example.com/k/v1/path'
|
241
|
+
)
|
242
|
+
.with(
|
243
|
+
body: { 'p1' => 'abc', 'p2' => 'def' }.to_json,
|
244
|
+
headers: { 'X-Cybozu-Authorization' => 'QWRtaW5pc3RyYXRvcjpjeWJvenU=' }
|
245
|
+
)
|
246
|
+
.to_return(
|
247
|
+
body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
|
248
|
+
status: 500
|
249
|
+
)
|
250
|
+
end
|
251
|
+
|
252
|
+
it { expect { subject }.to raise_error Kintone::KintoneError }
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
describe '#post_file' do
|
257
|
+
before(:each) do
|
258
|
+
stub_request(
|
259
|
+
:post,
|
260
|
+
'https://www.example.com/k/v1/path'
|
261
|
+
)
|
262
|
+
.with(headers: { 'X-Cybozu-Authorization' => 'QWRtaW5pc3RyYXRvcjpjeWJvenU=' }) { attachment } # rubocop:disable Metrics/LineLength
|
263
|
+
.to_return(
|
264
|
+
body: '{"fileKey":"abc"}',
|
265
|
+
status: 200,
|
266
|
+
headers: { 'Content-type' => 'application/json' }
|
267
|
+
)
|
268
|
+
|
269
|
+
expect(Faraday::UploadIO).to receive(:new).with(path, content_type, original_filename).and_return(attachment) # rubocop:disable Metrics/LineLength
|
270
|
+
end
|
271
|
+
|
272
|
+
subject { target.post_file(url, path, content_type, original_filename) }
|
273
|
+
let(:attachment) { double('attachment') }
|
274
|
+
let(:url) { '/k/v1/path' }
|
275
|
+
let(:path) { '/path/to/file.txt' }
|
276
|
+
let(:content_type) { 'text/plain' }
|
277
|
+
let(:original_filename) { 'fileName.txt' }
|
278
|
+
|
279
|
+
it { is_expected.to eq 'abc' }
|
280
|
+
|
281
|
+
context 'fail to request' do
|
282
|
+
before(:each) do
|
283
|
+
stub_request(
|
284
|
+
:post,
|
285
|
+
'https://www.example.com/k/v1/path'
|
286
|
+
)
|
287
|
+
.with(headers: { 'X-Cybozu-Authorization' => 'QWRtaW5pc3RyYXRvcjpjeWJvenU=' }) { attachment } # rubocop:disable Metrics/LineLength
|
288
|
+
.to_return(
|
289
|
+
body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
|
290
|
+
status: 500
|
291
|
+
)
|
292
|
+
end
|
293
|
+
|
294
|
+
it { expect { subject }.to raise_error Kintone::KintoneError }
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
describe '#record' do
|
299
|
+
subject { target.record }
|
300
|
+
|
301
|
+
it { is_expected.to be_a_kind_of(Kintone::Command::Record) }
|
302
|
+
end
|
303
|
+
|
304
|
+
describe '#records' do
|
305
|
+
subject { target.records }
|
306
|
+
|
307
|
+
it { is_expected.to be_a_kind_of(Kintone::Command::Records) }
|
308
|
+
end
|
309
|
+
|
310
|
+
describe '#form' do
|
311
|
+
subject { target.form }
|
312
|
+
|
313
|
+
it { is_expected.to be_a_kind_of(Kintone::Command::Form) }
|
314
|
+
end
|
315
|
+
|
316
|
+
describe '#app_acl' do
|
317
|
+
subject { target.app_acl }
|
318
|
+
|
319
|
+
it { is_expected.to be_a_kind_of(Kintone::Command::AppAcl) }
|
320
|
+
end
|
321
|
+
|
322
|
+
describe '#record_acl' do
|
323
|
+
subject { target.record_acl }
|
324
|
+
|
325
|
+
it { is_expected.to be_a_kind_of(Kintone::Command::RecordAcl) }
|
326
|
+
end
|
327
|
+
|
328
|
+
describe '#field_acl' do
|
329
|
+
subject { target.field_acl }
|
330
|
+
|
331
|
+
it { is_expected.to be_a_kind_of(Kintone::Command::FieldAcl) }
|
332
|
+
end
|
333
|
+
|
334
|
+
describe '#template_space' do
|
335
|
+
subject { target.template_space }
|
336
|
+
|
337
|
+
it { is_expected.to be_a_kind_of(Kintone::Command::TemplateSpace) }
|
338
|
+
end
|
339
|
+
|
340
|
+
describe '#space' do
|
341
|
+
subject { target.space }
|
342
|
+
|
343
|
+
it { is_expected.to be_a_kind_of(Kintone::Command::Space) }
|
344
|
+
end
|
345
|
+
|
346
|
+
describe '#space_body' do
|
347
|
+
subject { target.space_body }
|
348
|
+
|
349
|
+
it { is_expected.to be_a_kind_of(Kintone::Command::SpaceBody) }
|
350
|
+
end
|
351
|
+
|
352
|
+
describe '#space_thread' do
|
353
|
+
subject { target.space_thread }
|
354
|
+
|
355
|
+
it { is_expected.to be_a_kind_of(Kintone::Command::SpaceThread) }
|
356
|
+
end
|
357
|
+
|
358
|
+
describe '#space_members' do
|
359
|
+
subject { target.space_members }
|
360
|
+
|
361
|
+
it { is_expected.to be_a_kind_of(Kintone::Command::SpaceMembers) }
|
362
|
+
end
|
363
|
+
|
364
|
+
describe '#guests' do
|
365
|
+
subject { target.guests }
|
366
|
+
|
367
|
+
it { is_expected.to be_a_kind_of(Kintone::Command::Guests) }
|
368
|
+
end
|
369
|
+
|
370
|
+
describe '#app' do
|
371
|
+
subject { target.app }
|
372
|
+
|
373
|
+
it { is_expected.to be_a_kind_of(Kintone::Command::App) }
|
374
|
+
end
|
375
|
+
|
376
|
+
describe '#apps' do
|
377
|
+
subject { target.apps }
|
378
|
+
|
379
|
+
it { is_expected.to be_a_kind_of(Kintone::Command::Apps) }
|
380
|
+
end
|
381
|
+
|
382
|
+
describe '#apis' do
|
383
|
+
subject { target.apis }
|
384
|
+
|
385
|
+
it { is_expected.to be_a_kind_of(Kintone::Command::Apis) }
|
386
|
+
end
|
387
|
+
|
388
|
+
describe '#bulk_request' do
|
389
|
+
subject { target.bulk_request }
|
390
|
+
|
391
|
+
it { is_expected.to be_a_kind_of(Kintone::Command::BulkRequest) }
|
392
|
+
end
|
393
|
+
|
394
|
+
describe '#bulk' do
|
395
|
+
subject { target.bulk }
|
396
|
+
|
397
|
+
it { is_expected.to be_a_kind_of(Kintone::Command::BulkRequest) }
|
398
|
+
end
|
399
|
+
|
400
|
+
describe '#file' do
|
401
|
+
subject { target.file }
|
402
|
+
|
403
|
+
it { is_expected.to be_a_kind_of(Kintone::Command::File) }
|
404
|
+
end
|
405
|
+
|
406
|
+
describe '#preview_form' do
|
407
|
+
subject { target.preview_form }
|
408
|
+
|
409
|
+
it { is_expected.to be_a_kind_of(Kintone::Command::PreviewForm) }
|
410
|
+
end
|
411
|
+
end
|
412
|
+
|
413
|
+
context 'APIトークン認証の時' do
|
414
|
+
let(:user) { 'token-api' }
|
415
|
+
let(:password) { nil }
|
416
|
+
|
417
|
+
describe '#get' do
|
418
|
+
before(:each) do
|
419
|
+
stub_request(
|
420
|
+
:get,
|
421
|
+
'https://www.example.com/k/v1/path'
|
422
|
+
)
|
423
|
+
.with(query: query, headers: { 'X-Cybozu-API-Token' => 'token-api' })
|
424
|
+
.to_return(
|
425
|
+
body: '{"abc":"def"}',
|
426
|
+
status: 200,
|
427
|
+
headers: { 'Content-type' => 'application/json' }
|
428
|
+
)
|
429
|
+
end
|
430
|
+
|
431
|
+
subject { target.get(path, params) }
|
432
|
+
|
433
|
+
let(:path) { '/k/v1/path' }
|
434
|
+
|
435
|
+
context 'with no params' do
|
436
|
+
subject { target.get(path) }
|
437
|
+
|
438
|
+
let(:query) { nil }
|
439
|
+
|
440
|
+
it { is_expected.to eq 'abc' => 'def' }
|
441
|
+
end
|
442
|
+
end
|
443
|
+
|
444
|
+
describe '#post' do
|
445
|
+
before(:each) do
|
446
|
+
stub_request(
|
447
|
+
:post,
|
448
|
+
'https://www.example.com/k/v1/path'
|
449
|
+
)
|
450
|
+
.with(
|
451
|
+
headers: { 'X-Cybozu-API-Token' => 'token-api', 'Content-Type' => 'application/json' },
|
452
|
+
body: '{"p1":"abc","p2":"def"}'
|
453
|
+
)
|
454
|
+
.to_return(
|
455
|
+
body: '{"abc":"def"}',
|
456
|
+
status: 200,
|
457
|
+
headers: { 'Content-type' => 'application/json' }
|
458
|
+
)
|
459
|
+
end
|
460
|
+
|
461
|
+
subject { target.post(path, body) }
|
462
|
+
let(:path) { '/k/v1/path' }
|
463
|
+
let(:body) { { 'p1' => 'abc', 'p2' => 'def' } }
|
464
|
+
|
465
|
+
it { is_expected.to eq 'abc' => 'def' }
|
466
|
+
end
|
467
|
+
|
468
|
+
describe '#put' do
|
469
|
+
before(:each) do
|
470
|
+
stub_request(
|
471
|
+
:put,
|
472
|
+
'https://www.example.com/k/v1/path'
|
473
|
+
)
|
474
|
+
.with(
|
475
|
+
headers: { 'X-Cybozu-API-Token' => 'token-api', 'Content-Type' => 'application/json' },
|
476
|
+
body: '{"p1":"abc","p2":"def"}'
|
477
|
+
)
|
478
|
+
.to_return(
|
479
|
+
body: '{"abc":"def"}',
|
480
|
+
status: 200,
|
481
|
+
headers: { 'Content-type' => 'application/json' }
|
482
|
+
)
|
483
|
+
end
|
484
|
+
|
485
|
+
subject { target.put(path, body) }
|
486
|
+
let(:path) { '/k/v1/path' }
|
487
|
+
let(:body) { { 'p1' => 'abc', 'p2' => 'def' } }
|
488
|
+
|
489
|
+
it { is_expected.to eq 'abc' => 'def' }
|
490
|
+
end
|
491
|
+
|
492
|
+
describe '#delete' do
|
493
|
+
before(:each) do
|
494
|
+
stub_request(
|
495
|
+
:delete,
|
496
|
+
'https://www.example.com/k/v1/path'
|
497
|
+
)
|
498
|
+
.with(
|
499
|
+
body: { 'p1' => 'abc', 'p2' => 'def' }.to_json,
|
500
|
+
headers: { 'X-Cybozu-API-Token' => 'token-api' }
|
501
|
+
)
|
502
|
+
.to_return(
|
503
|
+
body: '{"abc":"def"}',
|
504
|
+
status: 200,
|
505
|
+
headers: { 'Content-type' => 'application/json' }
|
506
|
+
)
|
507
|
+
end
|
508
|
+
|
509
|
+
subject { target.delete(path, params) }
|
510
|
+
let(:path) { '/k/v1/path' }
|
511
|
+
let(:params) { { 'p1' => 'abc', 'p2' => 'def' } }
|
512
|
+
|
513
|
+
it { is_expected.to eq 'abc' => 'def' }
|
514
|
+
end
|
515
|
+
|
516
|
+
describe '#post_file' do
|
517
|
+
before(:each) do
|
518
|
+
stub_request(
|
519
|
+
:post,
|
520
|
+
'https://www.example.com/k/v1/path'
|
521
|
+
)
|
522
|
+
.with(headers: { 'X-Cybozu-API-Token' => 'token-api' })
|
523
|
+
.to_return(
|
524
|
+
body: '{"fileKey":"abc"}',
|
525
|
+
status: 200,
|
526
|
+
headers: { 'Content-type' => 'application/json' }
|
527
|
+
)
|
528
|
+
|
529
|
+
expect(Faraday::UploadIO).to receive(:new).with(path, content_type, original_filename).and_return(attachment) # rubocop:disable Metrics/LineLength
|
530
|
+
end
|
531
|
+
|
532
|
+
subject { target.post_file(url, path, content_type, original_filename) }
|
533
|
+
let(:attachment) { double('attachment') }
|
534
|
+
let(:url) { '/k/v1/path' }
|
535
|
+
let(:path) { '/path/to/file.txt' }
|
536
|
+
let(:content_type) { 'text/plain' }
|
537
|
+
let(:original_filename) { 'fileName.txt' }
|
538
|
+
|
539
|
+
it { is_expected.to eq 'abc' }
|
540
|
+
end
|
541
|
+
end
|
542
|
+
|
543
|
+
describe '#new' do
|
544
|
+
let(:domain) { 'www.example.com' }
|
545
|
+
let(:user) { 'Administrator' }
|
546
|
+
let(:password) { 'cybozu' }
|
547
|
+
|
548
|
+
context 'ブロック引数が与えられていない時' do
|
549
|
+
subject { api.instance_variable_get(:@connection).proxy }
|
550
|
+
let(:api) { Kintone::Api.new(domain, user, password) }
|
551
|
+
|
552
|
+
it { is_expected.to be_nil }
|
553
|
+
end
|
554
|
+
|
555
|
+
context 'ブロック引数が与えられている時' do
|
556
|
+
subject { api.instance_variable_get(:@connection).proxy }
|
557
|
+
let(:api) do
|
558
|
+
Kintone::Api.new(domain, user, password) do |connection|
|
559
|
+
connection.proxy = 'http://127.0.0.1'
|
560
|
+
end
|
561
|
+
end
|
562
|
+
|
563
|
+
it { is_expected.to be_a Faraday::ProxyOptions }
|
564
|
+
end
|
565
|
+
end
|
566
|
+
end
|