kintone_rb 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +7 -0
  2. data/.github/dependabot.yml +7 -0
  3. data/.github/workflows/rspec.yml +28 -0
  4. data/.gitignore +20 -0
  5. data/.rspec +1 -0
  6. data/.rubocop.yml +47 -0
  7. data/.ruby-version +1 -0
  8. data/CHANGELOG.md +4 -0
  9. data/Gemfile +4 -0
  10. data/LICENSE.txt +22 -0
  11. data/README.md +361 -0
  12. data/Rakefile +6 -0
  13. data/kintone.gemspec +30 -0
  14. data/lib/kintone/api/guest.rb +44 -0
  15. data/lib/kintone/api.rb +121 -0
  16. data/lib/kintone/command/accessor.rb +109 -0
  17. data/lib/kintone/command/apis.rb +22 -0
  18. data/lib/kintone/command/app.rb +11 -0
  19. data/lib/kintone/command/app_acl.rb +11 -0
  20. data/lib/kintone/command/apps.rb +12 -0
  21. data/lib/kintone/command/bulk_request.rb +12 -0
  22. data/lib/kintone/command/field_acl.rb +11 -0
  23. data/lib/kintone/command/file.rb +15 -0
  24. data/lib/kintone/command/form.rb +11 -0
  25. data/lib/kintone/command/guests.rb +17 -0
  26. data/lib/kintone/command/preview_form.rb +11 -0
  27. data/lib/kintone/command/record.rb +23 -0
  28. data/lib/kintone/command/record_acl.rb +11 -0
  29. data/lib/kintone/command/records.rb +29 -0
  30. data/lib/kintone/command/space.rb +15 -0
  31. data/lib/kintone/command/space_body.rb +11 -0
  32. data/lib/kintone/command/space_guests.rb +11 -0
  33. data/lib/kintone/command/space_members.rb +16 -0
  34. data/lib/kintone/command/space_thread.rb +14 -0
  35. data/lib/kintone/command/template_space.rb +12 -0
  36. data/lib/kintone/command.rb +12 -0
  37. data/lib/kintone/kintone_error.rb +12 -0
  38. data/lib/kintone/query/extension.rb +23 -0
  39. data/lib/kintone/query.rb +152 -0
  40. data/lib/kintone/type/extension/enumerable.rb +5 -0
  41. data/lib/kintone/type/extension/hash.rb +5 -0
  42. data/lib/kintone/type/extension/object.rb +5 -0
  43. data/lib/kintone/type/record.rb +11 -0
  44. data/lib/kintone/type.rb +6 -0
  45. data/lib/kintone/version.rb +3 -0
  46. data/lib/kintone_rb.rb +7 -0
  47. data/spec/kintone/api/guest_spec.rb +289 -0
  48. data/spec/kintone/api_spec.rb +566 -0
  49. data/spec/kintone/command/apis_spec.rb +179 -0
  50. data/spec/kintone/command/app_acl_spec.rb +43 -0
  51. data/spec/kintone/command/app_spec.rb +54 -0
  52. data/spec/kintone/command/apps_spec.rb +90 -0
  53. data/spec/kintone/command/bulk_request_spec.rb +92 -0
  54. data/spec/kintone/command/field_acl_spec.rb +47 -0
  55. data/spec/kintone/command/file_spec.rb +65 -0
  56. data/spec/kintone/command/form_spec.rb +47 -0
  57. data/spec/kintone/command/guests_spec.rb +107 -0
  58. data/spec/kintone/command/preview_form_spec.rb +30 -0
  59. data/spec/kintone/command/record_acl_spec.rb +48 -0
  60. data/spec/kintone/command/record_spec.rb +210 -0
  61. data/spec/kintone/command/records_spec.rb +463 -0
  62. data/spec/kintone/command/space_body_spec.rb +47 -0
  63. data/spec/kintone/command/space_guests_spec.rb +55 -0
  64. data/spec/kintone/command/space_members_spec.rb +117 -0
  65. data/spec/kintone/command/space_spec.rb +86 -0
  66. data/spec/kintone/command/space_thread_spec.rb +77 -0
  67. data/spec/kintone/command/template_space_spec.rb +59 -0
  68. data/spec/kintone/kintone_error_spec.rb +93 -0
  69. data/spec/kintone/query_spec.rb +506 -0
  70. data/spec/kintone/type/record_spec.rb +38 -0
  71. data/spec/spec_helper.rb +4 -0
  72. metadata +250 -0
