kintone 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ea0ac21ce99dbd0d7a7721f75a6ab200186aeabd
4
+ data.tar.gz: a52bb9292342a21c5d67821cfb2aa5fc05ecda82
5
+ SHA512:
6
+ metadata.gz: c549d6b8129703ef3b38879675e95e92a6dbbf01f3edbcc55dcdb4d7e89757c5f0295fa7937583a69b279f9d5faf386fc34db49f0136569bd7fc4d99ddfb7d06
7
+ data.tar.gz: dc38ec2c27cf9b0025e89628044ef7b173675dd2250122efde24b557bacf8314012825961e54eb3709906484dcedd5ec26a84049eaac410d796709ba887707db
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ vendor/
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ -c -f doc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kintone.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Rikiya Kawakami
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # Kintone
2
+
3
+ クラウド型データベースサービスKintone( https://kintone.cybozu.com/ )のREST APIを使用するためのgemです。
4
+
5
+ ## Installation
6
+
7
+ gem install kintone
8
+
9
+ 又は、Gemfileに
10
+
11
+ gem 'kintone'
12
+
13
+ と書いて、`bundle install` コマンドを実行してください。
14
+
15
+ ## Usage
16
+
17
+ require 'kintone'
18
+
19
+ ### レコード1件の取得/登録/更新
20
+
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
+ ### 他APIへのリクエスト
30
+
31
+ # フォーム設計情報取得
32
+ api.get("form.json", {"app" => 4}) # => {"properties" => [{...}, ...]}
33
+ # 複数レコード登録
34
+ body = {"app" => 7, "records" => [{...}, ...]}
35
+ api.post("records.json", body) # => {"ids" => ["100","101"]}
36
+
37
+ ### ゲストスペースへのAPIリクエスト
38
+
39
+ api = Kintone::Api.new("example.cybozu.com", "Administrator", "cybozu")
40
+ api.guest(1).record.get(8, 100)
41
+
42
+ APIの仕様等については、cybozu.com developers( https://developers.cybozu.com/ )を見てください。
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/kintone.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kintone/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "kintone"
8
+ spec.version = Kintone::VERSION
9
+ spec.authors = ["Rikiya Kawakami"]
10
+ spec.email = ["ricky.k.yang@gmail.com"]
11
+ spec.summary = %q{Kintone API client.}
12
+ spec.description = %q{Kintone API client.}
13
+ spec.homepage = "https://github.com/jue58/kintone"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency 'faraday', '~>0.8.9'
22
+ spec.add_runtime_dependency 'faraday_middleware', '~>0.9.0'
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.5"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "webmock"
28
+ end
data/lib/kintone.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "kintone/version"
2
+ require "kintone/api"
3
+
4
+ module Kintone
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,76 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+ require 'base64'
4
+ require 'json'
5
+ require 'kintone/command/record'
6
+
7
+ class Kintone::Api
8
+ BASE_PATH = "/k%s/v1/"
9
+ SPACE_PATH = "/guest/%s"
10
+
11
+ def initialize(domain, user, password)
12
+ @token = Base64.encode64("#{user}:#{password}")
13
+ @base_path = BASE_PATH % nil
14
+ @connection =
15
+ Faraday.new(:url => "https://#{domain}", :ssl => false) do |builder|
16
+ builder.adapter :net_http
17
+ builder.request :url_encoded
18
+ builder.response :json
19
+ builder.response :logger
20
+ end
21
+ end
22
+
23
+ def guest(space)
24
+ space_path = SPACE_PATH % space if space.to_s.match(/^[1-9][0-9]*$/)
25
+ @base_path = BASE_PATH % space_path
26
+ return self
27
+ end
28
+
29
+ def get(path, params=nil)
30
+ url = @base_path + path
31
+ response =
32
+ @connection.get do |request|
33
+ request.url url
34
+ request.params = params
35
+ request.headers = {"X-Cybozu-Authorization" => @token}
36
+ end
37
+ return response.body
38
+ end
39
+
40
+ def post(path, body)
41
+ url = @base_path + path
42
+ response =
43
+ @connection.post do |request|
44
+ request.url url
45
+ request.headers = {"X-Cybozu-Authorization" => @token, "Content-Type" => "application/json"}
46
+ request.body = body.to_json
47
+ end
48
+ return response.body
49
+ end
50
+
51
+ def put(path, body)
52
+ url = @base_path + path
53
+ response =
54
+ @connection.put do |request|
55
+ request.url url
56
+ request.headers = {"X-Cybozu-Authorization" => @token, "Content-Type" => "application/json"}
57
+ request.body = body.to_json
58
+ end
59
+ return response.body
60
+ end
61
+
62
+ def delete(path, params=nil)
63
+ url = @base_path + path
64
+ response =
65
+ @connection.delete do |request|
66
+ request.url url
67
+ request.params = params
68
+ request.headers = {"X-Cybozu-Authorization" => @token}
69
+ end
70
+ return response.body
71
+ end
72
+
73
+ def record
74
+ Kintone::Command::Record.new(self)
75
+ end
76
+ end
@@ -0,0 +1,23 @@
1
+ require 'kintone/api'
2
+
3
+ module Kintone::Command
4
+ class Record
5
+ PATH = "record.json"
6
+
7
+ def initialize(api)
8
+ @api = api
9
+ end
10
+
11
+ def get(app, id)
12
+ @api.get(PATH, {:app => app, :id => id})
13
+ end
14
+
15
+ def create(app, record)
16
+ @api.post(PATH, {:app => app, :record => record})
17
+ end
18
+
19
+ def update(app, id, record)
20
+ @api.put(PATH, {:app => app, :id => id, :record => record})
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module Kintone
2
+ VERSION = "0.0.1"
3
+ end
data/spec/api_spec.rb ADDED
@@ -0,0 +1,102 @@
1
+ require 'spec_helper'
2
+ require 'kintone/api'
3
+
4
+ describe Kintone::Api do
5
+ let(:target) { Kintone::Api.new(domain, user, password) }
6
+ let(:domain) { "www.example.com" }
7
+ let(:user) { "Administrator" }
8
+ let(:password) { "cybozu" }
9
+
10
+ describe "guest" do
11
+ before(:each) do
12
+ subject
13
+ end
14
+
15
+ subject { target.guest(space) }
16
+
17
+ context "引数が数値の1の時" do
18
+ let(:space) { 1 }
19
+ it { expect(target.instance_variable_get(:@base_path)).to eq("/k/guest/1/v1/") }
20
+ end
21
+
22
+ context "引数がnilの時" do
23
+ let(:space) { nil }
24
+ it { expect(target.instance_variable_get(:@base_path)).to eq("/k/v1/") }
25
+ end
26
+
27
+ context "引数に数字以外の文字が含まれる時" do
28
+ let(:space) { "2.1" }
29
+ it { expect(target.instance_variable_get(:@base_path)).to eq("/k/v1/") }
30
+ end
31
+ end
32
+
33
+ describe "#get" do
34
+ before(:each) do
35
+ stub_request(
36
+ :get,
37
+ "https://www.example.com/k/v1/path?p1=abc&p2=def"
38
+ ).
39
+ with(:headers => {"X-Cybozu-Authorization" => "QWRtaW5pc3RyYXRvcjpjeWJvenU="}).
40
+ to_return(:body => "{\"abc\":\"def\"}", :status => 200)
41
+ end
42
+
43
+ subject { target.get(path, params) }
44
+ let(:path) { "path" }
45
+ let(:params) { {"p1" => "abc", "p2" => "def"} }
46
+
47
+ it { expect(subject).to eq({"abc" => "def"}) }
48
+ end
49
+
50
+ describe "#post" do
51
+ before(:each) do
52
+ stub_request(
53
+ :post,
54
+ "https://www.example.com/k/v1/path"
55
+ ).
56
+ with(:headers => {"X-Cybozu-Authorization" => "QWRtaW5pc3RyYXRvcjpjeWJvenU=", "Content-Type" => "application/json"},
57
+ :body => "{\"p1\":\"abc\",\"p2\":\"def\"}").
58
+ to_return(:body => "{\"abc\":\"def\"}", :status => 200)
59
+ end
60
+
61
+ subject { target.post(path, body) }
62
+ let(:path) { "path" }
63
+ let(:body) { {"p1" => "abc", "p2" => "def"} }
64
+
65
+ it { expect(subject).to eq({"abc" => "def"}) }
66
+ end
67
+
68
+ describe "#put" do
69
+ before(:each) do
70
+ stub_request(
71
+ :put,
72
+ "https://www.example.com/k/v1/path"
73
+ ).
74
+ with(:headers => {"X-Cybozu-Authorization" => "QWRtaW5pc3RyYXRvcjpjeWJvenU=", "Content-Type" => "application/json"},
75
+ :body => "{\"p1\":\"abc\",\"p2\":\"def\"}").
76
+ to_return(:body => "{\"abc\":\"def\"}", :status => 200)
77
+ end
78
+
79
+ subject { target.put(path, body) }
80
+ let(:path) { "path" }
81
+ let(:body) { {"p1" => "abc", "p2" => "def"} }
82
+
83
+ it { expect(subject).to eq({"abc" => "def"}) }
84
+ end
85
+
86
+ describe "#delete" do
87
+ before(:each) do
88
+ stub_request(
89
+ :delete,
90
+ "https://www.example.com/k/v1/path?p1=abc&p2=def"
91
+ ).
92
+ with(:headers => {"X-Cybozu-Authorization" => "QWRtaW5pc3RyYXRvcjpjeWJvenU="}).
93
+ to_return(:body => "{\"abc\":\"def\"}", :status => 200)
94
+ end
95
+
96
+ subject { target.delete(path, params) }
97
+ let(:path) { "path" }
98
+ let(:params) { {"p1" => "abc", "p2" => "def"} }
99
+
100
+ it { expect(subject).to eq({"abc" => "def"}) }
101
+ end
102
+ end
@@ -0,0 +1,92 @@
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
+ def hash_record
45
+ return {
46
+ "number" => {"value" => "123456"},
47
+ "rich_editor" => {"value" => "testtest"},
48
+ "user_select" => {"value" => [{"code" => "sato"}]}
49
+ }
50
+ end
51
+ before(:each) do
52
+ stub_request(
53
+ :post,
54
+ "https://www.example.com/k/v1/record.json"
55
+ ).
56
+ with(:body => {"app" => 7, "record" => hash_record}.to_json).
57
+ to_return(:body => "{\"id\":\"100\"}", :status => 200)
58
+ end
59
+
60
+ subject { target.create(app, record) }
61
+
62
+ let(:app) { 7 }
63
+ let(:record) { hash_record }
64
+
65
+ it { expect(subject).to eq({"id" => "100"}) }
66
+ end
67
+
68
+ describe "#update" do
69
+ def hash_record
70
+ return {
71
+ "string_multi" => {"value" => "character string is changed"}
72
+ }
73
+ end
74
+
75
+ before(:each) do
76
+ stub_request(
77
+ :put,
78
+ "https://www.example.com/k/v1/record.json"
79
+ ).
80
+ with(:body => {"app" => 4, "id" => 1, "record" => hash_record}.to_json).
81
+ to_return(:body => "{}", :status => 200)
82
+ end
83
+
84
+ subject { target.update(app, id, record) }
85
+
86
+ let(:app) { 4 }
87
+ let(:id) { 1 }
88
+ let(:record) { hash_record }
89
+
90
+ it { expect(subject).to eq({}) }
91
+ end
92
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'kintone'
3
+ require 'webmock/rspec'
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kintone
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Rikiya Kawakami
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.8.9
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.9
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 0.9.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Kintone API client.
98
+ email:
99
+ - ricky.k.yang@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - .rspec
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - kintone.gemspec
111
+ - lib/kintone.rb
112
+ - lib/kintone/api.rb
113
+ - lib/kintone/command/record.rb
114
+ - lib/kintone/version.rb
115
+ - spec/api_spec.rb
116
+ - spec/command/record_spec.rb
117
+ - spec/spec_helper.rb
118
+ homepage: https://github.com/jue58/kintone
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - '>='
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.0.3
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Kintone API client.
142
+ test_files:
143
+ - spec/api_spec.rb
144
+ - spec/command/record_spec.rb
145
+ - spec/spec_helper.rb
146
+ has_rdoc: