kintone 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +10 -0
  3. data/.travis.yml +2 -1
  4. data/README.md +166 -6
  5. data/kintone.gemspec +4 -2
  6. data/lib/kintone.rb +1 -0
  7. data/lib/kintone/api.rb +30 -3
  8. data/lib/kintone/api/guest.rb +17 -0
  9. data/lib/kintone/command/apis.rb +22 -0
  10. data/lib/kintone/command/app.rb +11 -0
  11. data/lib/kintone/command/guests.rb +15 -0
  12. data/lib/kintone/command/record.rb +6 -2
  13. data/lib/kintone/command/records.rb +9 -5
  14. data/lib/kintone/command/space_guests.rb +11 -0
  15. data/lib/kintone/command/space_members.rb +16 -0
  16. data/lib/kintone/command/space_thread.rb +14 -0
  17. data/lib/kintone/query.rb +146 -0
  18. data/lib/kintone/query/extension.rb +23 -0
  19. data/lib/kintone/type.rb +6 -0
  20. data/lib/kintone/type/extension/enumerable.rb +5 -0
  21. data/lib/kintone/type/extension/hash.rb +5 -0
  22. data/lib/kintone/type/extension/object.rb +5 -0
  23. data/lib/kintone/type/record.rb +11 -0
  24. data/lib/kintone/version.rb +1 -1
  25. data/spec/kintone/api/guest_spec.rb +41 -2
  26. data/spec/kintone/api_spec.rb +83 -20
  27. data/spec/kintone/command/apis_spec.rb +113 -0
  28. data/spec/kintone/command/app_spec.rb +33 -0
  29. data/spec/kintone/command/guests_spec.rb +65 -0
  30. data/spec/kintone/command/record_spec.rb +55 -37
  31. data/spec/kintone/command/records_spec.rb +50 -18
  32. data/spec/kintone/command/space_guests_spec.rb +34 -0
  33. data/spec/kintone/command/space_members_spec.rb +80 -0
  34. data/spec/kintone/command/space_spec.rb +1 -1
  35. data/spec/kintone/command/space_thread_spec.rb +52 -0
  36. data/spec/kintone/query_spec.rb +294 -0
  37. data/spec/kintone/type/record_spec.rb +38 -0
  38. data/spec/spec_helper.rb +1 -0
  39. metadata +67 -10
