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.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/gem-push.yml +37 -0
  3. data/.github/workflows/test.yml +21 -0
  4. data/.gitignore +21 -0
  5. data/.rspec +1 -0
  6. data/.rubocop.yml +47 -0
  7. data/CHANGELOG.md +13 -0
  8. data/CODE_OF_CONDUCT.md +74 -0
  9. data/Gemfile +4 -0
  10. data/LICENSE.txt +21 -0
  11. data/README.md +374 -0
  12. data/bin/console +4 -0
  13. data/bin/setup +6 -0
  14. data/kintone.gemspec +38 -0
  15. data/lib/kintone.rb +8 -0
  16. data/lib/kintone/api.rb +121 -0
  17. data/lib/kintone/api/guest.rb +44 -0
  18. data/lib/kintone/command.rb +12 -0
  19. data/lib/kintone/command/accessor.rb +109 -0
  20. data/lib/kintone/command/apis.rb +22 -0
  21. data/lib/kintone/command/app.rb +11 -0
  22. data/lib/kintone/command/app_acl.rb +11 -0
  23. data/lib/kintone/command/apps.rb +12 -0
  24. data/lib/kintone/command/bulk_request.rb +12 -0
  25. data/lib/kintone/command/field_acl.rb +11 -0
  26. data/lib/kintone/command/file.rb +15 -0
  27. data/lib/kintone/command/form.rb +11 -0
  28. data/lib/kintone/command/guests.rb +17 -0
  29. data/lib/kintone/command/preview_form.rb +11 -0
  30. data/lib/kintone/command/record.rb +23 -0
  31. data/lib/kintone/command/record_acl.rb +11 -0
  32. data/lib/kintone/command/records.rb +29 -0
  33. data/lib/kintone/command/space.rb +15 -0
  34. data/lib/kintone/command/space_body.rb +11 -0
  35. data/lib/kintone/command/space_guests.rb +11 -0
  36. data/lib/kintone/command/space_members.rb +16 -0
  37. data/lib/kintone/command/space_thread.rb +14 -0
  38. data/lib/kintone/command/template_space.rb +12 -0
  39. data/lib/kintone/kintone_error.rb +12 -0
  40. data/lib/kintone/oauth_api.rb +91 -0
  41. data/lib/kintone/query.rb +152 -0
  42. data/lib/kintone/query/extension.rb +23 -0
  43. data/lib/kintone/type.rb +6 -0
  44. data/lib/kintone/type/extension/enumerable.rb +5 -0
  45. data/lib/kintone/type/extension/hash.rb +5 -0
  46. data/lib/kintone/type/extension/object.rb +5 -0
  47. data/lib/kintone/type/record.rb +11 -0
  48. data/lib/kintone/version.rb +3 -0
  49. data/spec/kintone/api/guest_spec.rb +289 -0
  50. data/spec/kintone/api_spec.rb +566 -0
  51. data/spec/kintone/command/apis_spec.rb +179 -0
  52. data/spec/kintone/command/app_acl_spec.rb +43 -0
  53. data/spec/kintone/command/app_spec.rb +54 -0
  54. data/spec/kintone/command/apps_spec.rb +90 -0
  55. data/spec/kintone/command/bulk_request_spec.rb +92 -0
  56. data/spec/kintone/command/field_acl_spec.rb +47 -0
  57. data/spec/kintone/command/file_spec.rb +65 -0
  58. data/spec/kintone/command/form_spec.rb +47 -0
  59. data/spec/kintone/command/guests_spec.rb +107 -0
  60. data/spec/kintone/command/preview_form_spec.rb +30 -0
  61. data/spec/kintone/command/record_acl_spec.rb +48 -0
  62. data/spec/kintone/command/record_spec.rb +210 -0
  63. data/spec/kintone/command/records_spec.rb +463 -0
  64. data/spec/kintone/command/space_body_spec.rb +47 -0
  65. data/spec/kintone/command/space_guests_spec.rb +55 -0
  66. data/spec/kintone/command/space_members_spec.rb +117 -0
  67. data/spec/kintone/command/space_spec.rb +86 -0
  68. data/spec/kintone/command/space_thread_spec.rb +77 -0
  69. data/spec/kintone/command/template_space_spec.rb +59 -0
  70. data/spec/kintone/kintone_error_spec.rb +93 -0
  71. data/spec/kintone/oauth_api_spec.rb +164 -0
  72. data/spec/kintone/query_spec.rb +506 -0
  73. data/spec/kintone/type/record_spec.rb +38 -0
  74. data/spec/spec_helper.rb +10 -0
  75. metadata +302 -0
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+ require 'kintone/command/space_body'
3
+ require 'kintone/api'
4
+
5
+ describe Kintone::Command::SpaceBody do
6
+ let(:target) { Kintone::Command::SpaceBody.new(api) }
7
+ let(:api) { Kintone::Api.new('example.cybozu.com', 'Administrator', 'cybozu') }
8
+
9
+ describe '#update' do
10
+ before(:each) do
11
+ stub_request(
12
+ :put,
13
+ 'https://example.cybozu.com/k/v1/space/body.json'
14
+ )
15
+ .with(body: { id: 1, body: '<b>総務課</b>専用のスペースです。' }.to_json)
16
+ .to_return(
17
+ body: '{}',
18
+ status: 200,
19
+ headers: { 'Content-type' => 'application/json' }
20
+ )
21
+ end
22
+
23
+ subject { target.update(id, body) }
24
+
25
+ let(:id) { 1 }
26
+ let(:body) { '<b>総務課</b>専用のスペースです。' }
27
+
28
+ it { expect(subject).to eq({}) }
29
+
30
+ context 'fail to request' do
31
+ before(:each) do
32
+ stub_request(
33
+ :put,
34
+ 'https://example.cybozu.com/k/v1/space/body.json'
35
+ )
36
+ .with(body: { id: 1, body: '<b>総務課</b>専用のスペースです。' }.to_json)
37
+ .to_return(
38
+ body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
39
+ status: 500,
40
+ headers: { 'Content-Type' => 'application/json' }
41
+ )
42
+ end
43
+
44
+ it { expect { subject }.to raise_error Kintone::KintoneError }
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+ require 'kintone/command/space_guests'
3
+ require 'kintone/api'
4
+
5
+ describe Kintone::Command::SpaceGuests do
6
+ let(:target) { Kintone::Command::SpaceGuests.new(guest) }
7
+ let(:guest) { api.guest(guest_id) }
8
+ let(:guest_id) { 1 }
9
+ let(:api) { Kintone::Api.new('example.cybozu.com', 'Administrator', 'cybozu') }
10
+
11
+ describe '#update' do
12
+ before(:each) do
13
+ stub_request(
14
+ :put,
15
+ 'https://example.cybozu.com/k/guest/1/v1/space/guests.json'
16
+ )
17
+ .with(body: { id: id, guests: guests }.to_json)
18
+ .to_return(
19
+ body: '{}',
20
+ status: 200,
21
+ headers: { 'Content-type' => 'application/json' }
22
+ )
23
+ end
24
+
25
+ subject { target.update(id, guests) }
26
+
27
+ let(:id) { 10 }
28
+ let(:guests) do
29
+ [
30
+ 'guest1@example.com',
31
+ 'guest2@example.com',
32
+ 'guest3@example.com'
33
+ ]
34
+ end
35
+
36
+ it { is_expected.to be_truthy }
37
+
38
+ context 'fail to request' do
39
+ before(:each) do
40
+ stub_request(
41
+ :put,
42
+ 'https://example.cybozu.com/k/guest/1/v1/space/guests.json'
43
+ )
44
+ .with(body: { id: id, guests: guests }.to_json)
45
+ .to_return(
46
+ body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
47
+ status: 500,
48
+ headers: { 'Content-Type' => 'application/json' }
49
+ )
50
+ end
51
+
52
+ it { expect { subject }.to raise_error Kintone::KintoneError }
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,117 @@
1
+ require 'spec_helper'
2
+ require 'kintone/command/space_members'
3
+ require 'kintone/api'
4
+
5
+ describe Kintone::Command::SpaceMembers do
6
+ let(:target) { Kintone::Command::SpaceMembers.new(api) }
7
+ let(:api) { Kintone::Api.new('example.cybozu.com', 'Administrator', 'cybozu') }
8
+
9
+ describe '#get' do
10
+ before(:each) do
11
+ stub_request(
12
+ :get,
13
+ 'https://example.cybozu.com/k/v1/space/members.json'
14
+ )
15
+ .with(body: request_body.to_json)
16
+ .to_return(
17
+ body: response_data.to_json,
18
+ status: 200,
19
+ headers: { 'Content-type' => 'application/json' }
20
+ )
21
+ end
22
+
23
+ subject { target.get(id) }
24
+
25
+ let(:id) { 1 }
26
+ let(:request_body) { { id: id } }
27
+ let(:response_data) { { 'members' => members } }
28
+ let(:members) do
29
+ [
30
+ {
31
+ 'entity' => { 'type' => 'USER', 'code' => 'user1' },
32
+ 'isAdmin' => false,
33
+ 'isImplicit' => true
34
+ }
35
+ ]
36
+ end
37
+
38
+ it { expect(subject).to match members }
39
+
40
+ context 'fail to request' do
41
+ before(:each) do
42
+ stub_request(
43
+ :get,
44
+ 'https://example.cybozu.com/k/v1/space/members.json'
45
+ )
46
+ .with(body: request_body.to_json)
47
+ .to_return(
48
+ body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
49
+ status: 500,
50
+ headers: { 'Content-Type' => 'application/json' }
51
+ )
52
+ end
53
+
54
+ it { expect { subject }.to raise_error Kintone::KintoneError }
55
+ end
56
+ end
57
+
58
+ describe '#update' do
59
+ before(:each) do
60
+ stub_request(
61
+ :put,
62
+ 'https://example.cybozu.com/k/v1/space/members.json'
63
+ )
64
+ .with(body: request_data.to_json)
65
+ .to_return(
66
+ body: '{}',
67
+ status: 200,
68
+ headers: { 'Content-type' => 'application/json' }
69
+ )
70
+ end
71
+
72
+ subject { target.update(id, members) }
73
+
74
+ let(:id) { 1 }
75
+ let(:members) do
76
+ [
77
+ {
78
+ 'entity' => { 'type' => 'USER', 'code' => 'user1' },
79
+ 'isAdmin' => false,
80
+ 'isImplicit' => true
81
+ }
82
+ ]
83
+ end
84
+
85
+ let(:request_data) do
86
+ {
87
+ 'id' => 1,
88
+ 'members' => [
89
+ {
90
+ 'entity' => { 'type' => 'USER', 'code' => 'user1' },
91
+ 'isAdmin' => false,
92
+ 'isImplicit' => true
93
+ }
94
+ ]
95
+ }
96
+ end
97
+
98
+ it { expect(subject).to be_truthy }
99
+
100
+ context 'fail to request' do
101
+ before(:each) do
102
+ stub_request(
103
+ :put,
104
+ 'https://example.cybozu.com/k/v1/space/members.json'
105
+ )
106
+ .with(body: request_data.to_json)
107
+ .to_return(
108
+ body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
109
+ status: 500,
110
+ headers: { 'Content-Type' => 'application/json' }
111
+ )
112
+ end
113
+
114
+ it { expect { subject }.to raise_error Kintone::KintoneError }
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+ require 'kintone/command/space'
3
+ require 'kintone/api'
4
+
5
+ describe Kintone::Command::Space do
6
+ let(:target) { Kintone::Command::Space.new(api) }
7
+ let(:api) { Kintone::Api.new('example.cybozu.com', 'Administrator', 'cybozu') }
8
+
9
+ describe '#get' do
10
+ before(:each) do
11
+ stub_request(
12
+ :get,
13
+ 'https://example.cybozu.com/k/v1/space.json'
14
+ )
15
+ .with(body: request_body.to_json)
16
+ .to_return(
17
+ body: result.to_json,
18
+ status: 200,
19
+ headers: { 'Content-type' => 'application/json' }
20
+ )
21
+ end
22
+
23
+ subject { target.get(id) }
24
+
25
+ let(:id) { 1 }
26
+ let(:request_body) { { id: id } }
27
+ let(:result) { { 'id' => '1', 'name' => 'sample space' } }
28
+
29
+ it { expect(subject).to eq(result) }
30
+
31
+ context 'fail to request' do
32
+ before(:each) do
33
+ stub_request(
34
+ :get,
35
+ 'https://example.cybozu.com/k/v1/space.json'
36
+ )
37
+ .with(body: request_body.to_json)
38
+ .to_return(
39
+ body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
40
+ status: 500,
41
+ headers: { 'Content-Type' => 'application/json' }
42
+ )
43
+ end
44
+
45
+ it { expect { subject }.to raise_error Kintone::KintoneError }
46
+ end
47
+ end
48
+
49
+ describe '#delete' do
50
+ before(:each) do
51
+ stub_request(
52
+ :delete,
53
+ 'https://example.cybozu.com/k/v1/space.json'
54
+ )
55
+ .with(body: { id: 1 }.to_json)
56
+ .to_return(
57
+ body: '{}',
58
+ status: 200,
59
+ headers: { 'Content-type' => 'application/json' }
60
+ )
61
+ end
62
+
63
+ subject { target.delete(id) }
64
+
65
+ let(:id) { 1 }
66
+
67
+ it { expect(subject).to be_truthy }
68
+
69
+ context 'fail to request' do
70
+ before(:each) do
71
+ stub_request(
72
+ :delete,
73
+ 'https://example.cybozu.com/k/v1/space.json'
74
+ )
75
+ .with(body: { id: 1 }.to_json)
76
+ .to_return(
77
+ body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
78
+ status: 500,
79
+ headers: { 'Content-Type' => 'application/json' }
80
+ )
81
+ end
82
+
83
+ it { expect { subject }.to raise_error Kintone::KintoneError }
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,77 @@
1
+ require 'spec_helper'
2
+ require 'kintone/command/space_thread'
3
+ require 'kintone/api'
4
+
5
+ describe Kintone::Command::SpaceThread do
6
+ let(:target) { Kintone::Command::SpaceThread.new(api) }
7
+ let(:api) { Kintone::Api.new('example.cybozu.com', 'Administrator', 'cybozu') }
8
+
9
+ describe '#update' do
10
+ before(:each) do
11
+ stub_request(
12
+ :put,
13
+ 'https://example.cybozu.com/k/v1/space/thread.json'
14
+ )
15
+ .with(body: request_body)
16
+ .to_return(
17
+ body: '{}',
18
+ status: 200,
19
+ headers: { 'Content-type' => 'application/json' }
20
+ )
21
+ end
22
+
23
+ subject { target.update(id, name: name, body: body) }
24
+
25
+ let(:id) { 1 }
26
+
27
+ where(:name, :body, :request_body) do
28
+ [
29
+ [
30
+ 'example thread',
31
+ '<b>awesome thread!</b>',
32
+ '{"id":1,"name":"example thread","body":"<b>awesome thread!</b>"}'
33
+ ],
34
+ [
35
+ nil,
36
+ '<b>awesome thread!</b>',
37
+ '{"id":1,"body":"<b>awesome thread!</b>"}'
38
+ ],
39
+ [
40
+ 'example thread',
41
+ nil,
42
+ '{"id":1,"name":"example thread"}'
43
+ ],
44
+ [
45
+ nil,
46
+ nil,
47
+ '{"id":1}'
48
+ ]
49
+ ]
50
+ end
51
+
52
+ with_them do
53
+ it { expect(subject).to be_truthy }
54
+ end
55
+
56
+ context 'fail to request' do
57
+ before(:each) do
58
+ stub_request(
59
+ :put,
60
+ 'https://example.cybozu.com/k/v1/space/thread.json'
61
+ )
62
+ .with(body: request_body)
63
+ .to_return(
64
+ body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
65
+ status: 500,
66
+ headers: { 'Content-Type' => 'application/json' }
67
+ )
68
+ end
69
+
70
+ let(:name) { 'example thread' }
71
+ let(:body) { '<b>awesome thread!</b>' }
72
+ let(:request_body) { '{"id":1,"name":"example thread","body":"<b>awesome thread!</b>"}' }
73
+
74
+ it { expect { subject }.to raise_error Kintone::KintoneError }
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+ require 'kintone/command/template_space'
3
+ require 'kintone/api'
4
+
5
+ describe Kintone::Command::TemplateSpace do
6
+ let(:target) { Kintone::Command::TemplateSpace.new(api) }
7
+ let(:api) { Kintone::Api.new('example.cybozu.com', 'Administrator', 'cybozu') }
8
+
9
+ describe '#create' do
10
+ before(:each) do
11
+ stub_request(
12
+ :post,
13
+ 'https://example.cybozu.com/k/v1/template/space.json'
14
+ )
15
+ .with(body: request_data.to_json)
16
+ .to_return(
17
+ body: '{"id":"1"}',
18
+ status: 200,
19
+ headers: { 'Content-type' => 'application/json' }
20
+ )
21
+ end
22
+
23
+ subject { target.create(id, name, members, is_guest: is_guest, fixed_member: fixed_member) }
24
+
25
+ let(:id) { 1 }
26
+ let(:name) { 'sample space' }
27
+ let(:members) { [] }
28
+ let(:is_guest) { false }
29
+ let(:fixed_member) { false }
30
+ let(:request_data) do
31
+ {
32
+ id: id,
33
+ name: name,
34
+ members: members,
35
+ isGuest: is_guest,
36
+ fixedMember: fixed_member
37
+ }
38
+ end
39
+
40
+ it { expect(subject).to eq 'id' => '1' }
41
+
42
+ context 'fail to request' do
43
+ before(:each) do
44
+ stub_request(
45
+ :post,
46
+ 'https://example.cybozu.com/k/v1/template/space.json'
47
+ )
48
+ .with(body: request_data.to_json)
49
+ .to_return(
50
+ body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
51
+ status: 500,
52
+ headers: { 'Content-Type' => 'application/json' }
53
+ )
54
+ end
55
+
56
+ it { expect { subject }.to raise_error Kintone::KintoneError }
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,93 @@
1
+ require 'spec_helper'
2
+ require 'kintone/kintone_error'
3
+
4
+ describe Kintone::KintoneError do
5
+ let(:target) { Kintone::KintoneError.new(messages, http_status) }
6
+
7
+ describe '#message' do
8
+ subject { target.message }
9
+
10
+ context '不正なJSONの場合' do
11
+ let(:messages) do
12
+ {
13
+ 'message' => '不正なJSON文字列です。',
14
+ 'id' => '1505999166-897850006',
15
+ 'code' => 'CB_IJ01'
16
+ }
17
+ end
18
+
19
+ let(:http_status) { 500 }
20
+
21
+ it { is_expected.to eq '500 [CB_IJ01] 不正なJSON文字列です。(1505999166-897850006)' }
22
+
23
+ describe '#message_text' do
24
+ subject { target.message_text }
25
+ it { is_expected.to eq '不正なJSON文字列です。' }
26
+ end
27
+
28
+ describe '#id' do
29
+ subject { target.id }
30
+ it { is_expected.to eq '1505999166-897850006' }
31
+ end
32
+
33
+ describe '#code' do
34
+ subject { target.code }
35
+ it { is_expected.to eq 'CB_IJ01' }
36
+ end
37
+
38
+ describe '#http_status' do
39
+ subject { target.http_status }
40
+ it { is_expected.to eq 500 }
41
+ end
42
+
43
+ describe '#errors' do
44
+ subject { target.errors }
45
+ it { is_expected.to be_nil }
46
+ end
47
+ end
48
+
49
+ context 'Validation Errorの場合' do
50
+ let(:messages) do
51
+ {
52
+ 'message' => '入力内容が正しくありません。',
53
+ 'id' => '1505999166-836316825',
54
+ 'code' => 'CB_VA01',
55
+ 'errors' => {
56
+ 'record.field_code.value' => {
57
+ 'messages' => ['必須です。']
58
+ }
59
+ }
60
+ }
61
+ end
62
+
63
+ let(:http_status) { 400 }
64
+
65
+ it { is_expected.to eq '400 [CB_VA01] 入力内容が正しくありません。(1505999166-836316825)' }
66
+
67
+ describe '#message_text' do
68
+ subject { target.message_text }
69
+ it { is_expected.to eq '入力内容が正しくありません。' }
70
+ end
71
+
72
+ describe '#id' do
73
+ subject { target.id }
74
+ it { is_expected.to eq '1505999166-836316825' }
75
+ end
76
+
77
+ describe '#code' do
78
+ subject { target.code }
79
+ it { is_expected.to eq 'CB_VA01' }
80
+ end
81
+
82
+ describe '#http_status' do
83
+ subject { target.http_status }
84
+ it { is_expected.to eq 400 }
85
+ end
86
+
87
+ describe '#errors' do
88
+ subject { target.errors['record.field_code.value']['messages'].first }
89
+ it { is_expected.to eq '必須です。' }
90
+ end
91
+ end
92
+ end
93
+ end