kintone 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ea0ac21ce99dbd0d7a7721f75a6ab200186aeabd
4
- data.tar.gz: a52bb9292342a21c5d67821cfb2aa5fc05ecda82
3
+ metadata.gz: 548e13d447b105ddea94cd11ffc2ca2b882d1a89
4
+ data.tar.gz: 8c7940cdf780cdc5980e9920326a7307d820976e
5
5
  SHA512:
6
- metadata.gz: c549d6b8129703ef3b38879675e95e92a6dbbf01f3edbcc55dcdb4d7e89757c5f0295fa7937583a69b279f9d5faf386fc34db49f0136569bd7fc4d99ddfb7d06
7
- data.tar.gz: dc38ec2c27cf9b0025e89628044ef7b173675dd2250122efde24b557bacf8314012825961e54eb3709906484dcedd5ec26a84049eaac410d796709ba887707db
6
+ metadata.gz: 9f28461efc3dbe61367ee5f178e9585eda7d450c6e56fda8b523b7c3802dbd09d2871d2e34985a6c4d305f956fa6866a48e026f2496b817f4f4a6ed04fd74920
7
+ data.tar.gz: 2fbf9eb1eb0c53e0247567cf72ccb5355a4f17a4b4b0ba8b3d47dd39b883d971ca2d73656685ca09fbcab1f8ef133c90e360c2de6d985354c5c77aff9c0306a9
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Kintone
1
+ # kintone
2
2
 
