kintone_rb 1.0.0

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 (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,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