kintone-oauth-extension 0.2.1
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/.github/workflows/gem-push.yml +37 -0
- data/.github/workflows/test.yml +21 -0
- data/.gitignore +21 -0
- data/.rspec +1 -0
- data/.rubocop.yml +47 -0
- data/CHANGELOG.md +13 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +374 -0
- data/bin/console +4 -0
- data/bin/setup +6 -0
- data/kintone.gemspec +38 -0
- data/lib/kintone.rb +8 -0
- data/lib/kintone/api.rb +121 -0
- data/lib/kintone/api/guest.rb +44 -0
- data/lib/kintone/command.rb +12 -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/kintone_error.rb +12 -0
- data/lib/kintone/oauth_api.rb +91 -0
- data/lib/kintone/query.rb +152 -0
- data/lib/kintone/query/extension.rb +23 -0
- data/lib/kintone/type.rb +6 -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/version.rb +3 -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/oauth_api_spec.rb +164 -0
- data/spec/kintone/query_spec.rb +506 -0
- data/spec/kintone/type/record_spec.rb +38 -0
- data/spec/spec_helper.rb +10 -0
- metadata +302 -0
data/bin/console
ADDED
data/bin/setup
ADDED
data/kintone.gemspec
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'kintone/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'kintone-oauth-extension'
|
7
|
+
spec.version = Kintone::VERSION
|
8
|
+
spec.authors = ['Kenji Koshikawa']
|
9
|
+
spec.email = ['koshikawa2009@gmail.com']
|
10
|
+
spec.summary = 'kintone API client for Ruby.'
|
11
|
+
spec.description = spec.summary
|
12
|
+
spec.homepage = 'https://github.com/koshilife/kintone'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.4.0')
|
15
|
+
|
16
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
17
|
+
spec.metadata['source_code_uri'] = 'https://github.com/koshilife/kintone'
|
18
|
+
spec.metadata['changelog_uri'] = "#{spec.metadata['source_code_uri']}/blob/master/CHANGELOG.md"
|
19
|
+
spec.metadata['documentation_uri'] = "https://www.rubydoc.info/gems/kintone-oauth-extension/#{spec.version}"
|
20
|
+
|
21
|
+
spec.files = `git ls-files -z`.split("\x0")
|
22
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
23
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
24
|
+
spec.require_paths = ['lib']
|
25
|
+
|
26
|
+
spec.add_runtime_dependency 'faraday', '>=1.0.1'
|
27
|
+
spec.add_runtime_dependency 'faraday_middleware', '>=1.0.0'
|
28
|
+
spec.add_runtime_dependency 'oauth2', '>=1.4.4'
|
29
|
+
|
30
|
+
spec.add_development_dependency 'bundler'
|
31
|
+
spec.add_development_dependency 'codecov'
|
32
|
+
spec.add_development_dependency 'rake'
|
33
|
+
spec.add_development_dependency 'rspec'
|
34
|
+
spec.add_development_dependency 'rspec-parameterized'
|
35
|
+
spec.add_development_dependency 'rubocop'
|
36
|
+
spec.add_development_dependency 'simplecov'
|
37
|
+
spec.add_development_dependency 'webmock'
|
38
|
+
end
|
data/lib/kintone.rb
ADDED
data/lib/kintone/api.rb
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
require 'base64'
|
4
|
+
require 'json'
|
5
|
+
require 'kintone/command/accessor'
|
6
|
+
require 'kintone/api/guest'
|
7
|
+
require 'kintone/query'
|
8
|
+
require 'kintone/kintone_error'
|
9
|
+
|
10
|
+
class Kintone::Api
|
11
|
+
BASE_PATH = '/k/v1/'.freeze
|
12
|
+
COMMAND = '%s.json'.freeze
|
13
|
+
ACCESSIBLE_COMMAND = [
|
14
|
+
:record, :records, :form, :app_acl, :record_acl,
|
15
|
+
:field_acl, :template_space, :space, :space_body, :space_thread,
|
16
|
+
:space_members, :guests, :app, :apps, :apis,
|
17
|
+
:bulk_request, :bulk, :file, :preview_form
|
18
|
+
].freeze
|
19
|
+
|
20
|
+
def initialize(domain, user, password = nil)
|
21
|
+
@connection =
|
22
|
+
Faraday.new(url: "https://#{domain}", headers: build_headers(user, password)) do |builder|
|
23
|
+
builder.request :url_encoded
|
24
|
+
builder.request :multipart
|
25
|
+
builder.response :json, content_type: /\bjson$/
|
26
|
+
builder.adapter :net_http
|
27
|
+
end
|
28
|
+
|
29
|
+
yield(@connection) if block_given?
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_url(command)
|
33
|
+
BASE_PATH + (COMMAND % command)
|
34
|
+
end
|
35
|
+
|
36
|
+
def guest(space_id)
|
37
|
+
Kintone::Api::Guest.new(space_id, self)
|
38
|
+
end
|
39
|
+
|
40
|
+
def get(url, params = {})
|
41
|
+
response =
|
42
|
+
@connection.get do |request|
|
43
|
+
request.url url
|
44
|
+
# NOTE: Request URI Too Large 対策
|
45
|
+
request.headers['Content-Type'] = 'application/json'
|
46
|
+
request.body = params.to_h.to_json
|
47
|
+
end
|
48
|
+
raise Kintone::KintoneError.new(response.body, response.status) if response.status != 200
|
49
|
+
response.body
|
50
|
+
end
|
51
|
+
|
52
|
+
def post(url, body)
|
53
|
+
response =
|
54
|
+
@connection.post do |request|
|
55
|
+
request.url url
|
56
|
+
request.headers['Content-Type'] = 'application/json'
|
57
|
+
request.body = body.to_json
|
58
|
+
end
|
59
|
+
raise Kintone::KintoneError.new(response.body, response.status) if response.status != 200
|
60
|
+
response.body
|
61
|
+
end
|
62
|
+
|
63
|
+
def put(url, body)
|
64
|
+
response =
|
65
|
+
@connection.put do |request|
|
66
|
+
request.url url
|
67
|
+
request.headers['Content-Type'] = 'application/json'
|
68
|
+
request.body = body.to_json
|
69
|
+
end
|
70
|
+
raise Kintone::KintoneError.new(response.body, response.status) if response.status != 200
|
71
|
+
response.body
|
72
|
+
end
|
73
|
+
|
74
|
+
def delete(url, body = nil)
|
75
|
+
response =
|
76
|
+
@connection.delete do |request|
|
77
|
+
request.url url
|
78
|
+
request.headers['Content-Type'] = 'application/json'
|
79
|
+
request.body = body.to_json
|
80
|
+
end
|
81
|
+
raise Kintone::KintoneError.new(response.body, response.status) if response.status != 200
|
82
|
+
response.body
|
83
|
+
end
|
84
|
+
|
85
|
+
def post_file(url, path, content_type, original_filename)
|
86
|
+
response =
|
87
|
+
@connection.post do |request|
|
88
|
+
request.url url
|
89
|
+
request.headers['Content-Type'] = 'multipart/form-data'
|
90
|
+
request.body = { file: Faraday::UploadIO.new(path, content_type, original_filename) }
|
91
|
+
end
|
92
|
+
raise Kintone::KintoneError.new(response.body, response.status) if response.status != 200
|
93
|
+
response.body['fileKey']
|
94
|
+
end
|
95
|
+
|
96
|
+
def method_missing(name, *args)
|
97
|
+
if ACCESSIBLE_COMMAND.include?(name)
|
98
|
+
CommandAccessor.send(name, self)
|
99
|
+
else
|
100
|
+
super
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def respond_to_missing?(name, *args)
|
105
|
+
ACCESSIBLE_COMMAND.include?(name) || super
|
106
|
+
end
|
107
|
+
|
108
|
+
class CommandAccessor
|
109
|
+
extend Kintone::Command::Accessor
|
110
|
+
end
|
111
|
+
|
112
|
+
private
|
113
|
+
|
114
|
+
def build_headers(user, password)
|
115
|
+
if password # パスワード認証
|
116
|
+
{ 'X-Cybozu-Authorization' => Base64.strict_encode64("#{user}:#{password}") }
|
117
|
+
else # APIトークン認証
|
118
|
+
{ 'X-Cybozu-API-Token' => user }
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
require 'kintone/api'
|
3
|
+
require 'kintone/command/accessor'
|
4
|
+
|
5
|
+
class Kintone::Api
|
6
|
+
class Guest
|
7
|
+
extend Forwardable
|
8
|
+
|
9
|
+
GUEST_PATH = '/k/guest/%s/v1/'.freeze
|
10
|
+
ACCESSIBLE_COMMAND = [
|
11
|
+
:record, :records, :form, :app_acl, :record_acl,
|
12
|
+
:field_acl, :space, :space_body, :space_thread, :space_members,
|
13
|
+
:space_guests, :app, :apps, :bulk_request, :bulk,
|
14
|
+
:file, :preview_form
|
15
|
+
].freeze
|
16
|
+
|
17
|
+
def_delegators :@api, :get, :post, :put, :delete, :post_file
|
18
|
+
|
19
|
+
def initialize(space_id, api)
|
20
|
+
@api = api
|
21
|
+
@guest_path = GUEST_PATH % space_id.to_i
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_url(command)
|
25
|
+
@guest_path + (COMMAND % command)
|
26
|
+
end
|
27
|
+
|
28
|
+
def method_missing(name, *args)
|
29
|
+
if ACCESSIBLE_COMMAND.include?(name)
|
30
|
+
CommandAccessor.send(name, self)
|
31
|
+
else
|
32
|
+
super
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def respond_to_missing?(name, *args)
|
37
|
+
ACCESSIBLE_COMMAND.include?(name) || super
|
38
|
+
end
|
39
|
+
|
40
|
+
class CommandAccessor
|
41
|
+
extend Kintone::Command::Accessor
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
class Kintone::Command
|
2
|
+
# common
|
3
|
+
autoload :Record, 'kintone/command/record'
|
4
|
+
autoload :Records, 'kintone/command/records'
|
5
|
+
autoload :BulkRequest, 'kintone/command/bulk_request'
|
6
|
+
autoload :Form, 'kintone/command/form'
|
7
|
+
autoload :PreviewForm, 'kintone/command/preview_form'
|
8
|
+
autoload :App, 'kintone/command/app'
|
9
|
+
autoload :Apps, 'kintone/command/apps'
|
10
|
+
autoload :AppAcl, 'kintone/command/app_acl'
|
11
|
+
autoload :RecordAcl, 'kintone/command/record_acl'
|
12
|
+
autoload :FieldAcl, 'kintone/command/field_acl'
|
13
|
+
autoload :Space, 'kintone/command/space'
|
14
|
+
autoload :SpaceBody, 'kintone/command/space_body'
|
15
|
+
autoload :SpaceThread, 'kintone/command/space_thread'
|
16
|
+
autoload :SpaceMembers, 'kintone/command/space_members'
|
17
|
+
autoload :File, 'kintone/command/file'
|
18
|
+
|
19
|
+
# other than guest
|
20
|
+
autoload :TemplateSpace, 'kintone/command/template_space'
|
21
|
+
autoload :Guests, 'kintone/command/guests'
|
22
|
+
autoload :Apis, 'kintone/command/apis'
|
23
|
+
|
24
|
+
# guest only
|
25
|
+
autoload :SpaceGuests, 'kintone/command/space_guests'
|
26
|
+
|
27
|
+
module Accessor
|
28
|
+
# common
|
29
|
+
def record(api)
|
30
|
+
Record.new(api)
|
31
|
+
end
|
32
|
+
|
33
|
+
def records(api)
|
34
|
+
Records.new(api)
|
35
|
+
end
|
36
|
+
|
37
|
+
def bulk_request(api)
|
38
|
+
BulkRequest.new(api)
|
39
|
+
end
|
40
|
+
|
41
|
+
def form(api)
|
42
|
+
Form.new(api)
|
43
|
+
end
|
44
|
+
|
45
|
+
def preview_form(api)
|
46
|
+
PreviewForm.new(api)
|
47
|
+
end
|
48
|
+
|
49
|
+
def app(api)
|
50
|
+
App.new(api)
|
51
|
+
end
|
52
|
+
|
53
|
+
def apps(api)
|
54
|
+
Apps.new(api)
|
55
|
+
end
|
56
|
+
|
57
|
+
def app_acl(api)
|
58
|
+
AppAcl.new(api)
|
59
|
+
end
|
60
|
+
|
61
|
+
def record_acl(api)
|
62
|
+
RecordAcl.new(api)
|
63
|
+
end
|
64
|
+
|
65
|
+
def field_acl(api)
|
66
|
+
FieldAcl.new(api)
|
67
|
+
end
|
68
|
+
|
69
|
+
def space(api)
|
70
|
+
Space.new(api)
|
71
|
+
end
|
72
|
+
|
73
|
+
def space_body(api)
|
74
|
+
SpaceBody.new(api)
|
75
|
+
end
|
76
|
+
|
77
|
+
def space_thread(api)
|
78
|
+
SpaceThread.new(api)
|
79
|
+
end
|
80
|
+
|
81
|
+
def space_members(api)
|
82
|
+
SpaceMembers.new(api)
|
83
|
+
end
|
84
|
+
|
85
|
+
def file(api)
|
86
|
+
File.new(api)
|
87
|
+
end
|
88
|
+
|
89
|
+
# other than guest
|
90
|
+
def template_space(api)
|
91
|
+
TemplateSpace.new(api)
|
92
|
+
end
|
93
|
+
|
94
|
+
def guests(api)
|
95
|
+
Guests.new(api)
|
96
|
+
end
|
97
|
+
|
98
|
+
def apis(api)
|
99
|
+
Apis.new(api)
|
100
|
+
end
|
101
|
+
|
102
|
+
# guest only
|
103
|
+
def space_guests(api)
|
104
|
+
SpaceGuests.new(api)
|
105
|
+
end
|
106
|
+
|
107
|
+
alias bulk bulk_request
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'kintone/command'
|
2
|
+
|
3
|
+
class Kintone::Command::Apis < Kintone::Command
|
4
|
+
def self.path
|
5
|
+
'apis'
|
6
|
+
end
|
7
|
+
|
8
|
+
def get
|
9
|
+
@api.get(@url)
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_details_of(link)
|
13
|
+
url = Kintone::Api::BASE_PATH + link
|
14
|
+
@api.get(url)
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_details_of_key(key)
|
18
|
+
response = get
|
19
|
+
link = response['apis'][key]['link']
|
20
|
+
get_details_of(link)
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'kintone/command'
|
2
|
+
|
3
|
+
class Kintone::Command::File < Kintone::Command
|
4
|
+
def self.path
|
5
|
+
'file'
|
6
|
+
end
|
7
|
+
|
8
|
+
def get(file_key)
|
9
|
+
@api.get(@url, fileKey: file_key)
|
10
|
+
end
|
11
|
+
|
12
|
+
def register(path, content_type, original_filename)
|
13
|
+
@api.post_file(@url, path, content_type, original_filename)
|
14
|
+
end
|
15
|
+
end
|