3
- クラウド型データベースサービスKintone( https://kintone.cybozu.com/ )のREST APIを使用するためのgemです。
3
+ クラウド型データベースサービスkintone( https://kintone.cybozu.com/ )のREST APIを使用するためのgemです。
4
4
 
5
5
  ## Installation
6
6
 
@@ -14,29 +14,79 @@
14
14
 
15
15
  ## Usage
16
16
 
17
- require 'kintone'
17
+ ```ruby
18
+ require 'kintone'
19
+ api = Kintone::Api.new("example.cybozu.com", "Administrator", "cybozu")
20
+ ```
18
21
 
19
- ### レコード1件の取得/登録/更新
22
+ ### 対応API
23
+ - レコード取得
24
+ - レコード登録
25
+ - レコード更新
26
+ - レコード削除
20
27
 
21
- api = Kintone::Api.new("example.cybozu.com", "Administrator", "cybozu")
22
- # レコード取得
23
- api.record.get(8, 100) # get(アプリID, レコード番号)
24
- # レコード登録
25
- api.record.create(7, {"number" => {"value" => "123456"}}) # create(アプリID, レコードデータ)
26
- # レコード更新
27
- api.record.update(4, 1, {"string_multi" => {"value" => "changed!"}}) # update(アプリID, レコード番号, レコードデータ)
28
+ ### レコード取得
29
+
30
+ ```ruby
31
+ # レコード取得(レコード番号指定)
32
+ app = 8; id = 100
33
+ api.record.get(app, id) # => {"record" => {"record_id" => {"type" => "RECORD_NUMBER", "value" => "1"}}}
34
+
35
+ # レコード取得(クエリで取得)
36
+ app = 8; fields = ["record_id", "created_time", "dropdown"]
37
+ query = "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"
38
+ api.records.get(app, query, fields) # => {"records" => [{...}, ...]}
39
+ ```
40
+
41
+ ### レコード登録
42
+
43
+ ```ruby
44
+ # レコード登録(1件)
45
+ app = 7
46
+ record = {"number" => {"value" => "123456"}}
47
+ api.record.create(app, record) # => {"id" => "100"}
48
+
49
+ # レコード登録(複数件)
50
+ app = 7
51
+ records = [{"number" => {"value" => "123456"}}, {"number" => {"value" => "7890"}}]
52
+ api.records.create(app, records) # => {"ids" => ["100", "101"]}
53
+ ```
54
+
55
+ ### レコード更新
56
+
57
+ ```ruby
58
+ # レコード更新(1件)
59
+ app = 4; id = 1
60
+ record = {"string_multi" => {"value" => "changed!"}}
61
+ api.record.update(app, id, record) # => {}
62
+
63
+ # レコード更新(複数件)
64
+ app = 4
65
+ records = [{"id" => 1, "string_multi" => {"value" => "abcdef"}}, {"id" => 2, "string_multi" => {"value" => "opqrstu"}}]
66
+ api.records.update(app, records) # => {}
67
+ ```
68
+
69
+ ### レコード削除
70
+
71
+ ```ruby
72
+ app = 8; ids = [100, 80]
73
+ api.records.delete(app, ids) # => {}
74
+ ```
28
75
 
29
76
  ### 他APIへのリクエスト
30
77
 
31
- # フォーム設計情報取得
32
- api.get("form.json", {"app" => 4}) # => {"properties" => [{...}, ...]}
33
- # 複数レコード登録
34
- body = {"app" => 7, "records" => [{...}, ...]}
35
- api.post("records.json", body) # => {"ids" => ["100","101"]}
78
+ ```ruby
79
+ # フォーム設計情報取得
80
+ api.get("form.json", {"app" => 4}) # => {"properties" => [{...}, ...]}
81
+ # 複数レコード登録
82
+ body = {"app" => 7, "records" => [{...}, ...]}
83
+ api.post("records.json", body) # => {"ids" => ["100","101"]}
84
+ ```
36
85
 
37
86
  ### ゲストスペースへのAPIリクエスト
38
87
 
39
- api = Kintone::Api.new("example.cybozu.com", "Administrator", "cybozu")
40
- api.guest(1).record.get(8, 100)
88
+ ```ruby
89
+ api.guest(1).record.get(8, 100)
90
+ ```
41
91
 
42
92
  APIの仕様等については、cybozu.com developers( https://developers.cybozu.com/ )を見てください。
data/kintone.gemspec CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Kintone::VERSION
9
9
  spec.authors = ["Rikiya Kawakami"]
10
10
  spec.email = ["ricky.k.yang@gmail.com"]
11
- spec.summary = %q{Kintone API client.}
12
- spec.description = %q{Kintone API client.}
11
+ spec.summary = %q{kintone API client for Ruby.}
12
+ spec.description = %q{kintone API client for Ruby.}
13
13
  spec.homepage = "https://github.com/jue58/kintone"
14
14
  spec.license = "MIT"
15
15
 
data/lib/kintone/api.rb CHANGED
@@ -3,6 +3,7 @@ require 'faraday_middleware'
3
3
  require 'base64'
4
4
  require 'json'
5
5
  require 'kintone/command/record'
6
+ require 'kintone/command/records'
6
7
 
7
8
  class Kintone::Api
8
9
  BASE_PATH = "/k%s/v1/"
@@ -73,4 +74,8 @@ class Kintone::Api
73
74
  def record
74
75
  Kintone::Command::Record.new(self)
75
76
  end
77
+
78
+ def records
79
+ Kintone::Command::Records.new(self)
80
+ end
76
81
  end
@@ -0,0 +1,3 @@
1
+ module Kintone::Command
2
+
3
+ end
@@ -1,23 +1,22 @@
1
+ require 'kintone/command'
1
2
  require 'kintone/api'
2
3
 
3
- module Kintone::Command
4
- class Record
5
- PATH = "record.json"
4
+ class Kintone::Command::Record
5
+ PATH = "record.json"
6
6
 
7
- def initialize(api)
8
- @api = api
9
- end
7
+ def initialize(api)
8
+ @api = api
9
+ end
10
10
 
11
- def get(app, id)
12
- @api.get(PATH, {:app => app, :id => id})
13
- end
11
+ def get(app, id)
12
+ @api.get(PATH, {:app => app, :id => id})
13
+ end
14
14
 
15
- def create(app, record)
16
- @api.post(PATH, {:app => app, :record => record})
17
- end
15
+ def create(app, record)
16
+ @api.post(PATH, {:app => app, :record => record})
17
+ end
18
18
 
19
- def update(app, id, record)
20
- @api.put(PATH, {:app => app, :id => id, :record => record})
21
- end
19
+ def update(app, id, record)
20
+ @api.put(PATH, {:app => app, :id => id, :record => record})
22
21
  end
23
22
  end
@@ -0,0 +1,30 @@
1
+ require 'kintone/command'
2
+ require 'kintone/api'
3
+
4
+ class Kintone::Command::Records
5
+ PATH = "records.json"
6
+
7
+ def initialize(api)
8
+ @api = api
9
+ end
10
+
11
+ def get(app, query, fields)
12
+ params = {:app => app, :query => query}
13
+ fields.each_with_index {|v, i| params["fields[#{i}]"] = v}
14
+ return @api.get(PATH, params)
15
+ end
16
+
17
+ def create(app, records)
18
+ return @api.post(PATH, {:app => app, :records => records})
19
+ end
20
+
21
+ def update(app, records)
22
+ return @api.put(PATH, {:app => app, :records => records})
23
+ end
24
+
25
+ def delete(app, ids)
26
+ params = {:app => app}
27
+ ids.each_with_index {|v, i| params["ids[#{i}]"] = v}
28
+ return @api.delete(PATH, params)
29
+ end
30
+ end
@@ -1,3 +1,3 @@
1
1
  module Kintone
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/spec/api_spec.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'kintone/api'
3
+ require 'kintone/command/record'
4
+ require 'kintone/command/records'
3
5
 
4
6
  describe Kintone::Api do
5
7
  let(:target) { Kintone::Api.new(domain, user, password) }
@@ -99,4 +101,16 @@ describe Kintone::Api do
99
101
 
100
102
  it { expect(subject).to eq({"abc" => "def"}) }
101
103
  end
104
+
105
+ describe "#record" do
106
+ subject { target.record }
107
+
108
+ it { expect(subject).to be_a_kind_of(Kintone::Command::Record) }
109
+ end
110
+
111
+ describe "#records" do
112
+ subject { target.records }
113
+
114
+ it { expect(subject).to be_a_kind_of(Kintone::Command::Records) }
115
+ end
102
116
  end
@@ -0,0 +1,162 @@
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 => "{\"records\":[{\"record_id\": {\"type\":\"RECORD_NUMBER\",\"value\":\"1\"}}]}", :status => 200)
22
+ end
23
+
24
+ it { expect(subject).to eq({"records" => [{"record_id" => {"type" => "RECORD_NUMBER", "value" => "1"}}]}) }
25
+ end
26
+
27
+ context "条件に文字列を含むqueryを指定した時" do
28
+ before(:each) do
29
+ stub_request(
30
+ :get,
31
+ "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"
32
+ ).
33
+ to_return(:body => "{\"records\":[{\"record_id\": {\"type\":\"RECORD_NUMBER\",\"value\":\"1\"}}]}", :status => 200)
34
+ end
35
+
36
+ let(:query) { "updated_time > \"2012-02-03T09:00:00+0900\" and updated_time < \"2012-02-03T10:00:00+0900\"" }
37
+
38
+ it { expect(subject).to eq({"records" => [{"record_id" => {"type" => "RECORD_NUMBER", "value" => "1"}}]}) }
39
+ end
40
+
41
+ context "項目に全角文字を含むfieldsを指定した時" do
42
+ before(:each) do
43
+ stub_request(
44
+ :get,
45
+ "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"
46
+ ).
47
+ to_return(:body => "{\"records\":[{\"record_id\": {\"type\":\"RECORD_NUMBER\",\"value\":\"1\"}}]}", :status => 200)
48
+ end
49
+
50
+ let(:fields) { ["レコード番号", "created_time", "dropdown"] }
51
+
52
+ it { expect(subject).to eq({"records" => [{"record_id" => {"type" => "RECORD_NUMBER", "value" => "1"}}]}) }
53
+ end
54
+
55
+ context "queryにnilを指定した時" do
56
+ before(:each) do
57
+ stub_request(
58
+ :get,
59
+ "https://example.cybozu.com/k/v1/records.json?app=8&query"
60
+ ).
61
+ to_return(:body => "{\"records\":[{\"record_id\": {\"type\":\"RECORD_NUMBER\",\"value\":\"1\"}}]}", :status => 200)
62
+ end
63
+
64
+ let(:query) { nil }
65
+
66
+ it { expect(subject).to eq({"records" => [{"record_id" => {"type" => "RECORD_NUMBER", "value" => "1"}}]}) }
67
+ end
68
+
69
+ context "fieldsにnilを指定した時" do
70
+ let(:fields) { nil }
71
+
72
+ it { expect{ subject }.to raise_error(NoMethodError)}
73
+ end
74
+ end
75
+
76
+ describe "#create" do
77
+ subject { target.create(app, records) }
78
+
79
+ context "" do
80
+ def records_data
81
+ return [
82
+ {
83
+ "rich_editor" => {"value" => "testtest"}
84
+ },
85
+ {
86
+ "user_select" => {"value" => [{"code"=> "suzuki"}]}
87
+ }
88
+ ]
89
+ end
90
+
91
+ before(:each) do
92
+ stub_request(
93
+ :post,
94
+ "https://example.cybozu.com/k/v1/records.json"
95
+ ).
96
+ with(:body => {"app" => 7, "records" => records_data}.to_json).
97
+ to_return(:body => "{\"ids\":[\"100\", \"101\"]}", :status => 200)
98
+ end
99
+
100
+ let(:app) { 7 }
101
+ let(:records) { records_data }
102
+
103
+ it { expect(subject).to eq({"ids" => ["100", "101"]}) }
104
+ end
105
+ end
106
+
107
+ describe "#update" do
108
+ subject { target.update(app, records) }
109
+
110
+ context "" do
111
+ def records_data
112
+ return [
113
+ {
114
+ "id" => 1,
115
+ "record" => {
116
+ "string_1" => {"value" => "abcdef"}
117
+ }
118
+ },
119
+ {
120
+ "id" => 2,
121
+ "record" => {
122
+ "string_multi" => {"value" => "opqrstu"}
123
+ }
124
+ }
125
+ ]
126
+ end
127
+
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
+ it { expect(subject).to eq({}) }
141
+ end
142
+ end
143
+
144
+ describe "#delete" do
145
+ subject { target.delete(app, ids) }
146
+
147
+ context "" do
148
+ before(:each) do
149
+ stub_request(
150
+ :delete,
151
+ "https://example.cybozu.com/k/v1/records.json?app=1&ids[0]=100&ids[1]=80"
152
+ ).
153
+ to_return(:body => "{}", :status => 200)
154
+ end
155
+
156
+ let(:app) { 1 }
157
+ let(:ids) { [100, 80] }
158
+
159
+ it { expect(subject).to eq({}) }
160
+ end
161
+ end
162
+ 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.1
4
+ version: 0.0.2
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-06 00:00:00.000000000 Z
11
+ date: 2014-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -94,7 +94,7 @@ dependencies:
94
94
  - - '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
- description: Kintone API client.
97
+ description: kintone API client for Ruby.
98
98
  email:
99
99
  - ricky.k.yang@gmail.com
100
100
  executables: []
@@ -110,10 +110,13 @@ files:
110
110
  - kintone.gemspec
111
111
  - lib/kintone.rb
112
112
  - lib/kintone/api.rb
113
+ - lib/kintone/command.rb
113
114
  - lib/kintone/command/record.rb
115
+ - lib/kintone/command/records.rb
114
116
  - lib/kintone/version.rb
115
117
  - spec/api_spec.rb
116
118
  - spec/command/record_spec.rb
119
+ - spec/command/records_spec.rb
117
120
  - spec/spec_helper.rb
118
121
  homepage: https://github.com/jue58/kintone
119
122
  licenses:
@@ -138,9 +141,10 @@ rubyforge_project:
138
141
  rubygems_version: 2.0.3
139
142
  signing_key:
140
143
  specification_version: 4
141
- summary: Kintone API client.
144
+ summary: kintone API client for Ruby.
142
145
  test_files:
143
146
  - spec/api_spec.rb
144
147
  - spec/command/record_spec.rb
148
+ - spec/command/records_spec.rb
145
149
  - spec/spec_helper.rb
146
150
  has_rdoc: