kintone 0.0.4 → 0.0.5

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 (41) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +26 -0
  3. data/.travis.yml +4 -0
  4. data/Guardfile +10 -0
  5. data/README.md +35 -13
  6. data/Rakefile +9 -1
  7. data/kintone.gemspec +17 -14
  8. data/lib/kintone.rb +2 -2
  9. data/lib/kintone/api.rb +36 -22
  10. data/lib/kintone/api/guest.rb +16 -8
  11. data/lib/kintone/command.rb +11 -2
  12. data/lib/kintone/command/app_acl.rb +4 -8
  13. data/lib/kintone/command/field_acl.rb +4 -8
  14. data/lib/kintone/command/form.rb +4 -8
  15. data/lib/kintone/command/record.rb +6 -10
  16. data/lib/kintone/command/record_acl.rb +4 -8
  17. data/lib/kintone/command/records.rb +11 -15
  18. data/lib/kintone/command/space.rb +15 -0
  19. data/lib/kintone/command/space_body.rb +11 -0
  20. data/lib/kintone/command/template_space.rb +12 -0
  21. data/lib/kintone/version.rb +1 -1
  22. data/spec/kintone/api/guest_spec.rb +134 -0
  23. data/spec/kintone/api_spec.rb +176 -0
  24. data/spec/kintone/command/app_acl_spec.rb +28 -0
  25. data/spec/kintone/command/field_acl_spec.rb +28 -0
  26. data/spec/kintone/command/form_spec.rb +26 -0
  27. data/spec/kintone/command/record_acl_spec.rb +28 -0
  28. data/spec/kintone/command/record_spec.rb +93 -0
  29. data/spec/kintone/command/records_spec.rb +169 -0
  30. data/spec/kintone/command/space_body_spec.rb +28 -0
  31. data/spec/kintone/command/space_spec.rb +53 -0
  32. data/spec/kintone/command/template_space_spec.rb +41 -0
  33. metadata +75 -36
  34. data/spec/api/guest_spec.rb +0 -54
  35. data/spec/api_spec.rb +0 -148
  36. data/spec/command/app_acl_spec.rb +0 -28
  37. data/spec/command/field_acl_spec.rb +0 -28
  38. data/spec/command/form_spec.rb +0 -25
  39. data/spec/command/record_acl_spec.rb +0 -28
  40. data/spec/command/record_spec.rb +0 -92
  41. data/spec/command/records_spec.rb +0 -162
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+ require 'kintone/command/app_acl'
3
+ require 'kintone/api'
4
+
5
+ describe Kintone::Command::AppAcl do
6
+ let(:target) { Kintone::Command::AppAcl.new(api) }
7
+ let(:api) { Kintone::Api.new('example.cybozu.com', 'Administrator', 'cybozu') }
8
+
9
+ describe '#update' do
10
+ subject { target.update(app, rights) }
11
+
12
+ context '' do
13
+ before(:each) do
14
+ stub_request(
15
+ :put,
16
+ 'https://example.cybozu.com/k/v1/app/acl.json'
17
+ )
18
+ .with(body: { 'app' => 1, 'rights' => { 'p1' => 'abc', 'p2' => 'def' } }.to_json)
19
+ .to_return(body: '{}', status: 200)
20
+ end
21
+
22
+ let(:app) { 1 }
23
+ let(:rights) { { 'p1' => 'abc', 'p2' => 'def' } }
24
+
25
+ it { expect(subject).to eq({}) }
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+ require 'kintone/command/field_acl'
3
+ require 'kintone/api'
4
+
5
+ describe Kintone::Command::FieldAcl do
6
+ let(:target) { Kintone::Command::FieldAcl.new(api) }
7
+ let(:api) { Kintone::Api.new('example.cybozu.com', 'Administrator', 'cybozu') }
8
+
9
+ describe '#update' do
10
+ subject { target.update(id, rights) }
11
+
12
+ context '' do
13
+ before(:each) do
14
+ stub_request(
15
+ :put,
16
+ 'https://example.cybozu.com/k/v1/field/acl.json'
17
+ )
18
+ .with(body: { 'id' => 1, 'rights' => { 'p1' => 'abc', 'p2' => 'def' } }.to_json)
19
+ .to_return(body: '{}', status: 200)
20
+ end
21
+
22
+ let(:id) { 1 }
23
+ let(:rights) { { 'p1' => 'abc', 'p2' => 'def' } }
24
+
25
+ it { expect(subject).to eq({}) }
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+ require 'kintone/command/form'
3
+ require 'kintone/api'
4
+
5
+ describe Kintone::Command::Form do
6
+ let(:target) { Kintone::Command::Form.new(api) }
7
+ let(:api) { Kintone::Api.new('example.cybozu.com', 'Administrator', 'cybozu') }
8
+
9
+ describe '#get' do
10
+ subject { target.get(app) }
11
+
12
+ context '' do
13
+ before(:each) do
14
+ stub_request(
15
+ :get,
16
+ 'https://example.cybozu.com/k/v1/form.json?app=4'
17
+ )
18
+ .to_return(body: "{\"result\":\"ok\"}", status: 200)
19
+ end
20
+
21
+ let(:app) { 4 }
22
+
23
+ it { expect(subject).to eq 'result' => 'ok' }
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,28 @@
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
+ subject { target.update(id, rights) }
11
+
12
+ context '' do
13
+ before(:each) do
14
+ stub_request(
15
+ :put,
16
+ 'https://example.cybozu.com/k/v1/record/acl.json'
17
+ )
18
+ .with(body: { 'id' => 1, 'rights' => { 'p1' => 'abc', 'p2' => 'def' } }.to_json)
19
+ .to_return(body: '{}', status: 200)
20
+ end
21
+
22
+ let(:id) { 1 }
23
+ let(:rights) { { 'p1' => 'abc', 'p2' => 'def' } }
24
+
25
+ it { expect(subject).to eq({}) }
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,93 @@
1
+ require 'spec_helper'
2
+ require 'kintone/command/record'
3
+ require 'kintone/api'
4
+
5
+ describe Kintone::Command::Record do
6
+ let(:target) { Kintone::Command::Record.new(api) }
7
+ let(:api) { Kintone::Api.new('www.example.com', 'Administrator', 'cybozu') }
8
+
9
+ describe '#get' do
10
+ subject { target.get(app, id) }
11
+
12
+ context '引数が整数型の時' do
13
+ before(:each) do
14
+ stub_request(
15
+ :get,
16
+ 'https://www.example.com/k/v1/record.json?app=8&id=100'
17
+ )
18
+ .to_return(body: "{\"result\":\"ok\"}", status: 200)
19
+ end
20
+
21
+ let(:app) { 8 }
22
+ let(:id) { 100 }
23
+
24
+ it { expect(subject).to eq 'result' => 'ok' }
25
+ end
26
+
27
+ context '引数が数字の文字列の時' do
28
+ before(:each) do
29
+ stub_request(
30
+ :get,
31
+ 'https://www.example.com/k/v1/record.json?app=8&id=100'
32
+ )
33
+ .to_return(body: "{\"result\":\"ok\"}", status: 200)
34
+ end
35
+
36
+ let(:app) { '8' }
37
+ let(:id) { '100' }
38
+
39
+ it { expect(subject).to eq 'result' => 'ok' }
40
+ end
41
+ end
42
+
43
+ describe '#create' do
44
+ before(:each) do
45
+ stub_request(
46
+ :post,
47
+ 'https://www.example.com/k/v1/record.json'
48
+ )
49
+ .with(body: { 'app' => 7, 'record' => hash_record }.to_json)
50
+ .to_return(body: "{\"id\":\"100\"}", status: 200)
51
+ end
52
+
53
+ subject { target.create(app, record) }
54
+
55
+ let(:app) { 7 }
56
+ let(:record) { hash_record }
57
+
58
+ def hash_record
59
+ {
60
+ 'number' => { 'value' => '123456' },
61
+ 'rich_editor' => { 'value' => 'testtest' },
62
+ 'user_select' => { 'value' => [{ 'code' => 'sato' }] }
63
+ }
64
+ end
65
+
66
+ it { expect(subject).to eq 'id' => '100' }
67
+ end
68
+
69
+ describe '#update' do
70
+ def hash_record
71
+ {
72
+ 'string_multi' => { 'value' => 'character string is changed' }
73
+ }
74
+ end
75
+
76
+ before(:each) do
77
+ stub_request(
78
+ :put,
79
+ 'https://www.example.com/k/v1/record.json'
80
+ )
81
+ .with(body: { 'app' => 4, 'id' => 1, 'record' => hash_record }.to_json)
82
+ .to_return(body: '{}', status: 200)
83
+ end
84
+
85
+ subject { target.update(app, id, record) }
86
+
87
+ let(:app) { 4 }
88
+ let(:id) { 1 }
89
+ let(:record) { hash_record }
90
+
91
+ it { expect(subject).to eq({}) }
92
+ end
93
+ end
@@ -0,0 +1,169 @@
1
+ require 'spec_helper'
2
+ require 'kintone/command/records'
3
+ require 'kintone/api'
4
+
5
+ describe Kintone::Command::Records do
6
+ let(:target) { Kintone::Command::Records.new(api) }
7
+ let(:api) { Kintone::Api.new('example.cybozu.com', 'Administrator', 'cybozu') }
8
+
9
+ describe '#get' do
10
+ subject { target.get(app, query, fields) }
11
+ let(:app) { 8 }
12
+ let(:query) { '' }
13
+ let(:fields) { [] }
14
+
15
+ context 'アプリIDだけ指定した時' do
16
+ before(:each) do
17
+ stub_request(
18
+ :get,
19
+ 'https://example.cybozu.com/k/v1/records.json?app=8&query='
20
+ )
21
+ .to_return(body: response_data.to_json, status: 200)
22
+ end
23
+
24
+ def response_data
25
+ { 'records' => [{ 'record_id' => { 'type' => 'RECORD_NUMBER', 'value' => '1' } }] }
26
+ end
27
+
28
+ it { expect(subject).to eq response_data }
29
+ end
30
+
31
+ context '条件に文字列を含むqueryを指定した時' do
32
+ before(:each) do
33
+ stub_request(
34
+ :get,
35
+ 'https://example.cybozu.com/k/v1/records.json?app=8&query=updated_time%20%3e%20%222012%2d02%2d03T09%3a00%3a00%2b0900%22%20and%20updated_time%20%3c%20%222012%2d02%2d03T10%3a00%3a00%2b0900%22'
36
+ )
37
+ .to_return(body: response_data.to_json, status: 200)
38
+ end
39
+
40
+ let(:query) { "updated_time > \"2012-02-03T09:00:00+0900\" and updated_time < \"2012-02-03T10:00:00+0900\"" } # rubocop:disable Style/LineLength
41
+
42
+ def response_data
43
+ { 'records' => [{ 'record_id' => { 'type' => 'RECORD_NUMBER', 'value' => '1' } }] }
44
+ end
45
+
46
+ it { expect(subject).to eq response_data }
47
+ end
48
+
49
+ context '項目に全角文字を含むfieldsを指定した時' do
50
+ before(:each) do
51
+ stub_request(
52
+ :get,
53
+ 'https://example.cybozu.com/k/v1/records.json?app=8&query=&fields%5b0%5d=%E3%83%AC%E3%82%B3%E3%83%BC%E3%83%89%E7%95%AA%E5%8F%B7&fields%5b1%5d=created_time&fields%5b2%5d=dropdown'
54
+ )
55
+ .to_return(body: response_data.to_json, status: 200)
56
+ end
57
+
58
+ let(:fields) { %w(レコード番号 created_time dropdown) }
59
+
60
+ def response_data
61
+ { 'records' => [{ 'record_id' => { 'type' => 'RECORD_NUMBER', 'value' => '1' } }] }
62
+ end
63
+
64
+ it { expect(subject).to eq response_data }
65
+ end
66
+
67
+ context 'queryにnilを指定した時' do
68
+ before(:each) do
69
+ stub_request(
70
+ :get,
71
+ 'https://example.cybozu.com/k/v1/records.json?'
72
+ )
73
+ .with(query: { app: 8, query: nil })
74
+ .to_return(body: response_data.to_json, status: 200)
75
+ end
76
+
77
+ let(:query) { nil }
78
+
79
+ def response_data
80
+ { 'records' => [{ 'record_id' => { 'type' => 'RECORD_NUMBER', 'value' => '1' } }] }
81
+ end
82
+
83
+ it { expect(subject).to eq response_data }
84
+ end
85
+
86
+ context 'fieldsにnilを指定した時' do
87
+ let(:fields) { nil }
88
+
89
+ it { expect { subject }.to raise_error(NoMethodError) }
90
+ end
91
+ end
92
+
93
+ describe '#create' do
94
+ subject { target.create(app, records) }
95
+
96
+ context '' do
97
+ def records_data
98
+ [
99
+ {
100
+ 'rich_editor' => { 'value' => 'testtest' }
101
+ },
102
+ {
103
+ 'user_select' => { 'value' => [{ 'code' => 'suzuki' }] }
104
+ }
105
+ ]
106
+ end
107
+
108
+ before(:each) do
109
+ stub_request(
110
+ :post,
111
+ 'https://example.cybozu.com/k/v1/records.json'
112
+ )
113
+ .with(body: { 'app' => 7, 'records' => records_data }.to_json)
114
+ .to_return(body: "{\"ids\":[\"100\", \"101\"]}", status: 200)
115
+ end
116
+
117
+ let(:app) { 7 }
118
+ let(:records) { records_data }
119
+
120
+ it { expect(subject).to eq 'ids' => %w(100 101) }
121
+ end
122
+ end
123
+
124
+ describe '#update' do
125
+ subject { target.update(app, records) }
126
+
127
+ context '' do
128
+ before(:each) do
129
+ stub_request(
130
+ :put,
131
+ 'https://example.cybozu.com/k/v1/records.json'
132
+ )
133
+ .with(body: { 'app' => 4, 'records' => records_data }.to_json)
134
+ .to_return(body: '{}', status: 200)
135
+ end
136
+
137
+ let(:app) { 4 }
138
+ let(:records) { records_data }
139
+
140
+ def records_data
141
+ [
142
+ { 'id' => 1, 'record' => { 'string_1' => { 'value' => 'abcdef' } } },
143
+ { 'id' => 2, 'record' => { 'string_multi' => { 'value' => 'opqrstu' } } }
144
+ ]
145
+ end
146
+
147
+ it { expect(subject).to eq({}) }
148
+ end
149
+ end
150
+
151
+ describe '#delete' do
152
+ subject { target.delete(app, ids) }
153
+
154
+ context '' do
155
+ before(:each) do
156
+ stub_request(
157
+ :delete,
158
+ 'https://example.cybozu.com/k/v1/records.json?app=1&ids[0]=100&ids[1]=80'
159
+ )
160
+ .to_return(body: '{}', status: 200)
161
+ end
162
+
163
+ let(:app) { 1 }
164
+ let(:ids) { [100, 80] }
165
+
166
+ it { expect(subject).to eq({}) }
167
+ end
168
+ end
169
+ end
@@ -0,0 +1,28 @@
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
+ subject { target.update(id, body) }
11
+
12
+ context '' do
13
+ before(:each) do
14
+ stub_request(
15
+ :put,
16
+ 'https://example.cybozu.com/k/v1/space/body.json'
17
+ )
18
+ .with(body: { id: 1, body: '<b>総務課</b>専用のスペースです。' }.to_json)
19
+ .to_return(body: '{}', status: 200)
20
+ end
21
+
22
+ let(:id) { 1 }
23
+ let(:body) { '<b>総務課</b>専用のスペースです。' }
24
+
25
+ it { expect(subject).to eq({}) }
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,53 @@
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
+ subject { target.get(id) }
11
+
12
+ context '' do
13
+ before(:each) do
14
+ stub_request(
15
+ :get,
16
+ 'https://example.cybozu.com/k/v1/space.json'
17
+ )
18
+ .with(query: { id: 1 })
19
+ .to_return(body: result.to_json, status: 200)
20
+ end
21
+
22
+ let(:id) { 1 }
23
+
24
+ def result
25
+ {
26
+ 'id' => '1',
27
+ 'name' => 'sample space'
28
+ }
29
+ end
30
+
31
+ it { expect(subject).to eq(result) }
32
+ end
33
+ end
34
+
35
+ describe '#delete' do
36
+ subject { target.delete(id) }
37
+
38
+ context '' do
39
+ before(:each) do
40
+ stub_request(
41
+ :delete,
42
+ 'https://example.cybozu.com/k/v1/space.json'
43
+ )
44
+ .with(query: { id: 1 })
45
+ .to_return(body: '{}', status: 200)
46
+ end
47
+
48
+ let(:id) { 1 }
49
+
50
+ it { expect(subject).to be_truthy }
51
+ end
52
+ end
53
+ end