@@ -0,0 +1,113 @@
1
+ require 'spec_helper'
2
+ require 'kintone/command/apis'
3
+
4
+ describe Kintone::Command::Apis do
5
+ let(:target) { Kintone::Command::Apis.new(api) }
6
+ let(:api) { Kintone::Api.new('example.cybozu.com', 'Administrator', 'cybozu') }
7
+
8
+ describe '#get' do
9
+ before(:each) do
10
+ stub_request(
11
+ :get,
12
+ 'https://example.cybozu.com/k/v1/apis.json'
13
+ )
14
+ .to_return(body: response_data.to_json, status: 200)
15
+ end
16
+
17
+ subject { target.get }
18
+
19
+ def response_data
20
+ {
21
+ 'baseUrl' => 'https://example.cybozu.com/k/v1/',
22
+ 'apis' => {
23
+ 'records/get' => {
24
+ 'link' => 'apis/records/get.json'
25
+ }
26
+ }
27
+ }
28
+ end
29
+
30
+ it { is_expected.to eq(response_data) }
31
+ end
32
+
33
+ describe '#get_details_of' do
34
+ before(:each) do
35
+ stub_request(
36
+ :get,
37
+ 'https://example.cybozu.com/k/v1/apis/records/get.json'
38
+ )
39
+ .to_return(body: response_data.to_json, status: 200)
40
+ end
41
+
42
+ subject { target.get_details_of(link) }
43
+
44
+ let(:link) { 'apis/records/get.json' }
45
+
46
+ def response_data
47
+ {
48
+ 'id' => 'GetRecords',
49
+ 'baseUrl' => 'https://example.cybozu.com/k/v1/',
50
+ 'path' => 'records.json',
51
+ 'httpMethod' => 'GET'
52
+ }
53
+ end
54
+
55
+ it { is_expected.to eq(response_data) }
56
+ end
57
+
58
+ describe '#get_details_of_key' do
59
+ before(:each) do
60
+ stub_request(
61
+ :get,
62
+ 'https://example.cybozu.com/k/v1/apis.json'
63
+ )
64
+ .to_return(body: apis_response_data.to_json, status: 200)
65
+
66
+ stub_request(
67
+ :get,
68
+ 'https://example.cybozu.com/k/v1/apis/records/get.json'
69
+ )
70
+ .to_return(body: api_response_data.to_json, status: 200)
71
+ end
72
+
73
+ subject { target.get_details_of_key(key) }
74
+
75
+ def apis_response_data
76
+ {
77
+ 'baseUrl' => 'https://example.cybozu.com/k/v1/',
78
+ 'apis' => {
79
+ 'records/get' => {
80
+ 'link' => 'apis/records/get.json'
81
+ }
82
+ }
83
+ }
84
+ end
85
+
86
+ def api_response_data
87
+ {
88
+ 'id' => 'GetRecords',
89
+ 'baseUrl' => 'https://example.cybozu.com/k/v1/',
90
+ 'path' => 'records.json',
91
+ 'httpMethod' => 'GET'
92
+ }
93
+ end
94
+
95
+ context 'with key that exists' do
96
+ let(:key) { 'records/get' }
97
+
98
+ it { is_expected.to eq(api_response_data) }
99
+ end
100
+
101
+ context 'with key that does not exists' do
102
+ let(:key) { 'records/hoge' }
103
+
104
+ it { expect { subject }.to raise_error NoMethodError }
105
+ end
106
+
107
+ context 'with nil' do
108
+ let(:key) { nil }
109
+
110
+ it { expect { subject }.to raise_error NoMethodError }
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+ require 'kintone/command/app'
3
+
4
+ describe Kintone::Command::App do
5
+ let(:target) { Kintone::Command::App.new(api) }
6
+ let(:api) { Kintone::Api.new('example.cybozu.com', 'Administrator', 'cybozu') }
7
+
8
+ describe '#get' do
9
+ before(:each) do
10
+ stub_request(
11
+ :get,
12
+ 'https://example.cybozu.com/k/v1/app.json'
13
+ )
14
+ .with(query: { id: id })
15
+ .to_return(body: response_data.to_json, status: 200)
16
+ end
17
+
18
+ subject { target.get(id) }
19
+
20
+ let(:id) { 4 }
21
+
22
+ def response_data
23
+ {
24
+ appId: '4',
25
+ code: '',
26
+ name: 'アプリ',
27
+ description: 'よいアプリです'
28
+ }
29
+ end
30
+
31
+ it { is_expected.to be_kind_of(Hash) }
32
+ end
33
+ end
@@ -0,0 +1,65 @@
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 '#create' 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(body: '{}', status: 200)
17
+ end
18
+
19
+ subject { target.create(guests) }
20
+
21
+ let(:guests) do
22
+ [
23
+ {
24
+ code: 'hoge@example.com',
25
+ password: 'password',
26
+ timezone: 'Asia/Tokyo',
27
+ locale: 'ja',
28
+ image: '78a586f2-e73e-4a70-bec2-43976a60746e',
29
+ name: '東京 三郎',
30
+ surNameReading: 'とうきょう',
31
+ givenNameReading: 'さぶろう',
32
+ company: 'サイボウズ株式会社',
33
+ division: '営業部',
34
+ phone: '999-456-7890',
35
+ callto: 'tokyo3rou'
36
+ }
37
+ ]
38
+ end
39
+
40
+ it { is_expected.to be_truthy }
41
+ end
42
+
43
+ describe '#delete' do
44
+ before(:each) do
45
+ stub_request(
46
+ :delete,
47
+ 'https://example.cybozu.com/k/v1/guests.json'
48
+ )
49
+ .with(body: { guests: guests }.to_json)
50
+ .to_return(body: '{}', status: 200)
51
+ end
52
+
53
+ subject { target.delete(guests) }
54
+
55
+ let(:guests) do
56
+ [
57
+ 'guest1@example.com',
58
+ 'guest2@example.com',
59
+ 'guest3@example.com'
60
+ ]
61
+ end
62
+
63
+ it { is_expected.to be_truthy }
64
+ end
65
+ end
@@ -1,46 +1,36 @@
1
1
  require 'spec_helper'
