kintone 0.1.3 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e8c6531671baef8c02b16c44f8c97eb94fb8661b
4
- data.tar.gz: 842dfa2299afbb03b96e711794681763011a9ef3
3
+ metadata.gz: b117f1c781845b8712805c6ede66ed44d8b44382
4
+ data.tar.gz: 2f3151d4228579e118fec2564f55f93b1eef955b
5
5
  SHA512:
6
- metadata.gz: f58df87bf47682c15223ceb026674d8199b58d3bc2230402bc0680562d090cec2acf1a8500d2759948eb0fec1ef0ccc02008e6b3537967be01f893f7b6386114
7
- data.tar.gz: dd16a9a45c84bf9e468164dc980fccfcd7044901c9158055e055e601bcdf211153e1c8155f6063fdb636b497c75b69cb540818f3ffc665435b4f4ba0ad4ba642
6
+ metadata.gz: dd4fb7e33d330c4922c26b16449cd4ea5ef3998c2eda3376f127fafffcefb5193604f9cce5c381f0e86b239b859f1fe23979827c053edcf1f70cdeda8144f232
7
+ data.tar.gz: 34b39834c77beddbd95b4ebeff58483663210185a781f1c5e72a2a7213ddb9b67fe66e6a43dd047405f4eb2b23563c7f0a145e33bac209b63cf56ad4c54dd865
data/README.md CHANGED
@@ -20,7 +20,12 @@ or execute `bundle install` command after you insert the following into Gemfile
20
20
 
21
21
  ```ruby
22
22
  require 'kintone'
23
+
24
+ # Use password authentication
23
25
  api = Kintone::Api.new("example.cybozu.com", "Administrator", "cybozu")
26
+
27
+ # Use token authentication
28
+ api = Kintone::Api.new("example.cybozu.com", "authtoken")
24
29
  ```
25
30
 
26
31
  ### Supported API
@@ -30,12 +30,9 @@ class Kintone::Api
30
30
  :file
31
31
  ].freeze
32
32
 
33
- def initialize(domain, user, password)
34
- token = Base64.encode64("#{user}:#{password}")
35
- url = "https://#{domain}"
36
- headers = { 'X-Cybozu-Authorization' => token }
33
+ def initialize(domain, user, password = nil)
37
34
  @connection =
38
- Faraday.new(url: url, headers: headers) do |builder|
35
+ Faraday.new(url: "https://#{domain}", headers: build_headers(user, password)) do |builder|
39
36
  builder.request :url_encoded
40
37
  builder.request :multipart
41
38
  builder.response :json, content_type: /\bjson$/
@@ -113,4 +110,14 @@ class Kintone::Api
113
110
  class CommandAccessor
114
111
  extend Kintone::Command::Accessor
115
112
  end
113
+
114
+ private
115
+
116
+ def build_headers(user, password)
117
+ if password # パスワード認証
118
+ { 'X-Cybozu-Authorization' => Base64.encode64("#{user}:#{password}") }
119
+ else # APIトークン認証
120
+ { 'X-Cybozu-API-Token' => user }
121
+ end
122
+ end
116
123
  end
@@ -1,3 +1,3 @@
1
1
  module Kintone
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
@@ -7,287 +7,421 @@ require 'kintone/command/records'
7
7
  describe Kintone::Api do
8
8
  let(:target) { Kintone::Api.new(domain, user, password) }
9
9
  let(:domain) { 'www.example.com' }
10
- let(:user) { 'Administrator' }
11
- let(:password) { 'cybozu' }
12
10
 
13
- describe '#get_url' do
14
- subject { target.get_url(command) }
11
+ context 'ユーザー認証の時' do
12
+ let(:user) { 'Administrator' }
13
+ let(:password) { 'cybozu' }
15
14
 