@@ -0,0 +1,107 @@
1
+ require 'spec_helper'
2
+ require 'kintone/command/guests'
3
+ require 'kintone/api'
4
+
5
+ describe Kintone::Command::Guests do
6
+ let(:target) { Kintone::Command::Guests.new(api) }
7
+ let(:api) { Kintone::Api.new('example.cybozu.com', 'Administrator', 'cybozu') }
8
+
9
+ describe '#register' do
10
+ before(:each) do
11
+ stub_request(
12
+ :post,
13
+ 'https://example.cybozu.com/k/v1/guests.json'
14
+ )
15
+ .with(body: { guests: guests }.to_json)
16
+ .to_return(
17
+ body: '{}',
18
+ status: 200,
19
+ headers: { 'Content-type' => 'application/json' }
20
+ )
21
+ end
22
+
23
+ subject { target.register(guests) }
24
+
25
+ let(:guests) do
26
+ [
27
+ {
28
+ code: 'hoge@example.com',
29
+ password: 'password',
30
+ timezone: 'Asia/Tokyo',
31
+ locale: 'ja',
32
+ image: '78a586f2-e73e-4a70-bec2-43976a60746e',
33
+ name: '東京 三郎',
34
+ surNameReading: 'とうきょう',
35
+ givenNameReading: 'さぶろう',
36
+ company: 'サイボウズ株式会社',
37
+ division: '営業部',
38
+ phone: '999-456-7890',
39
+ callto: 'tokyo3rou'
40
+ }
41
+ ]
42
+ end
43
+
44
+ it { is_expected.to be_truthy }
45
+
46
+ context 'fail to request' do
47
+ before(:each) do
48
+ stub_request(
49
+ :post,
50
+ 'https://example.cybozu.com/k/v1/guests.json'
51
+ )
52
+ .with(body: { guests: guests }.to_json)
53
+ .to_return(
54
+ body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
55
+ status: 500,
56
+ headers: { 'Content-type' => 'application/json' }
57
+ )
58
+ end
59
+
60
+ it { expect { subject }.to raise_error Kintone::KintoneError }
61
+ end
62
+ end
63
+
64
+ describe '#delete' do
65
+ before(:each) do
66
+ stub_request(
67
+ :delete,
68
+ 'https://example.cybozu.com/k/v1/guests.json'
69
+ )
70
+ .with(body: { guests: guests }.to_json)
71
+ .to_return(
72
+ body: '{}',
73
+ status: 200,
74
+ headers: { 'Content-type' => 'application/json' }
75
+ )
76
+ end
77
+
78
+ subject { target.delete(guests) }
79
+
80
+ let(:guests) do
81
+ [
82
+ 'guest1@example.com',
83
+ 'guest2@example.com',
84
+ 'guest3@example.com'
85
+ ]
86
+ end
87
+
88
+ it { is_expected.to be_truthy }
89
+
90
+ context 'fail to request' do
91
+ before(:each) do
92
+ stub_request(
93
+ :delete,
94
+ 'https://example.cybozu.com/k/v1/guests.json'
95
+ )
96
+ .with(body: { guests: guests }.to_json)
97
+ .to_return(
98
+ body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
99
+ status: 500,
100
+ headers: { 'Content-Type' => 'application/json' }
101
+ )
102
+ end
103
+
104
+ it { expect { subject }.to raise_error Kintone::KintoneError }
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+ require 'kintone/command/preview_form'
3
+ require 'kintone/api'
4
+
5
+ describe Kintone::Command::PreviewForm do
6
+ let(:target) { Kintone::Command::PreviewForm.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/preview/form.json'
14
+ )
15
+ .with(body: request_body.to_json)
16
+ .to_return(
17
+ body: '{"result":"ok"}',
18
+ status: 200,
19
+ headers: { 'Content-type' => 'application/json' }
20
+ )
21
+ end
22
+
23
+ subject { target.get(app) }
24
+
25
+ let(:app) { 1 }
26
+ let(:request_body) { { app: app } }
27
+
28
+ it { expect(subject).to eq 'result' => 'ok' }
29
+ end
30
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+ require 'kintone/command/record_acl'
3
+ require 'kintone/api'
4
+
5
+ describe Kintone::Command::RecordAcl do
6
+ let(:target) { Kintone::Command::RecordAcl.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/record/acl.json'
14
+ )
15
+ .with(body: request_body.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, rights) }
24
+
25
+ let(:id) { 1 }
26
+ let(:rights) { { 'p1' => 'abc', 'p2' => 'def' } }
27
+ let(:request_body) { { 'id' => 1, 'rights' => { 'p1' => 'abc', 'p2' => 'def' } } }
28
+
29
+ it { expect(subject).to eq({}) }
30
+
31
+ context 'fail to request' do
32
+ before(:each) do
33
+ stub_request(
34
+ :put,
35
+ 'https://example.cybozu.com/k/v1/record/acl.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
+ end
@@ -0,0 +1,210 @@
1
+ require 'spec_helper'
2
+ require 'kintone/command/record'
3
+ require 'kintone/api'
4
+ require 'kintone/type/record'
5
+
6
+ describe Kintone::Command::Record do
7
+ let(:target) { Kintone::Command::Record.new(api) }
8
+ let(:api) { Kintone::Api.new('www.example.com', 'Administrator', 'cybozu') }
9
+
10
+ describe '#get' do
11
+ before(:each) do
12
+ stub_request(:get, 'https://www.example.com/k/v1/record.json')
13
+ .with(body: request_body.to_json)
14
+ .to_return(
15
+ body: '{"result":"ok"}',
16
+ status: 200,
17
+ headers: { 'Content-Type' => 'application/json' }
18
+ )
19
+ end
20
+
21
+ subject { target.get(app, id) }
22
+
23
+ let(:request_body) { { app: app, id: id } }
24
+
25
+ where(:app, :id) do
26
+ [
27
+ [8, 100],
28
+ ['8', '100']
29
+ ]
30
+ end
31
+
32
+ with_them do
33
+ it { expect(subject).to eq 'result' => 'ok' }
34
+ end
35
+
36
+ context 'fail to request' do
37
+ before(:each) do
38
+ stub_request(:get, 'https://www.example.com/k/v1/record.json')
39
+ .with(body: request_body)
40
+ .to_return(
41
+ body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
42
+ status: 500,
43
+ headers: { 'Content-Type' => 'application/json' }
44
+ )
45
+ end
46
+
47
+ let(:app) { 8 }
48
+ let(:id) { 100 }
49
+
50
+ it { expect { subject }.to raise_error Kintone::KintoneError }
51
+ end
52
+ end
53
+
54
+ describe '#register' do
55
+ before(:each) do
56
+ stub_request(
57
+ :post,
58
+ 'https://www.example.com/k/v1/record.json'
59
+ )
60
+ .with(body: request_body.to_json)
61
+ .to_return(
62
+ body: response_body.to_json,
63
+ status: 200,
64
+ headers: { 'Content-type' => 'application/json' }
65
+ )
66
+ end
67
+
68
+ subject { target.register(app, record) }
69
+
70
+ let(:app) { 7 }
71
+ let(:request_body) do
72
+ {
73
+ 'app' => 7,
74
+ 'record' => {
75
+ 'number' => { 'value' => '123456' },
76
+ 'rich_editor' => { 'value' => 'testtest' },
77
+ 'user_select' => { 'value' => [{ 'code' => 'sato' }] }
78
+ }
79
+ }
80
+ end
81
+ let(:response_body) { { 'id' => '100', 'revision' => '1' } }
82
+
83
+ context 'use hash' do
84
+ let(:record) do
85
+ {
86
+ 'number' => { 'value' => '123456' },
87
+ 'rich_editor' => { 'value' => 'testtest' },
88
+ 'user_select' => { 'value' => [{ 'code' => 'sato' }] }
89
+ }
90
+ end
91
+
92
+ it { expect(subject).to eq response_body }
93
+ end
94
+
95
+ context 'use record' do
96
+ let(:record) do
97
+ Kintone::Type::Record.new(
98
+ number: '123456',
99
+ rich_editor: 'testtest',
100
+ user_select: [{ 'code' => 'sato' }]
101
+ )
102
+ end
103
+
104
+ it { expect(subject).to eq response_body }
105
+ end
106
+
107
+ context 'fail to request' do
108
+ before(:each) do
109
+ stub_request(
110
+ :post,
111
+ 'https://www.example.com/k/v1/record.json'
112
+ )
113
+ .with(body: request_body.to_json)
114
+ .to_return(
115
+ body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
116
+ status: 500,
117
+ headers: { 'Content-Type' => 'application/json' }
118
+ )
119
+ end
120
+
121
+ let(:record) do
122
+ {
123
+ 'number' => { 'value' => '123456' },
124
+ 'rich_editor' => { 'value' => 'testtest' },
125
+ 'user_select' => { 'value' => [{ 'code' => 'sato' }] }
126
+ }
127
+ end
128
+
129
+ it { expect { subject }.to raise_error Kintone::KintoneError }
130
+ end
131
+ end
132
+
133
+ describe '#update' do
134
+ before(:each) do
135
+ stub_request(
136
+ :put,
137
+ 'https://www.example.com/k/v1/record.json'
138
+ )
139
+ .with(body: request_body.to_json)
140
+ .to_return(
141
+ body: response_body.to_json,
142
+ status: 200,
143
+ headers: { 'Content-type' => 'application/json' }
144
+ )
145
+ end
146
+
147
+ subject { target.update(app, id, record) }
148
+
149
+ let(:app) { 4 }
150
+ let(:id) { 1 }
151
+ let(:hash_record) { { 'string_multi' => { 'value' => 'character string is changed' } } }
152
+ let(:record_record) { Kintone::Type::Record.new(string_multi: 'character string is changed') }
153
+ let(:response_body) { { revision: '2' } }
154
+
155
+ context 'without revision' do
156
+ let(:request_body) { { 'app' => 4, 'id' => 1, 'record' => hash_record } }
157
+
158
+ context 'use hash' do
159
+ let(:record) { hash_record }
160
+
161
+ it { expect(subject).to match 'revision' => '2' }
162
+ end
163
+
164
+ context 'use record' do
165
+ let(:record) { record_record }
166
+
167
+ it { expect(subject).to match 'revision' => '2' }
168
+ end
169
+ end
170
+
171
+ context 'with revision' do
172
+ subject { target.update(app, id, record, revision: revision) }
173
+
174
+ let(:revision) { 1 }
175
+ let(:request_body) { { 'app' => 4, 'id' => 1, 'record' => hash_record, 'revision' => 1 } }
176
+
177
+ context 'use hash' do
178
+ let(:record) { hash_record }
179
+
180
+ it { expect(subject).to match 'revision' => '2' }
181
+ end
182
+
183
+ context 'use record' do
184
+ let(:record) { record_record }
185
+
186
+ it { expect(subject).to match 'revision' => '2' }
187
+ end
188
+ end
189
+
190
+ context 'fail to request' do
191
+ before(:each) do
192
+ stub_request(
193
+ :put,
194
+ 'https://www.example.com/k/v1/record.json'
195
+ )
196
+ .with(body: request_body.to_json)
197
+ .to_return(
198
+ body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
199
+ status: 500,
200
+ headers: { 'Content-Type' => 'application/json' }
201
+ )
202
+ end
203
+
204
+ let(:request_body) { { 'app' => 4, 'id' => 1, 'record' => hash_record } }
205
+ let(:record) { hash_record }
206
+
207
+ it { expect { subject }.to raise_error Kintone::KintoneError }
208
+ end
209
+ end
210
+ end