kintone 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -4
- data/lib/kintone/api.rb +18 -15
- data/lib/kintone/api/guest.rb +33 -0
- data/lib/kintone/command/form.rb +15 -0
- data/lib/kintone/command/record.rb +5 -4
- data/lib/kintone/command/records.rb +6 -5
- data/lib/kintone/version.rb +1 -1
- data/spec/api/guest_spec.rb +18 -0
- data/spec/api_spec.rb +24 -10
- data/spec/command/form_spec.rb +25 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f270a6f3feb46411a8f630efced0f9240f6715a
|
4
|
+
data.tar.gz: 67f676a7708f96f99be690bd60d9d4e9fe211c5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f6193b7f58e9299c55fb5723fb0b519e838cc483f469b6ec7b458ea767a041d1fa8bb0471df30bfdd9a87dd411650d04847616a1f7559bf20e43ab759113d21
|
7
|
+
data.tar.gz: 889ab4189f4ced1bc9c9a873bf52a7731f0dfcfe2dead65b713b6f45d0ba1aced9dad75de38a568e150d3cfd0b0ce4aba21313b9a712232c708d589c0cbadd54
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# kintone
|
2
2
|
|
3
|
-
クラウド型データベースサービスkintone(
|
3
|
+
クラウド型データベースサービス[kintone](https://kintone.cybozu.com/)のREST APIを使用するためのgemです。
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -24,6 +24,7 @@ api = Kintone::Api.new("example.cybozu.com", "Administrator", "cybozu")
|
|
24
24
|
- レコード登録
|
25
25
|
- レコード更新
|
26
26
|
- レコード削除
|
27
|
+
- フォーム設計情報取得
|
27
28
|
|
28
29
|
### レコード取得
|
29
30
|
|
@@ -73,14 +74,24 @@ app = 8; ids = [100, 80]
|
|
73
74
|
api.records.delete(app, ids) # => {}
|
74
75
|
```
|
75
76
|
|
77
|
+
### フォーム設計情報取得
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
app = 4
|
81
|
+
api.form.get(app) # => {"properties" => [{...}, ...]}
|
82
|
+
```
|
83
|
+
|
76
84
|
### 他APIへのリクエスト
|
77
85
|
|
78
86
|
```ruby
|
79
87
|
# フォーム設計情報取得
|
80
|
-
api.
|
88
|
+
url = api.get_url("form")
|
89
|
+
api.get(url, {"app" => 4}) # => {"properties" => [{...}, ...]}
|
90
|
+
|
81
91
|
# 複数レコード登録
|
92
|
+
url = api.get_url("records")
|
82
93
|
body = {"app" => 7, "records" => [{...}, ...]}
|
83
|
-
api.post(
|
94
|
+
api.post(url, body) # => {"ids" => ["100","101"]}
|
84
95
|
```
|
85
96
|
|
86
97
|
### ゲストスペースへのAPIリクエスト
|
@@ -89,4 +100,4 @@ api.post("records.json", body) # => {"ids" => ["100","101"]}
|
|
89
100
|
api.guest(1).record.get(8, 100)
|
90
101
|
```
|
91
102
|
|
92
|
-
APIの仕様等については、cybozu.com developers(
|
103
|
+
APIの仕様等については、[cybozu.com developers](https://developers.cybozu.com/)を見てください。
|
data/lib/kintone/api.rb
CHANGED
@@ -4,14 +4,15 @@ require 'base64'
|
|
4
4
|
require 'json'
|
5
5
|
require 'kintone/command/record'
|
6
6
|
require 'kintone/command/records'
|
7
|
+
require 'kintone/command/form'
|
8
|
+
require 'kintone/api/guest'
|
7
9
|
|
8
10
|
class Kintone::Api
|
9
|
-
BASE_PATH = "/k
|
10
|
-
|
11
|
+
BASE_PATH = "/k/v1/"
|
12
|
+
COMMAND = "%s.json"
|
11
13
|
|
12
14
|
def initialize(domain, user, password)
|
13
15
|
@token = Base64.encode64("#{user}:#{password}")
|
14
|
-
@base_path = BASE_PATH % nil
|
15
16
|
@connection =
|
16
17
|
Faraday.new(:url => "https://#{domain}", :ssl => false) do |builder|
|
17
18
|
builder.adapter :net_http
|
@@ -21,14 +22,15 @@ class Kintone::Api
|
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
24
|
-
def
|
25
|
-
|
26
|
-
@base_path = BASE_PATH % space_path
|
27
|
-
return self
|
25
|
+
def get_url(command)
|
26
|
+
return BASE_PATH + (COMMAND % command)
|
28
27
|
end
|
29
28
|
|
30
|
-
def
|
31
|
-
|
29
|
+
def guest(space_id)
|
30
|
+
return Kintone::Api::Guest.new(space_id, self)
|
31
|
+
end
|
32
|
+
|
33
|
+
def get(url, params=nil)
|
32
34
|
response =
|
33
35
|
@connection.get do |request|
|
34
36
|
request.url url
|
@@ -38,8 +40,7 @@ class Kintone::Api
|
|
38
40
|
return response.body
|
39
41
|
end
|
40
42
|
|
41
|
-
def post(
|
42
|
-
url = @base_path + path
|
43
|
+
def post(url, body)
|
43
44
|
response =
|
44
45
|
@connection.post do |request|
|
45
46
|
request.url url
|
@@ -49,8 +50,7 @@ class Kintone::Api
|
|
49
50
|
return response.body
|
50
51
|
end
|
51
52
|
|
52
|
-
def put(
|
53
|
-
url = @base_path + path
|
53
|
+
def put(url, body)
|
54
54
|
response =
|
55
55
|
@connection.put do |request|
|
56
56
|
request.url url
|
@@ -60,8 +60,7 @@ class Kintone::Api
|
|
60
60
|
return response.body
|
61
61
|
end
|
62
62
|
|
63
|
-
def delete(
|
64
|
-
url = @base_path + path
|
63
|
+
def delete(url, params=nil)
|
65
64
|
response =
|
66
65
|
@connection.delete do |request|
|
67
66
|
request.url url
|
@@ -78,4 +77,8 @@ class Kintone::Api
|
|
78
77
|
def records
|
79
78
|
Kintone::Command::Records.new(self)
|
80
79
|
end
|
80
|
+
|
81
|
+
def form
|
82
|
+
Kintone::Command::Form.new(self)
|
83
|
+
end
|
81
84
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
require 'kintone/api'
|
3
|
+
|
4
|
+
class Kintone::Api
|
5
|
+
class Guest
|
6
|
+
extend Forwardable
|
7
|
+
|
8
|
+
GUEST_PATH = "/k/guest/%s/v1/"
|
9
|
+
|
10
|
+
def initialize(space_id, api)
|
11
|
+
@api = api
|
12
|
+
@guest_path = GUEST_PATH % space_id
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_url(command)
|
16
|
+
return @guest_path + (COMMAND % command)
|
17
|
+
end
|
18
|
+
|
19
|
+
def record
|
20
|
+
return Kintone::Command::Record.new(self)
|
21
|
+
end
|
22
|
+
|
23
|
+
def records
|
24
|
+
return Kintone::Command::Records.new(self)
|
25
|
+
end
|
26
|
+
|
27
|
+
def form
|
28
|
+
return Kintone::Command::Form.new(self)
|
29
|
+
end
|
30
|
+
|
31
|
+
def_delegators :@api, :get, :post, :put, :delete
|
32
|
+
end
|
33
|
+
end
|
@@ -2,21 +2,22 @@ require 'kintone/command'
|
|
2
2
|
require 'kintone/api'
|
3
3
|
|
4
4
|
class Kintone::Command::Record
|
5
|
-
PATH = "record
|
5
|
+
PATH = "record"
|
6
6
|
|
7
7
|
def initialize(api)
|
8
8
|
@api = api
|
9
|
+
@url = @api.get_url(PATH)
|
9
10
|
end
|
10
11
|
|
11
12
|
def get(app, id)
|
12
|
-
@api.get(
|
13
|
+
@api.get(@url, {:app => app, :id => id})
|
13
14
|
end
|
14
15
|
|
15
16
|
def create(app, record)
|
16
|
-
@api.post(
|
17
|
+
@api.post(@url, {:app => app, :record => record})
|
17
18
|
end
|
18
19
|
|
19
20
|
def update(app, id, record)
|
20
|
-
@api.put(
|
21
|
+
@api.put(@url, {:app => app, :id => id, :record => record})
|
21
22
|
end
|
22
23
|
end
|
@@ -2,29 +2,30 @@ require 'kintone/command'
|
|
2
2
|
require 'kintone/api'
|
3
3
|
|
4
4
|
class Kintone::Command::Records
|
5
|
-
PATH = "records
|
5
|
+
PATH = "records"
|
6
6
|
|
7
7
|
def initialize(api)
|
8
8
|
@api = api
|
9
|
+
@url = @api.get_url(PATH)
|
9
10
|
end
|
10
11
|
|
11
12
|
def get(app, query, fields)
|
12
13
|
params = {:app => app, :query => query}
|
13
14
|
fields.each_with_index {|v, i| params["fields[#{i}]"] = v}
|
14
|
-
return @api.get(
|
15
|
+
return @api.get(@url, params)
|
15
16
|
end
|
16
17
|
|
17
18
|
def create(app, records)
|
18
|
-
return @api.post(
|
19
|
+
return @api.post(@url, {:app => app, :records => records})
|
19
20
|
end
|
20
21
|
|
21
22
|
def update(app, records)
|
22
|
-
return @api.put(
|
23
|
+
return @api.put(@url, {:app => app, :records => records})
|
23
24
|
end
|
24
25
|
|
25
26
|
def delete(app, ids)
|
26
27
|
params = {:app => app}
|
27
28
|
ids.each_with_index {|v, i| params["ids[#{i}]"] = v}
|
28
|
-
return @api.delete(
|
29
|
+
return @api.delete(@url, params)
|
29
30
|
end
|
30
31
|
end
|
data/lib/kintone/version.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'kintone/api/guest'
|
3
|
+
require 'kintone/api'
|
4
|
+
|
5
|
+
describe Kintone::Api::Guest do
|
6
|
+
let(:target) { Kintone::Api::Guest.new(space, api) }
|
7
|
+
let(:space) { 1 }
|
8
|
+
let(:api) { Kintone::Api.new("example.cybozu.com", "Administrator", "cybozu") }
|
9
|
+
|
10
|
+
describe "#get_url" do
|
11
|
+
subject { target.get_url(command) }
|
12
|
+
context "" do
|
13
|
+
let(:command) { "path" }
|
14
|
+
|
15
|
+
it { expect(subject).to eq("/k/guest/1/v1/path.json") }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/spec/api_spec.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'kintone/api'
|
3
|
+
require 'kintone/api/guest'
|
3
4
|
require 'kintone/command/record'
|
4
5
|
require 'kintone/command/records'
|
5
6
|
|
@@ -9,26 +10,33 @@ describe Kintone::Api do
|
|
9
10
|
let(:user) { "Administrator" }
|
10
11
|
let(:password) { "cybozu" }
|
11
12
|
|
12
|
-
describe "
|
13
|
-
|
14
|
-
|
13
|
+
describe "#get_url" do
|
14
|
+
subject { target.get_url(command) }
|
15
|
+
|
16
|
+
context "" do
|
17
|
+
let(:command) { "path" }
|
18
|
+
it { expect(subject).to eq("/k/v1/path.json") }
|
15
19
|
end
|
20
|
+
end
|
16
21
|
|
22
|
+
describe "#guest" do
|
17
23
|
subject { target.guest(space) }
|
18
24
|
|
19
25
|
context "引数が数値の1の時" do
|
20
26
|
let(:space) { 1 }
|
21
|
-
|
27
|
+
|
28
|
+
it { expect(subject).to be_a_kind_of(Kintone::Api::Guest) }
|
29
|
+
it { expect(subject.instance_variable_get(:@guest_path)).to eq("/k/guest/1/v1/") }
|
22
30
|
end
|
23
31
|
|
24
32
|
context "引数がnilの時" do
|
25
33
|
let(:space) { nil }
|
26
|
-
|
34
|
+
xit { expect(subject.instance_variable_get(:@guest_path)).to eq("/k/guest//v1/") }
|
27
35
|
end
|
28
36
|
|
29
37
|
context "引数に数字以外の文字が含まれる時" do
|
30
38
|
let(:space) { "2.1" }
|
31
|
-
|
39
|
+
xit { expect(subject.instance_variable_get(:@guest_path)).to eq("/k/guest//v1/") }
|
32
40
|
end
|
33
41
|
end
|
34
42
|
|
@@ -43,7 +51,7 @@ describe Kintone::Api do
|
|
43
51
|
end
|
44
52
|
|
45
53
|
subject { target.get(path, params) }
|
46
|
-
let(:path) { "path" }
|
54
|
+
let(:path) { "/k/v1/path" }
|
47
55
|
let(:params) { {"p1" => "abc", "p2" => "def"} }
|
48
56
|
|
49
57
|
it { expect(subject).to eq({"abc" => "def"}) }
|
@@ -61,7 +69,7 @@ describe Kintone::Api do
|
|
61
69
|
end
|
62
70
|
|
63
71
|
subject { target.post(path, body) }
|
64
|
-
let(:path) { "path" }
|
72
|
+
let(:path) { "/k/v1/path" }
|
65
73
|
let(:body) { {"p1" => "abc", "p2" => "def"} }
|
66
74
|
|
67
75
|
it { expect(subject).to eq({"abc" => "def"}) }
|
@@ -79,7 +87,7 @@ describe Kintone::Api do
|
|
79
87
|
end
|
80
88
|
|
81
89
|
subject { target.put(path, body) }
|
82
|
-
let(:path) { "path" }
|
90
|
+
let(:path) { "/k/v1/path" }
|
83
91
|
let(:body) { {"p1" => "abc", "p2" => "def"} }
|
84
92
|
|
85
93
|
it { expect(subject).to eq({"abc" => "def"}) }
|
@@ -96,7 +104,7 @@ describe Kintone::Api do
|
|
96
104
|
end
|
97
105
|
|
98
106
|
subject { target.delete(path, params) }
|
99
|
-
let(:path) { "path" }
|
107
|
+
let(:path) { "/k/v1/path" }
|
100
108
|
let(:params) { {"p1" => "abc", "p2" => "def"} }
|
101
109
|
|
102
110
|
it { expect(subject).to eq({"abc" => "def"}) }
|
@@ -113,4 +121,10 @@ describe Kintone::Api do
|
|
113
121
|
|
114
122
|
it { expect(subject).to be_a_kind_of(Kintone::Command::Records) }
|
115
123
|
end
|
124
|
+
|
125
|
+
describe "#form" do
|
126
|
+
subject { target.form }
|
127
|
+
|
128
|
+
it { expect(subject).to be_a_kind_of(Kintone::Command::Form) }
|
129
|
+
end
|
116
130
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'kintone/command/form'
|
2
|
+
require 'kintone/api'
|
3
|
+
|
4
|
+
describe Kintone::Command::Form do
|
5
|
+
let(:target) { Kintone::Command::Form.new(api) }
|
6
|
+
let(:api) { Kintone::Api.new("example.cybozu.com", "Administrator", "cybozu") }
|
7
|
+
|
8
|
+
describe "#get" do
|
9
|
+
subject { target.get(app) }
|
10
|
+
|
11
|
+
context "" do
|
12
|
+
before(:each) do
|
13
|
+
stub_request(
|
14
|
+
:get,
|
15
|
+
"https://example.cybozu.com/k/v1/form.json?app=4"
|
16
|
+
).
|
17
|
+
to_return(:body => "{\"result\":\"ok\"}", :status => 200)
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:app) { 4 }
|
21
|
+
|
22
|
+
it { expect(subject).to eq({"result" => "ok"})}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kintone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rikiya Kawakami
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -110,11 +110,15 @@ files:
|
|
110
110
|
- kintone.gemspec
|
111
111
|
- lib/kintone.rb
|
112
112
|
- lib/kintone/api.rb
|
113
|
+
- lib/kintone/api/guest.rb
|
113
114
|
- lib/kintone/command.rb
|
115
|
+
- lib/kintone/command/form.rb
|
114
116
|
- lib/kintone/command/record.rb
|
115
117
|
- lib/kintone/command/records.rb
|
116
118
|
- lib/kintone/version.rb
|
119
|
+
- spec/api/guest_spec.rb
|
117
120
|
- spec/api_spec.rb
|
121
|
+
- spec/command/form_spec.rb
|
118
122
|
- spec/command/record_spec.rb
|
119
123
|
- spec/command/records_spec.rb
|
120
124
|
- spec/spec_helper.rb
|
@@ -143,7 +147,9 @@ signing_key:
|
|
143
147
|
specification_version: 4
|
144
148
|
summary: kintone API client for Ruby.
|
145
149
|
test_files:
|
150
|
+
- spec/api/guest_spec.rb
|
146
151
|
- spec/api_spec.rb
|
152
|
+
- spec/command/form_spec.rb
|
147
153
|
- spec/command/record_spec.rb
|
148
154
|
- spec/command/records_spec.rb
|
149
155
|
- spec/spec_helper.rb
|