2
2
  require 'kintone/command/record'
3
3
  require 'kintone/api'
4
+ require 'kintone/type/record'
4
5
 
5
6
  describe Kintone::Command::Record do
6
7
  let(:target) { Kintone::Command::Record.new(api) }
7
8
  let(:api) { Kintone::Api.new('www.example.com', 'Administrator', 'cybozu') }
8
9
 
9
10
  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' }
11
+ before(:each) do
12
+ stub_request(
13
+ :get,
14
+ 'https://www.example.com/k/v1/record.json?app=8&id=100'
15
+ )
16
+ .to_return(body: "{\"result\":\"ok\"}", status: 200)
25
17
  end
26
18
 
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
19
+ subject { target.get(app, id) }
35
20
 
36
- let(:app) { '8' }
37
- let(:id) { '100' }
21
+ where(:app, :id) do
22
+ [
23
+ [8, 100],
24
+ ['8', '100']
25
+ ]
26
+ end
38
27
 
28
+ with_them do
39
29
  it { expect(subject).to eq 'result' => 'ok' }
40
30
  end
41
31
  end
42
32
 
43
- describe '#create' do
33
+ describe '#register' do
44
34
  before(:each) do
45
35
  stub_request(
46
36
  :post,
@@ -50,10 +40,9 @@ describe Kintone::Command::Record do
50
40
  .to_return(body: "{\"id\":\"100\"}", status: 200)
51
41
  end
52
42
 
53
- subject { target.create(app, record) }
43
+ subject { target.register(app, record) }
54
44
 
55
45
  let(:app) { 7 }
56
- let(:record) { hash_record }
57
46
 
58
47
  def hash_record
59
48
  {
@@ -63,16 +52,27 @@ describe Kintone::Command::Record do
63
52
  }
64
53
  end
65
54
 
66
- it { expect(subject).to eq 'id' => '100' }
67
- end
55
+ def record_record
56
+ Kintone::Type::Record.new(
57
+ number: '123456',
58
+ rich_editor: 'testtest',
59
+ user_select: [{ 'code' => 'sato' }]
60
+ )
61
+ end
68
62
 
69
- describe '#update' do
70
- def hash_record
71
- {
72
- 'string_multi' => { 'value' => 'character string is changed' }
73
- }
63
+ where(:record, :result) do
64
+ [
65
+ [hash_record, { 'id' => '100' }],
66
+ [record_record, { 'id' => '100' }]
67
+ ]
68
+ end
69
+
70
+ with_them do
71
+ it { expect(subject).to eq result }
74
72
  end
73
+ end
75
74
 
75
+ describe '#update' do
76
76
  before(:each) do
77
77
  stub_request(
78
78
  :put,
@@ -86,8 +86,26 @@ describe Kintone::Command::Record do
86
86
 
87
87
  let(:app) { 4 }
88
88
  let(:id) { 1 }
89
- let(:record) { hash_record }
90
89
 
91
- it { expect(subject).to eq({}) }
90
+ def hash_record
91
+ {
92
+ 'string_multi' => { 'value' => 'character string is changed' }
93
+ }
94
+ end
95
+
96
+ def record_record
97
+ Kintone::Type::Record.new(string_multi: 'character string is changed')
98
+ end
99
+
100
+ where(:record, :result) do
101
+ [
102
+ [hash_record, {}],
103
+ [record_record, {}]
104
+ ]
105
+ end
106
+
107
+ with_them do
108
+ it { expect(subject).to match result }
109
+ end
92
110
  end
93
111
  end
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'kintone/command/records'
3
3
  require 'kintone/api'
4
+ require 'kintone/type'
4
5
 
5
6
  describe Kintone::Command::Records do
6
7
  let(:target) { Kintone::Command::Records.new(api) }
@@ -90,11 +91,22 @@ describe Kintone::Command::Records do
90
91
  end
91
92
  end
92
93
 
93
- describe '#create' do
94
- subject { target.create(app, records) }
94
+ describe '#register' do
95
+ subject { target.register(app, records) }
95
96
 
96
97
  context '' do
97
- def records_data
98
+ before(:each) do
99
+ stub_request(
100
+ :post,
101
+ 'https://example.cybozu.com/k/v1/records.json'
102
+ )
103
+ .with(body: { 'app' => 7, 'records' => hash_data }.to_json)
104
+ .to_return(body: "{\"ids\":[\"100\", \"101\"]}", status: 200)
105
+ end
106
+
107
+ let(:app) { 7 }
108
+
109
+ def hash_data
98
110
  [
99
111
  {
100
112
  'rich_editor' => { 'value' => 'testtest' }
@@ -105,19 +117,23 @@ describe Kintone::Command::Records do
105
117
  ]
106
118
  end
107
119
 
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)
120
+ def record_data
121
+ [
122
+ Kintone::Type::Record.new(rich_editor: 'testtest'),
123
+ Kintone::Type::Record.new(user_select: [{ code: 'suzuki' }])
124
+ ]
115
125
  end
116
126
 
117
- let(:app) { 7 }
118
- let(:records) { records_data }
127
+ where(:records, :result) do
128
+ [
129
+ [hash_data, { 'ids' => %w(100 101) }],
130
+ [record_data, { 'ids' => %w(100 101) }]
131
+ ]
132
+ end
119
133
 
120
- it { expect(subject).to eq 'ids' => %w(100 101) }
134
+ with_them do
135
+ it { expect(subject).to eq result }
136
+ end
121
137
  end
122
138
  end
123
139
 
@@ -130,21 +146,36 @@ describe Kintone::Command::Records do
130
146
  :put,
131
147
  'https://example.cybozu.com/k/v1/records.json'
132
148
  )
133
- .with(body: { 'app' => 4, 'records' => records_data }.to_json)
149
+ .with(body: { 'app' => 4, 'records' => hash_data }.to_json)
134
150
  .to_return(body: '{}', status: 200)
135
151
  end
136
152
 
137
153
  let(:app) { 4 }
138
- let(:records) { records_data }
139
154
 
140
- def records_data
155
+ def hash_data
141
156
  [
142
157
  { 'id' => 1, 'record' => { 'string_1' => { 'value' => 'abcdef' } } },
143
158
  { 'id' => 2, 'record' => { 'string_multi' => { 'value' => 'opqrstu' } } }
144
159
  ]
145
160
  end
146
161
 
147
- it { expect(subject).to eq({}) }
162
+ def record_data
163
+ [
164
+ { id: 1, record: Kintone::Type::Record.new(string_1: 'abcdef') },
165
+ { id: 2, record: Kintone::Type::Record.new(string_multi: 'opqrstu') }
166
+ ]
167
+ end
168
+
169
+ where(:records, :result) do
170
+ [
171
+ [hash_data, {}],
172
+ [record_data, {}]
173
+ ]
174
+ end
175
+
176
+ with_them do
177
+ it { expect(subject).to eq result }
178
+ end
148
179
  end
149
180
  end
150
181
 
@@ -155,8 +186,9 @@ describe Kintone::Command::Records do
155
186
  before(:each) do
156
187
  stub_request(
157
188
  :delete,
158
- 'https://example.cybozu.com/k/v1/records.json?app=1&ids[0]=100&ids[1]=80'
189
+ 'https://example.cybozu.com/k/v1/records.json'
159
190
  )
191
+ .with(body: { app: app, ids: ids }.to_json)
160
192
  .to_return(body: '{}', status: 200)
161
193
  end
162
194