kintone-oauth-extension 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ee744c1f9e1ef957970753bbb6fde98153b504e05e912d32d82172c6f7b59f89
4
- data.tar.gz: a437f27dbd27d4aad95e5e6019f3f78ad959d414e6aea5bcbdf9a9ec495d3604
3
+ metadata.gz: c275f8943bcf9303a04c8f19ae83bb12bd1a19c20308cc4f1ed7fadf8c78a588
4
+ data.tar.gz: 5e49f32c0cf255490c325dad8b78ed0ac0580aba09c9a08cf56cf5d8e26c775b
5
5
  SHA512:
6
- metadata.gz: 603cc2cb7d028e0ad6452b0d57c8b4bd18ff539d190281d1060a5fa76b5782c56c2288fe6eab6376c0e7db9b4c91fe01a7f44e90302dd827c50630b95b90dd0e
7
- data.tar.gz: 9529b5198422902acf0f79f9ac5c480a918b0f675fe841fc2c2be49222e78ad4d1d1bd7a0d4bbdd46ce99a73d393e29dca9934316c67cb1562657db583e09288
6
+ metadata.gz: 9e097558ac73d48f947939fd733473c954e11314fbc7e36c262bc118ea06db53861451d2344e4008d340d87fe786d19471db3914d87323f47f26572c900e854a
7
+ data.tar.gz: e8ca4028be628802c3dec1102a86ba15ad559b724db74c5511bfc364fd3079be636296137f47b195a14c095da3bfd44538eb411c8f0429145ed7bdd7d5d86060
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.2.2 (2020-09-26)
4
+
5
+ support uploading a file in case of oauth authentication.
6
+
3
7
  ## 0.2.1 (2020-09-18)
4
8
 
5
9
  rename gem to `kintone-oauth-extension`.
@@ -1,3 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
1
4
  require 'bundler/setup'
2
5
  require 'kintone'
3
6
  require 'irb'
@@ -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
- opts = request_options(body: body)
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
- opts = request_options(body: body)
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
- opts = request_options(body: body)
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 refresh!
47
- @access_token = @access_token.refresh!
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.to_json if body
95
+ opts[:body] = body if body
85
96
  opts
86
97
  end
87
98
 
@@ -1,3 +1,3 @@
1
1
  module Kintone
2
- VERSION = '0.2.1'.freeze
2
+ VERSION = '0.2.2'.freeze
3
3
  end
@@ -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' }.to_json }
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.1
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-18 00:00:00.000000000 Z
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.1
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: