kintone 0.0.5 → 0.1.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.
- checksums.yaml +4 -4
- data/.rubocop.yml +10 -0
- data/.travis.yml +2 -1
- data/README.md +166 -6
- data/kintone.gemspec +4 -2
- data/lib/kintone.rb +1 -0
- data/lib/kintone/api.rb +30 -3
- data/lib/kintone/api/guest.rb +17 -0
- data/lib/kintone/command/apis.rb +22 -0
- data/lib/kintone/command/app.rb +11 -0
- data/lib/kintone/command/guests.rb +15 -0
- data/lib/kintone/command/record.rb +6 -2
- data/lib/kintone/command/records.rb +9 -5
- data/lib/kintone/command/space_guests.rb +11 -0
- data/lib/kintone/command/space_members.rb +16 -0
- data/lib/kintone/command/space_thread.rb +14 -0
- data/lib/kintone/query.rb +146 -0
- data/lib/kintone/query/extension.rb +23 -0
- data/lib/kintone/type.rb +6 -0
- data/lib/kintone/type/extension/enumerable.rb +5 -0
- data/lib/kintone/type/extension/hash.rb +5 -0
- data/lib/kintone/type/extension/object.rb +5 -0
- data/lib/kintone/type/record.rb +11 -0
- data/lib/kintone/version.rb +1 -1
- data/spec/kintone/api/guest_spec.rb +41 -2
- data/spec/kintone/api_spec.rb +83 -20
- data/spec/kintone/command/apis_spec.rb +113 -0
- data/spec/kintone/command/app_spec.rb +33 -0
- data/spec/kintone/command/guests_spec.rb +65 -0
- data/spec/kintone/command/record_spec.rb +55 -37
- data/spec/kintone/command/records_spec.rb +50 -18
- data/spec/kintone/command/space_guests_spec.rb +34 -0
- data/spec/kintone/command/space_members_spec.rb +80 -0
- data/spec/kintone/command/space_spec.rb +1 -1
- data/spec/kintone/command/space_thread_spec.rb +52 -0
- data/spec/kintone/query_spec.rb +294 -0
- data/spec/kintone/type/record_spec.rb +38 -0
- data/spec/spec_helper.rb +1 -0
- metadata +67 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a164c300acd21a0f68fd1c1bd5c44ec1bafe48f7
|
4
|
+
data.tar.gz: 6bea016672ebf7fc90e4f488f47a81f576b1cab4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d6fbb16fb2f20c48b1b0e726794991ea487f24f98134844fa54f6c24ac1ece0a415494633814b454be19bb50fd2d9705ca9669da4637686e4323c63bb4f15a1
|
7
|
+
data.tar.gz: 0a65774ec1a15d1efa4729cd5178445e7a52bcc2d2d4aeaeeb015a315c8d0237bcf2f17a460064722c17bd65d88daa11d7606390345a00e8105f3ecfed550f0a
|
data/.rubocop.yml
CHANGED
@@ -24,3 +24,13 @@ Style/LineLength:
|
|
24
24
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
25
25
|
Style/StringLiterals:
|
26
26
|
EnforcedStyle: single_quotes
|
27
|
+
|
28
|
+
Style/WordArray:
|
29
|
+
Exclude:
|
30
|
+
- 'spec/**/**'
|
31
|
+
|
32
|
+
Style/AsciiComments:
|
33
|
+
Enabled: false
|
34
|
+
|
35
|
+
CyclomaticComplexity:
|
36
|
+
Max: 10
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
A Ruby gem for communicating with the [kintone](https://kintone.cybozu.com/us/) REST API
|
4
4
|
|
5
|
+
## Requirements
|
6
|
+
|
7
|
+
- ruby 2.1.0 or later
|
8
|
+
|
5
9
|
## Installation
|
6
10
|
|
7
11
|
gem install kintone
|
@@ -24,7 +28,10 @@ api = Kintone::Api.new("example.cybozu.com", "Administrator", "cybozu")
|
|
24
28
|
- [Record delete](#record_delete)
|
25
29
|
- [Format retrieval](#format_retrieval)
|
26
30
|
- [Permissions](#permissions)
|
27
|
-
- [Space management](
|
31
|
+
- [Space management](#space_management)
|
32
|
+
- [Guests](#guests)
|
33
|
+
- [Application information](#application_information)
|
34
|
+
- [API information](#api_information)
|
28
35
|
|
29
36
|
### <a name="record_retrieval"> Record retrieval
|
30
37
|
|
@@ -39,31 +46,139 @@ query = "updated_time > \"2012-02-03T09:00:00+0900\" and updated_time < \"2012-0
|
|
39
46
|
api.records.get(app, query, fields) # => {"records" => [{...}, ...]}
|
40
47
|
```
|
41
48
|
|
49
|
+
Query helper
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
query =
|
53
|
+
Kintone::Query.new do
|
54
|
+
field(:updated_time) > "2012-02-03T09:00:00+0900"
|
55
|
+
and!
|
56
|
+
field(:updated_time) < "2012-02-03T10:00:00+0900"
|
57
|
+
order_by(:record_id)
|
58
|
+
limit(10)
|
59
|
+
offset(20)
|
60
|
+
end
|
61
|
+
query.to_s # => "updated_time > \"2012-02-03T09:00:00+0900\" and updated_time < \"2012-02-03T10:00:00+0900\" order by record_id asc limit 10 offset 20"
|
62
|
+
api.records.get(app, query, fields)
|
63
|
+
|
64
|
+
# Example
|
65
|
+
Kintone::Query.new do
|
66
|
+
field(:Created_datetime) >= last_month
|
67
|
+
and!
|
68
|
+
precede do
|
69
|
+
field(:text).like("Hello")
|
70
|
+
and!
|
71
|
+
field(:number) == 200
|
72
|
+
end
|
73
|
+
or!
|
74
|
+
precede do
|
75
|
+
field(:number) > 100
|
76
|
+
and!
|
77
|
+
field(:Created_by).in([login_user])
|
78
|
+
end
|
79
|
+
order_by(:record_id, :desc)
|
80
|
+
limit(10)
|
81
|
+
offset(20)
|
82
|
+
end
|
83
|
+
# => "Created_datetime >= LAST_MONTH() and (text like \"Hello\" and number = 200) or (number > 100 and Created_by in (LOGINUSER())) order by record_id desc limit 10 offset 20"
|
84
|
+
```
|
85
|
+
|
86
|
+
operator symbol | query helper
|
87
|
+
--- | ---
|
88
|
+
= | field(:code) == other
|
89
|
+
!= | field(:code) != other
|
90
|
+
> | field(:code) > other
|
91
|
+
< | field(:code) < other
|
92
|
+
>= | field(:code) >= other
|
93
|
+
<= | field(:code) <= other
|
94
|
+
in | field(:code).in(["A", "B"])
|
95
|
+
not in | field(:code).not_in(["A", "B"])
|
96
|
+
like | field(:code).like("Hello")
|
97
|
+
not like | field(:code).not_like("Hello")
|
98
|
+
and | and!
|
99
|
+
or | or!
|
100
|
+
() | precede do; end
|
101
|
+
|
102
|
+
function | query helper
|
103
|
+
--- | ---
|
104
|
+
LOGINUSER() | login_user
|
105
|
+
NOW() | now
|
106
|
+
TODAY() | today
|
107
|
+
THIS_MONTH() | this_month
|
108
|
+
LAST_MONTH() | last_month
|
109
|
+
THIS_YEAR() | this_year
|
110
|
+
|
111
|
+
option | query helper
|
112
|
+
--- | ---
|
113
|
+
order by | order_by(:code, :asc or :desc)
|
114
|
+
limit | limit(20)
|
115
|
+
offset | offset(30)
|
116
|
+
|
42
117
|
### <a name="record_register"> Record register
|
43
118
|
|
44
119
|
```ruby
|
45
120
|
# Record register(single record)
|
121
|
+
# Use Hash
|
46
122
|
app = 7
|
47
123
|
record = {"number" => {"value" => "123456"}}
|
48
|
-
api.record.
|
124
|
+
api.record.register(app, record) # => {"id" => "100"}
|
125
|
+
|
126
|
+
# Use Kintone::Type::Record
|
127
|
+
app = 7
|
128
|
+
record = Kintone::Type::Record.new(number: "123456")
|
129
|
+
api.record.register(app, record) # => {"id" => "100"}
|
49
130
|
|
50
131
|
# Records register(batch)
|
132
|
+
# Use Hash
|
51
133
|
app = 7
|
52
|
-
records = [
|
53
|
-
|
134
|
+
records = [
|
135
|
+
{"number" => {"value" => "123456"}},
|
136
|
+
{"number" => {"value" => "7890"}}
|
137
|
+
]
|
138
|
+
api.records.register(app, records) # => {"ids" => ["100", "101"]}
|
139
|
+
|
140
|
+
# Use Kintone::Type::Record
|
141
|
+
app = 7
|
142
|
+
records = [
|
143
|
+
Kintone::Type::Record.new(number: "123456"),
|
144
|
+
Kintone::Type::Record.new(number: "7890")
|
145
|
+
]
|
146
|
+
api.records.register(app, records) # => {"ids" => ["100", "101"]}
|
147
|
+
|
148
|
+
# Deprecated
|
149
|
+
api.record.create(app, record)
|
150
|
+
api.records.create(app, records)
|
54
151
|
```
|
55
152
|
|
56
153
|
### <a name="record_update"> Record update
|
57
154
|
|
58
155
|
```ruby
|
59
156
|
# Record update(single record)
|
157
|
+
# Use Hash
|
60
158
|
app = 4; id = 1
|
61
159
|
record = {"string_multi" => {"value" => "changed!"}}
|
62
160
|
api.record.update(app, id, record) # => {}
|
63
161
|
|
162
|
+
# Use Kintone::Type::Record
|
163
|
+
app = 4; id = 1
|
164
|
+
record = Kintone::Type::Record.new({string_multi: "changed!"})
|
165
|
+
api.record.update(app, id, record) # => {}
|
166
|
+
|
64
167
|
# Records update(batch)
|
168
|
+
# Use Hash
|
65
169
|
app = 4
|
66
|
-
records = [
|
170
|
+
records = [
|
171
|
+
{"id" => 1, "record" => {"string_multi" => {"value" => "abcdef"}}},
|
172
|
+
{"id" => 2, "record" => {"string_multi" => {"value" => "opqrstu"}}}
|
173
|
+
]
|
174
|
+
api.records.update(app, records) # => {}
|
175
|
+
|
176
|
+
# Use Kintone::Type::Record
|
177
|
+
app = 4
|
178
|
+
records = [
|
179
|
+
{id: 1, record: Kintone::Type::Record.new(string_multi: "abcdef")},
|
180
|
+
{id: 2, record: Kintone::Type::Record.new(string_multi: "opqrstu")}
|
181
|
+
]
|
67
182
|
api.records.update(app, records) # => {}
|
68
183
|
```
|
69
184
|
|
@@ -103,7 +218,7 @@ api.field_acl.update(id, rights) # => {}
|
|
103
218
|
### <a name="space_management"> Space management
|
104
219
|
|
105
220
|
```ruby
|
106
|
-
# Space information
|
221
|
+
# Space information
|
107
222
|
id = 1
|
108
223
|
api.space.get(id) # => { "id" => "1", "name" => "space", "defaultThread" => "3", "isPrivate" => true, ...}
|
109
224
|
|
@@ -116,11 +231,56 @@ api.template_space.create(id, name, members, is_guest: true, fixed_member: false
|
|
116
231
|
id = 1; body = "<b>awesome space!</b>"
|
117
232
|
api.space_body.update(id, body) # => {}
|
118
233
|
|
234
|
+
# Space members
|
235
|
+
id = 1
|
236
|
+
members = api.space_members.get(id) # => {"members"=>[{"entity"=>{"type"=>"USER", "code"=> "user1"}, ...}, ...]}
|
237
|
+
members << {"entity" => {"type" => "GROUP", "code" => "group1"}}
|
238
|
+
members = api.space_members.update(id, members) # => {}
|
239
|
+
|
240
|
+
# Space thread update
|
241
|
+
id = 1; name = "thread name"
|
242
|
+
body = "<b>awesome thread!</b>"
|
243
|
+
api.space_thread.update(id, name: name, body: body) # => {}
|
244
|
+
|
245
|
+
# Space guests
|
246
|
+
id = 1
|
247
|
+
guests = ["hoge@example.com"]
|
248
|
+
api.guest(1).space_guests.update(id, guests) # => {}
|
249
|
+
|
119
250
|
# Space delete
|
120
251
|
id = 1
|
121
252
|
api.space.delete(id) # => {}
|
122
253
|
```
|
123
254
|
|
255
|
+
### <a name="guests"> Guests
|
256
|
+
|
257
|
+
```ruby
|
258
|
+
# Add guest
|
259
|
+
guests = [{code: "hoge@example.com", password: "p@ssword", timezone: "Asia/Tokyo", name: "Tokyo, Saburo", ...}, ...]
|
260
|
+
api.guests.create(guests) # => {}
|
261
|
+
|
262
|
+
# delete guest
|
263
|
+
guests = ["hoge@example.com", "fuga@example.com"]
|
264
|
+
api.guests.delete(guests) # => {}
|
265
|
+
```
|
266
|
+
|
267
|
+
### <a name="application_information"> Application information
|
268
|
+
|
269
|
+
```ruby
|
270
|
+
id = 4
|
271
|
+
api.app.get(id) # => {"appId" => "4", "code" => "", ...}
|
272
|
+
```
|
273
|
+
|
274
|
+
### <a name="api_information"> API information
|
275
|
+
|
276
|
+
```ruby
|
277
|
+
api.apis.get # => {"baseUrl" => "https://example.cybozu.com/k/v1/", "apis" => {"records/get" => {"link" => "apis/records/get.json"}}}
|
278
|
+
|
279
|
+
api.apis.get_details_of("apis/records/get.json") # => {"id" => "GetRecords", "baseUrl" => "https://example.cybozu.com/k/v1/", ...}
|
280
|
+
|
281
|
+
api.apis.get_details_of_key("records/get") # => {"id" => "GetRecords", "baseUrl" => "https://example.cybozu.com/k/v1/", ...}
|
282
|
+
```
|
283
|
+
|
124
284
|
### Other examples
|
125
285
|
|
126
286
|
```ruby
|
data/kintone.gemspec
CHANGED
@@ -24,8 +24,10 @@ Gem::Specification.new do |spec|
|
|
24
24
|
|
25
25
|
spec.add_development_dependency 'bundler', '~> 1.5'
|
26
26
|
spec.add_development_dependency 'rake'
|
27
|
-
spec.add_development_dependency 'rspec'
|
28
|
-
spec.add_development_dependency '
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.0.0'
|
28
|
+
spec.add_development_dependency 'rubocop', '~> 0.24.1'
|
29
|
+
spec.add_development_dependency 'webmock', '~> 1.18'
|
29
30
|
spec.add_development_dependency 'guard-rspec'
|
30
31
|
spec.add_development_dependency 'guard-rubocop'
|
32
|
+
spec.add_development_dependency 'rspec-parameterized', '~> 0.1.2'
|
31
33
|
end
|
data/lib/kintone.rb
CHANGED
data/lib/kintone/api.rb
CHANGED
@@ -11,7 +11,13 @@ require 'kintone/command/field_acl'
|
|
11
11
|
require 'kintone/command/template_space'
|
12
12
|
require 'kintone/command/space'
|
13
13
|
require 'kintone/command/space_body'
|
14
|
+
require 'kintone/command/space_thread'
|
15
|
+
require 'kintone/command/space_members'
|
16
|
+
require 'kintone/command/guests'
|
17
|
+
require 'kintone/command/app'
|
18
|
+
require 'kintone/command/apis'
|
14
19
|
require 'kintone/api/guest'
|
20
|
+
require 'kintone/query'
|
15
21
|
|
16
22
|
class Kintone::Api
|
17
23
|
BASE_PATH = '/k/v1/'
|
@@ -37,7 +43,7 @@ class Kintone::Api
|
|
37
43
|
Kintone::Api::Guest.new(space_id, self)
|
38
44
|
end
|
39
45
|
|
40
|
-
def get(url, params =
|
46
|
+
def get(url, params = {})
|
41
47
|
response =
|
42
48
|
@connection.get do |request|
|
43
49
|
request.url url
|
@@ -66,11 +72,12 @@ class Kintone::Api
|
|
66
72
|
response.body
|
67
73
|
end
|
68
74
|
|
69
|
-
def delete(url,
|
75
|
+
def delete(url, body = nil)
|
70
76
|
response =
|
71
77
|
@connection.delete do |request|
|
72
78
|
request.url url
|
73
|
-
request.
|
79
|
+
request.headers['Content-Type'] = 'application/json'
|
80
|
+
request.body = body.to_json
|
74
81
|
end
|
75
82
|
response.body
|
76
83
|
end
|
@@ -110,4 +117,24 @@ class Kintone::Api
|
|
110
117
|
def space_body
|
111
118
|
Kintone::Command::SpaceBody.new(self)
|
112
119
|
end
|
120
|
+
|
121
|
+
def space_thread
|
122
|
+
Kintone::Command::SpaceThread.new(self)
|
123
|
+
end
|
124
|
+
|
125
|
+
def space_members
|
126
|
+
Kintone::Command::SpaceMembers.new(self)
|
127
|
+
end
|
128
|
+
|
129
|
+
def guests
|
130
|
+
Kintone::Command::Guests.new(self)
|
131
|
+
end
|
132
|
+
|
133
|
+
def app
|
134
|
+
Kintone::Command::App.new(self)
|
135
|
+
end
|
136
|
+
|
137
|
+
def apis
|
138
|
+
Kintone::Command::Apis.new(self)
|
139
|
+
end
|
113
140
|
end
|
data/lib/kintone/api/guest.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'forwardable'
|
2
2
|
require 'kintone/api'
|
3
|
+
require 'kintone/command/space_guests'
|
3
4
|
|
4
5
|
class Kintone::Api
|
5
6
|
class Guest
|
@@ -48,6 +49,22 @@ class Kintone::Api
|
|
48
49
|
Kintone::Command::SpaceBody.new(self)
|
49
50
|
end
|
50
51
|
|
52
|
+
def space_thread
|
53
|
+
Kintone::Command::SpaceThread.new(self)
|
54
|
+
end
|
55
|
+
|
56
|
+
def space_members
|
57
|
+
Kintone::Command::SpaceMembers.new(self)
|
58
|
+
end
|
59
|
+
|
60
|
+
def space_guests
|
61
|
+
Kintone::Command::SpaceGuests.new(self)
|
62
|
+
end
|
63
|
+
|
64
|
+
def app
|
65
|
+
Kintone::Command::App.new(self)
|
66
|
+
end
|
67
|
+
|
51
68
|
def_delegators :@api, :get, :post, :put, :delete
|
52
69
|
end
|
53
70
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'kintone/command'
|
2
|
+
|
3
|
+
class Kintone::Command::Apis < Kintone::Command
|
4
|
+
def self.path
|
5
|
+
'apis'
|
6
|
+
end
|
7
|
+
|
8
|
+
def get
|
9
|
+
@api.get(@url)
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_details_of(link)
|
13
|
+
url = Kintone::Api::BASE_PATH + link
|
14
|
+
@api.get(url)
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_details_of_key(key)
|
18
|
+
response = get
|
19
|
+
link = response['apis'][key]['link']
|
20
|
+
get_details_of(link)
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'kintone/command'
|
2
|
+
|
3
|
+
class Kintone::Command::Guests < Kintone::Command
|
4
|
+
def self.path
|
5
|
+
'guests'
|
6
|
+
end
|
7
|
+
|
8
|
+
def create(guests)
|
9
|
+
@api.post(@url, guests: guests)
|
10
|
+
end
|
11
|
+
|
12
|
+
def delete(guests)
|
13
|
+
@api.delete(@url, guests: guests)
|
14
|
+
end
|
15
|
+
end
|
@@ -9,11 +9,15 @@ class Kintone::Command::Record < Kintone::Command
|
|
9
9
|
@api.get(@url, app: app, id: id)
|
10
10
|
end
|
11
11
|
|
12
|
+
def register(app, record)
|
13
|
+
@api.post(@url, app: app, record: record.to_kintone)
|
14
|
+
end
|
15
|
+
|
12
16
|
def create(app, record)
|
13
|
-
|
17
|
+
register(app, record)
|
14
18
|
end
|
15
19
|
|
16
20
|
def update(app, id, record)
|
17
|
-
@api.put(@url, app: app, id: id, record: record)
|
21
|
+
@api.put(@url, app: app, id: id, record: record.to_kintone)
|
18
22
|
end
|
19
23
|
end
|