kintone-oauth-extension 0.2.1 → 0.2.2
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/bin/console +3 -0
- data/lib/kintone/oauth_api.rb +17 -6
- data/lib/kintone/version.rb +1 -1
- data/spec/kintone/oauth_api_spec.rb +28 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c275f8943bcf9303a04c8f19ae83bb12bd1a19c20308cc4f1ed7fadf8c78a588
|
4
|
+
data.tar.gz: 5e49f32c0cf255490c325dad8b78ed0ac0580aba09c9a08cf56cf5d8e26c775b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e097558ac73d48f947939fd733473c954e11314fbc7e36c262bc118ea06db53861451d2344e4008d340d87fe786d19471db3914d87323f47f26572c900e854a
|
7
|
+
data.tar.gz: e8ca4028be628802c3dec1102a86ba15ad559b724db74c5511bfc364fd3079be636296137f47b195a14c095da3bfd44538eb411c8f0429145ed7bdd7d5d86060
|
data/CHANGELOG.md
CHANGED
data/bin/console
CHANGED
data/lib/kintone/oauth_api.rb
CHANGED
@@ -23,28 +23,39 @@ class Kintone::OAuthApi < Kintone::Api
|
|
23
23
|
@access_token = ::OAuth2::AccessToken.new(client, token, refresh_token: opts[:refresh_token], expires_at: opts[:expires_at])
|
24
24
|
end
|
25
25
|
|
26
|
+
def refresh!
|
27
|
+
@access_token = @access_token.refresh!
|
28
|
+
end
|
29
|
+
|
26
30
|
def get(url, params = {})
|
27
31
|
opts = request_options(params: params, headers: nil)
|
28
32
|
request(:get, url, opts)
|
29
33
|
end
|
30
34
|
|
31
35
|
def post(url, body)
|
32
|
-
|
36
|
+
json_body = body.to_json if body.respond_to?(:to_json)
|
37
|
+
opts = request_options(body: json_body)
|
33
38
|
request(:post, url, opts)
|
34
39
|
end
|
35
40
|
|
36
41
|
def put(url, body)
|
37
|
-
|
42
|
+
json_body = body.to_json if body.respond_to?(:to_json)
|
43
|
+
opts = request_options(body: json_body)
|
38
44
|
request(:put, url, opts)
|
39
45
|
end
|
40
46
|
|
41
47
|
def delete(url, body = nil)
|
42
|
-
|
48
|
+
json_body = body.to_json if body.respond_to?(:to_json)
|
49
|
+
opts = request_options(body: json_body)
|
43
50
|
request(:delete, url, opts)
|
44
51
|
end
|
45
52
|
|
46
|
-
def
|
47
|
-
|
53
|
+
def post_file(url, path, content_type, original_filename)
|
54
|
+
body = { file: Faraday::UploadIO.new(path, content_type, original_filename) }
|
55
|
+
headers = { 'Content-Type' => 'multipart/form-data' }
|
56
|
+
opts = request_options(body: body, headers: headers)
|
57
|
+
res = request(:post, url, opts)
|
58
|
+
res['fileKey']
|
48
59
|
end
|
49
60
|
|
50
61
|
private
|
@@ -81,7 +92,7 @@ class Kintone::OAuthApi < Kintone::Api
|
|
81
92
|
opts = {}
|
82
93
|
opts[:headers] = headers
|
83
94
|
opts[:params] = params if params
|
84
|
-
opts[:body] = body
|
95
|
+
opts[:body] = body if body
|
85
96
|
opts
|
86
97
|
end
|
87
98
|
|
data/lib/kintone/version.rb
CHANGED
@@ -57,9 +57,17 @@ describe Kintone::OAuthApi do
|
|
57
57
|
it { is_expected.to eq 'abc' => 'def' }
|
58
58
|
end
|
59
59
|
|
60
|
+
context 'fail to request when unexpected response status returns' do
|
61
|
+
let(:response_status) { 201 }
|
62
|
+
before(:each) do
|
63
|
+
add_stub_request
|
64
|
+
end
|
65
|
+
it { expect { subject }.to raise_error Kintone::KintoneError }
|
66
|
+
end
|
67
|
+
|
60
68
|
context 'fail to request' do
|
61
69
|
let(:response_status) { 500 }
|
62
|
-
let(:response_body) { { message: '不正なJSON文字列です。', id: '1505999166-897850006', code: 'CB_IJ01' }
|
70
|
+
let(:response_body) { { message: '不正なJSON文字列です。', id: '1505999166-897850006', code: 'CB_IJ01' } }
|
63
71
|
before(:each) do
|
64
72
|
add_stub_request
|
65
73
|
end
|
@@ -112,6 +120,25 @@ describe Kintone::OAuthApi do
|
|
112
120
|
it { is_expected.to eq 'abc' => 'def' }
|
113
121
|
end
|
114
122
|
|
123
|
+
describe '#post_file' do
|
124
|
+
before(:each) do
|
125
|
+
add_stub_request
|
126
|
+
expect(Faraday::UploadIO).to receive(:new).with(file_path, content_type, original_filename).and_return(attachment)
|
127
|
+
end
|
128
|
+
|
129
|
+
subject { target.post_file(path, file_path, content_type, original_filename) }
|
130
|
+
let(:file_path) { '/path/to/file.txt' }
|
131
|
+
let(:content_type) { 'text/plain' }
|
132
|
+
let(:original_filename) { 'fileName.txt' }
|
133
|
+
let(:attachment) { double('attachment') }
|
134
|
+
let(:request_verb) { :post }
|
135
|
+
let(:response_status) { 200 }
|
136
|
+
let(:response_body) { { fileKey: 'abc' } }
|
137
|
+
let(:option_headers) { { 'Content-Type' => %r{multipart/form-data} } }
|
138
|
+
|
139
|
+
it { is_expected.to eq 'abc' }
|
140
|
+
end
|
141
|
+
|
115
142
|
describe '#refresh!' do
|
116
143
|
subject { target.refresh! }
|
117
144
|
it { expect { subject }.to raise_error RuntimeError }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kintone-oauth-extension
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kenji Koshikawa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-09-
|
11
|
+
date: 2020-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -253,7 +253,7 @@ metadata:
|
|
253
253
|
homepage_uri: https://github.com/koshilife/kintone
|
254
254
|
source_code_uri: https://github.com/koshilife/kintone
|
255
255
|
changelog_uri: https://github.com/koshilife/kintone/blob/master/CHANGELOG.md
|
256
|
-
documentation_uri: https://www.rubydoc.info/gems/kintone-oauth-extension/0.2.
|
256
|
+
documentation_uri: https://www.rubydoc.info/gems/kintone-oauth-extension/0.2.2
|
257
257
|
post_install_message:
|
258
258
|
rdoc_options: []
|
259
259
|
require_paths:
|