16
- context '' do
17
- let(:command) { 'path' }
18
- it { is_expected.to eq('/k/v1/path.json') }
15
+ describe '#get_url' do
16
+ subject { target.get_url(command) }
17
+
18
+ context '' do
19
+ let(:command) { 'path' }
20
+ it { is_expected.to eq('/k/v1/path.json') }
21
+ end
19
22
  end
20
- end
21
23
 
22
- describe '#guest' do
23
- subject { target.guest(space) }
24
+ describe '#guest' do
25
+ subject { target.guest(space) }
24
26
 
25
- context '引数が数値の1の時' do
26
- let(:space) { 1 }
27
+ context '引数が数値の1の時' do
28
+ let(:space) { 1 }
27
29
 
28
- it { is_expected.to be_a_kind_of(Kintone::Api::Guest) }
29
- it { expect(subject.instance_variable_get(:@guest_path)).to eq('/k/guest/1/v1/') }
30
- end
30
+ it { is_expected.to be_a_kind_of(Kintone::Api::Guest) }
31
+ it { expect(subject.instance_variable_get(:@guest_path)).to eq('/k/guest/1/v1/') }
32
+ end
31
33
 
32
- context '引数がnilの時' do
33
- let(:space) { nil }
34
- xit { expect(subject.instance_variable_get(:@guest_path)).to eq('/k/guest//v1/') }
35
- end
34
+ context '引数がnilの時' do
35
+ let(:space) { nil }
36
+ xit { expect(subject.instance_variable_get(:@guest_path)).to eq('/k/guest//v1/') }
37
+ end
36
38
 
37
- context '引数に数字以外の文字が含まれる時' do
38
- let(:space) { '2.1' }
39
- xit { expect(subject.instance_variable_get(:@guest_path)).to eq('/k/guest//v1/') }
39
+ context '引数に数字以外の文字が含まれる時' do
40
+ let(:space) { '2.1' }
41
+ xit { expect(subject.instance_variable_get(:@guest_path)).to eq('/k/guest//v1/') }
42
+ end
40
43
  end
41
- end
42
44
 
43
- describe '#get' do
44
- before(:each) do
45
- stub_request(
46
- :get,
47
- 'https://www.example.com/k/v1/path'
48
- )
49
- .with(
50
- query: query,
51
- headers: { 'X-Cybozu-Authorization' => 'QWRtaW5pc3RyYXRvcjpjeWJvenU=' }
45
+ describe '#get' do
46
+ before(:each) do
47
+ stub_request(
48
+ :get,
49
+ 'https://www.example.com/k/v1/path'
52
50
  )
53
- .to_return(body: "{\"abc\":\"def\"}", status: 200,
54
- headers: { 'Content-type' => 'application/json' })
55
- end
51
+ .with(
52
+ query: query,
53
+ headers: { 'X-Cybozu-Authorization' => 'QWRtaW5pc3RyYXRvcjpjeWJvenU=' }
54
+ )
55
+ .to_return(body: "{\"abc\":\"def\"}", status: 200,
56
+ headers: { 'Content-type' => 'application/json' })
57
+ end
56
58
 
57
- subject { target.get(path, params) }
59
+ subject { target.get(path, params) }
58
60
 
59
- let(:path) { '/k/v1/path' }
61
+ let(:path) { '/k/v1/path' }
60
62
 
61
- context 'with some params' do
62
- let(:params) { { 'p1' => 'abc', 'p2' => 'def' } }
63
- let(:query) { 'p1=abc&p2=def' }
63
+ context 'with some params' do
64
+ let(:params) { { 'p1' => 'abc', 'p2' => 'def' } }
65
+ let(:query) { 'p1=abc&p2=def' }
64
66
 
65
- it { is_expected.to eq 'abc' => 'def' }
67
+ it { is_expected.to eq 'abc' => 'def' }
68
+ end
69
+
70
+ context 'with empty params' do
71
+ let(:params) { {} }
72
+ let(:query) { nil }
73
+
74
+ it { is_expected.to eq 'abc' => 'def' }
75
+ end
76
+
77
+ context 'with nil' do
78
+ let(:params) { nil }
79
+ let(:query) { nil }
80
+
81
+ it { expect { subject }.to raise_error NoMethodError }
82
+ end
83
+
84
+ context 'with no params' do
85
+ subject { target.get(path) }
86
+
87
+ let(:query) { nil }
88
+
89
+ it { is_expected.to eq 'abc' => 'def' }
90
+ end
66
91
  end
67
92
 
68
- context 'with empty params' do
69
- let(:params) { {} }
70
- let(:query) { nil }
93
+ describe '#post' do
94
+ before(:each) do
95
+ stub_request(
96
+ :post,
97
+ 'https://www.example.com/k/v1/path'
98
+ )
99
+ .with(
100
+ headers: {
101
+ 'X-Cybozu-Authorization' => 'QWRtaW5pc3RyYXRvcjpjeWJvenU=',
102
+ 'Content-Type' => 'application/json'
103
+ },
104
+ body: "{\"p1\":\"abc\",\"p2\":\"def\"}"
105
+ )
106
+ .to_return(body: "{\"abc\":\"def\"}", status: 200,
107
+ headers: { 'Content-type' => 'application/json' })
108
+ end
109
+
110
+ subject { target.post(path, body) }
111
+ let(:path) { '/k/v1/path' }
112
+ let(:body) { { 'p1' => 'abc', 'p2' => 'def' } }
71
113
 
72
114
  it { is_expected.to eq 'abc' => 'def' }
73
115
  end
74
116
 
75
- context 'with nil' do
76
- let(:params) { nil }
77
- let(:query) { nil }
117
+ describe '#put' do
118
+ before(:each) do
119
+ stub_request(
120
+ :put,
121
+ 'https://www.example.com/k/v1/path'
122
+ )
123
+ .with(
124
+ headers: {
125
+ 'X-Cybozu-Authorization' => 'QWRtaW5pc3RyYXRvcjpjeWJvenU=',
126
+ 'Content-Type' => 'application/json'
127
+ },
128
+ body: "{\"p1\":\"abc\",\"p2\":\"def\"}"
129
+ )
130
+ .to_return(body: "{\"abc\":\"def\"}", status: 200,
131
+ headers: { 'Content-type' => 'application/json' })
132
+ end
78
133
 
79
- it { expect { subject }.to raise_error NoMethodError }
134
+ subject { target.put(path, body) }
135
+ let(:path) { '/k/v1/path' }
136
+ let(:body) { { 'p1' => 'abc', 'p2' => 'def' } }
137
+
138
+ it { is_expected.to eq 'abc' => 'def' }
80
139
  end
81
140
 
82
- context 'with no params' do
83
- subject { target.get(path) }
141
+ describe '#delete' do
142
+ before(:each) do
143
+ stub_request(
144
+ :delete,
145
+ 'https://www.example.com/k/v1/path'
146
+ )
147
+ .with(
148
+ body: { 'p1' => 'abc', 'p2' => 'def' }.to_json,
149
+ headers: { 'X-Cybozu-Authorization' => 'QWRtaW5pc3RyYXRvcjpjeWJvenU=' }
150
+ )
151
+ .to_return(body: "{\"abc\":\"def\"}", status: 200,
152
+ headers: { 'Content-type' => 'application/json' })
153
+ end
84
154
 
85
- let(:query) { nil }
155
+ subject { target.delete(path, params) }
156
+ let(:path) { '/k/v1/path' }
157
+ let(:params) { { 'p1' => 'abc', 'p2' => 'def' } }
86
158
 
87
159
  it { is_expected.to eq 'abc' => 'def' }
88
160
  end
89
- end
90
161
 
91
- describe '#post' do
92
- before(:each) do
93
- stub_request(
94
- :post,
95
- 'https://www.example.com/k/v1/path'
96
- )
97
- .with(
98
- headers: {
99
- 'X-Cybozu-Authorization' => 'QWRtaW5pc3RyYXRvcjpjeWJvenU=',
100
- 'Content-Type' => 'application/json'
101
- },
102
- body: "{\"p1\":\"abc\",\"p2\":\"def\"}"
162
+ describe '#post_file' do
163
+ before(:each) do
164
+ stub_request(
165
+ :post,
166
+ 'https://www.example.com/k/v1/path'
103
167
  )
104
- .to_return(body: "{\"abc\":\"def\"}", status: 200,
105
- headers: { 'Content-type' => 'application/json' })
168
+ .with(headers: { 'X-Cybozu-Authorization' => 'QWRtaW5pc3RyYXRvcjpjeWJvenU=' }) do
169
+ attachment
170
+ end
171
+ .to_return(body: "{\"fileKey\":\"abc\"}", status: 200,
172
+ headers: { 'Content-type' => 'application/json' })
173
+
174
+ expect(Faraday::UploadIO).to receive(:new)
175
+ .with(path, content_type, original_filename,
176
+ 'Content-Disposition' => 'form-data')
177
+ .and_return(attachment)
178
+ end
179
+
180
+ subject { target.post_file(url, path, content_type, original_filename) }
181
+ let(:attachment) { double('attachment') }
182
+ let(:url) { '/k/v1/path' }
183
+ let(:path) { '/path/to/file.txt' }
184
+ let(:content_type) { 'text/plain' }
185
+ let(:original_filename) { 'fileName.txt' }
186
+
187
+ it { is_expected.to eq 'abc' }
106
188
  end
107
189
 
108
- subject { target.post(path, body) }
109
- let(:path) { '/k/v1/path' }
110
- let(:body) { { 'p1' => 'abc', 'p2' => 'def' } }
190
+ describe '#record' do
191
+ subject { target.record }
111
192
 
112
- it { is_expected.to eq 'abc' => 'def' }
113
- end
193
+ it { is_expected.to be_a_kind_of(Kintone::Command::Record) }
194
+ end
114
195
 
115
- describe '#put' do
116
- before(:each) do
117
- stub_request(
118
- :put,
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(body: "{\"abc\":\"def\"}", status: 200,
129
- headers: { 'Content-type' => 'application/json' })
196
+ describe '#records' do
197
+ subject { target.records }
198
+
199
+ it { is_expected.to be_a_kind_of(Kintone::Command::Records) }
130
200
  end
131
201
 
132
- subject { target.put(path, body) }
133
- let(:path) { '/k/v1/path' }
134
- let(:body) { { 'p1' => 'abc', 'p2' => 'def' } }
202
+ describe '#form' do
203
+ subject { target.form }
135
204
 
136
- it { is_expected.to eq 'abc' => 'def' }
137
- end
205
+ it { is_expected.to be_a_kind_of(Kintone::Command::Form) }
206
+ end
138
207
 
139
- describe '#delete' do
140
- before(:each) do
141
- stub_request(
142
- :delete,
143
- 'https://www.example.com/k/v1/path'
144
- )
145
- .with(
146
- body: { 'p1' => 'abc', 'p2' => 'def' }.to_json,
147
- headers: { 'X-Cybozu-Authorization' => 'QWRtaW5pc3RyYXRvcjpjeWJvenU=' }
148
- )
149
- .to_return(body: "{\"abc\":\"def\"}", status: 200,
150
- headers: { 'Content-type' => 'application/json' })
208
+ describe '#app_acl' do
209
+ subject { target.app_acl }
210
+
211
+ it { is_expected.to be_a_kind_of(Kintone::Command::AppAcl) }
151
212
  end
152
213
 
153
- subject { target.delete(path, params) }
154
- let(:path) { '/k/v1/path' }
155
- let(:params) { { 'p1' => 'abc', 'p2' => 'def' } }
214
+ describe '#record_acl' do
215
+ subject { target.record_acl }
156
216
 
157
- it { is_expected.to eq 'abc' => 'def' }
158
- end
217
+ it { is_expected.to be_a_kind_of(Kintone::Command::RecordAcl) }
218
+ end
159
219
 
160
- describe '#post_file' do
161
- before(:each) do
162
- stub_request(
163
- :post,
164
- 'https://www.example.com/k/v1/path'
165
- )
166
- .with { attachment }
167
- .to_return(body: "{\"fileKey\":\"abc\"}", status: 200,
168
- headers: { 'Content-type' => 'application/json' })
220
+ describe '#field_acl' do
221
+ subject { target.field_acl }
169
222
 
170
- expect(Faraday::UploadIO).to receive(:new)
171
- .with(path, content_type, original_filename,
172
- 'Content-Disposition' => 'form-data')
173
- .and_return(attachment)
223
+ it { is_expected.to be_a_kind_of(Kintone::Command::FieldAcl) }
174
224
  end
175
225
 
176
- subject { target.post_file(url, path, content_type, original_filename) }
177
- let(:attachment) { double('attachment') }
178
- let(:url) { '/k/v1/path' }
179
- let(:path) { '/path/to/file.txt' }
180
- let(:content_type) { 'text/plain' }
181
- let(:original_filename) { 'fileName.txt' }
226
+ describe '#template_space' do
227
+ subject { target.template_space }
182
228
 
183
- it { is_expected.to eq 'abc' }
184
- end
229
+ it { is_expected.to be_a_kind_of(Kintone::Command::TemplateSpace) }
230
+ end
185
231
 
186
- describe '#record' do
187
- subject { target.record }
232
+ describe '#space' do
233
+ subject { target.space }
188
234
 
189
- it { is_expected.to be_a_kind_of(Kintone::Command::Record) }
190
- end
235
+ it { is_expected.to be_a_kind_of(Kintone::Command::Space) }
236
+ end
191
237
 
192
- describe '#records' do
193
- subject { target.records }
238
+ describe '#space_body' do
239
+ subject { target.space_body }
194
240
 
195
- it { is_expected.to be_a_kind_of(Kintone::Command::Records) }
196
- end
241
+ it { is_expected.to be_a_kind_of(Kintone::Command::SpaceBody) }
242
+ end
197
243
 
198
- describe '#form' do
199
- subject { target.form }
244
+ describe '#space_thread' do
245
+ subject { target.space_thread }
200
246
 
201
- it { is_expected.to be_a_kind_of(Kintone::Command::Form) }
202
- end
247
+ it { is_expected.to be_a_kind_of(Kintone::Command::SpaceThread) }
248
+ end
203
249
 
204
- describe '#app_acl' do
205
- subject { target.app_acl }
250
+ describe '#space_members' do
251
+ subject { target.space_members }
206
252
 
207
- it { is_expected.to be_a_kind_of(Kintone::Command::AppAcl) }
208
- end
253
+ it { is_expected.to be_a_kind_of(Kintone::Command::SpaceMembers) }
254
+ end
209
255
 
210
- describe '#record_acl' do
211
- subject { target.record_acl }
256
+ describe '#guests' do
257
+ subject { target.guests }
212
258
 
213
- it { is_expected.to be_a_kind_of(Kintone::Command::RecordAcl) }
214
- end
259
+ it { is_expected.to be_a_kind_of(Kintone::Command::Guests) }
260
+ end
215
261
 
216
- describe '#field_acl' do
217
- subject { target.field_acl }
262
+ describe '#app' do
263
+ subject { target.app }
218
264
 
219
- it { is_expected.to be_a_kind_of(Kintone::Command::FieldAcl) }
220
- end
265
+ it { is_expected.to be_a_kind_of(Kintone::Command::App) }
266
+ end
221
267
 
222
- describe '#template_space' do
223
- subject { target.template_space }
268
+ describe '#apps' do
269
+ subject { target.apps }
224
270
 
225
- it { is_expected.to be_a_kind_of(Kintone::Command::TemplateSpace) }
226
- end
271
+ it { is_expected.to be_a_kind_of(Kintone::Command::Apps) }
272
+ end
227
273
 
228
- describe '#space' do
229
- subject { target.space }
274
+ describe '#apis' do
275
+ subject { target.apis }
230
276
 
231
- it { is_expected.to be_a_kind_of(Kintone::Command::Space) }
232
- end
277
+ it { is_expected.to be_a_kind_of(Kintone::Command::Apis) }
278
+ end
233
279
 
234
- describe '#space_body' do
235
- subject { target.space_body }
280
+ describe '#bulk_request' do
281
+ subject { target.bulk_request }
236
282
 
237
- it { is_expected.to be_a_kind_of(Kintone::Command::SpaceBody) }
238
- end
283
+ it { is_expected.to be_a_kind_of(Kintone::Command::BulkRequest) }
284
+ end
239
285
 
240
- describe '#space_thread' do
241
- subject { target.space_thread }
286
+ describe '#bulk' do
287
+ subject { target.bulk }
242
288
 
243
- it { is_expected.to be_a_kind_of(Kintone::Command::SpaceThread) }
244
- end
289
+ it { is_expected.to be_a_kind_of(Kintone::Command::BulkRequest) }
290
+ end
245
291
 
246
- describe '#space_members' do
247
- subject { target.space_members }
292
+ describe '#file' do
293
+ subject { target.file }
248
294
 
249
- it { is_expected.to be_a_kind_of(Kintone::Command::SpaceMembers) }
295
+ it { is_expected.to be_a_kind_of(Kintone::Command::File) }
296
+ end
250
297
  end
251
298
 
252
- describe '#guests' do
253
- subject { target.guests }
299
+ context 'APIトークン認証の時' do
300
+ let(:user) { 'token-api' }
301
+ let(:password) { nil }
254
302
 
255
- it { is_expected.to be_a_kind_of(Kintone::Command::Guests) }
256
- end
303
+ describe '#get' do
304
+ before(:each) do
305
+ stub_request(
306
+ :get,
307
+ 'https://www.example.com/k/v1/path'
308
+ )
309
+ .with(
310
+ query: query,
311
+ headers: { 'X-Cybozu-API-Token' => 'token-api' }
312
+ )
313
+ .to_return(body: "{\"abc\":\"def\"}", status: 200,
314
+ headers: { 'Content-type' => 'application/json' })
315
+ end
257
316
 
258
- describe '#app' do
259
- subject { target.app }
317
+ subject { target.get(path, params) }
260
318
 
261
- it { is_expected.to be_a_kind_of(Kintone::Command::App) }
262
- end
319
+ let(:path) { '/k/v1/path' }
263
320
 
264
- describe '#apps' do
265
- subject { target.apps }
321
+ context 'with no params' do
322
+ subject { target.get(path) }
266
323
 
267
- it { is_expected.to be_a_kind_of(Kintone::Command::Apps) }
268
- end
324
+ let(:query) { nil }
269
325
 
270
- describe '#apis' do
271
- subject { target.apis }
326
+ it { is_expected.to eq 'abc' => 'def' }
327
+ end
328
+ end
272
329
 
273
- it { is_expected.to be_a_kind_of(Kintone::Command::Apis) }
274
- end
330
+ describe '#post' do
331
+ before(:each) do
332
+ stub_request(
333
+ :post,
334
+ 'https://www.example.com/k/v1/path'
335
+ )
336
+ .with(
337
+ headers: {
338
+ 'X-Cybozu-API-Token' => 'token-api',
339
+ 'Content-Type' => 'application/json'
340
+ },
341
+ body: "{\"p1\":\"abc\",\"p2\":\"def\"}"
342
+ )
343
+ .to_return(body: "{\"abc\":\"def\"}", status: 200,
344
+ headers: { 'Content-type' => 'application/json' })
345
+ end
346
+
347
+ subject { target.post(path, body) }
348
+ let(:path) { '/k/v1/path' }
349
+ let(:body) { { 'p1' => 'abc', 'p2' => 'def' } }
275
350
 
276
- describe '#bulk_request' do
277
- subject { target.bulk_request }
351
+ it { is_expected.to eq 'abc' => 'def' }
352
+ end
278
353
 
279
- it { is_expected.to be_a_kind_of(Kintone::Command::BulkRequest) }
280
- end
354
+ describe '#put' do
355
+ before(:each) do
356
+ stub_request(
357
+ :put,
358
+ 'https://www.example.com/k/v1/path'
359
+ )
360
+ .with(
361
+ headers: {
362
+ 'X-Cybozu-API-Token' => 'token-api',
363
+ 'Content-Type' => 'application/json'
364
+ },
365
+ body: "{\"p1\":\"abc\",\"p2\":\"def\"}"
366
+ )
367
+ .to_return(body: "{\"abc\":\"def\"}", status: 200,
368
+ headers: { 'Content-type' => 'application/json' })
369
+ end
370
+
371
+ subject { target.put(path, body) }
372
+ let(:path) { '/k/v1/path' }
373
+ let(:body) { { 'p1' => 'abc', 'p2' => 'def' } }
281
374
 
282
- describe '#bulk' do
283
- subject { target.bulk }
375
+ it { is_expected.to eq 'abc' => 'def' }
376
+ end
284
377
 
285
- it { is_expected.to be_a_kind_of(Kintone::Command::BulkRequest) }
286
- end
378
+ describe '#delete' do
379
+ before(:each) do
380
+ stub_request(
381
+ :delete,
382
+ 'https://www.example.com/k/v1/path'
383
+ )
384
+ .with(
385
+ body: { 'p1' => 'abc', 'p2' => 'def' }.to_json,
386
+ headers: { 'X-Cybozu-API-Token' => 'token-api' }
387
+ )
388
+ .to_return(body: "{\"abc\":\"def\"}", status: 200,
389
+ headers: { 'Content-type' => 'application/json' })
390
+ end
391
+
392
+ subject { target.delete(path, params) }
393
+ let(:path) { '/k/v1/path' }
394
+ let(:params) { { 'p1' => 'abc', 'p2' => 'def' } }
287
395
 
288
- describe '#file' do
289
- subject { target.file }
396
+ it { is_expected.to eq 'abc' => 'def' }
397
+ end
290
398
 
291
- it { is_expected.to be_a_kind_of(Kintone::Command::File) }
399
+ describe '#post_file' do
400
+ before(:each) do
401
+ stub_request(
402
+ :post,
403
+ 'https://www.example.com/k/v1/path'
404
+ )
405
+ .with(
406
+ headers: { 'X-Cybozu-API-Token' => 'token-api' }
407
+ )
408
+ .to_return(body: "{\"fileKey\":\"abc\"}", status: 200,
409
+ headers: { 'Content-type' => 'application/json' })
410
+
411
+ expect(Faraday::UploadIO).to receive(:new)
412
+ .with(path, content_type, original_filename,
413
+ 'Content-Disposition' => 'form-data')
414
+ .and_return(attachment)
415
+ end
416
+
417
+ subject { target.post_file(url, path, content_type, original_filename) }
418
+ let(:attachment) { double('attachment') }
419
+ let(:url) { '/k/v1/path' }
420
+ let(:path) { '/path/to/file.txt' }
421
+ let(:content_type) { 'text/plain' }
422
+ let(:original_filename) { 'fileName.txt' }
423
+
424
+ it { is_expected.to eq 'abc' }
425
+ end
292
426
  end
293
427
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kintone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rikiya Kawakami
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-29 00:00:00.000000000 Z
11
+ date: 2016-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -241,7 +241,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
241
241
  version: '0'
242
242
  requirements: []
243
243
  rubyforge_project:
244
- rubygems_version: 2.4.5
244
+ rubygems_version: 2.2.2
245
245
  signing_key:
246
246
  specification_version: 4
247
247
  summary: kintone API client for Ruby.