kintone-client 0.1.0

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: 8cca615744dca51c5e2047bb6c049616a651a4f9
4
+ data.tar.gz: 5d40ca03305fd56927ae382eef8e94c843b2bb2d
5
+ SHA512:
6
+ metadata.gz: 18fe3edccc7c7d7bbc595d7ff874ba6a4785fb837a56ed22818c128c2ad104e6a9478f4a6700b3def71f5a6617b88a364930e5368847dfec158300ee1a6618a9
7
+ data.tar.gz: a56c3f09d11d2b007606acd0f1229e6509a37ab5530eba43dc77716d5f09da80b2bd737c4736b8d3176f445c734d96df72dc119446d80ac7d3ab3518e0e358f5
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ test.rb
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kintone-client.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Genki Sugawara
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,38 @@
1
+ # Kintone::Client
2
+
3
+ It is a simple client of [cybozu kintone](https://kintone.cybozu.com).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'kintone-client'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install kintone-client
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require 'kintone/client'
25
+
26
+ client = Kintone::Client.new(subdomein: "max6j", login_name: "Genki Sugawara", password: "...")
27
+
28
+ # https://cybozudev.zendesk.com/hc/ja/articles/202931674-%E3%82%A2%E3%83%97%E3%83%AA%E6%83%85%E5%A0%B1%E3%81%AE%E5%8F%96%E5%BE%97
29
+ p client.app.get(id: 211)
30
+ p client.records.get(app: 211)
31
+
32
+ # https://cybozudev.zendesk.com/hc/ja/articles/202166220-%E3%82%B9%E3%83%9A%E3%83%BC%E3%82%B9%E3%81%AE%E3%83%A1%E3%83%B3%E3%83%90%E3%83%BC%E3%81%AE%E5%8F%96%E5%BE%97
33
+ p client.space.members.get(id: 4)
34
+ ```
35
+
36
+ ## kintone API
37
+
38
+ * https://cybozudev.zendesk.com/hc/ja/categories/200147600-kintone-API
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new('spec')
5
+ task :default => :spec
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kintone/client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'kintone-client'
8
+ spec.version = Kintone::Client::VERSION
9
+ spec.authors = ['Genki Sugawara']
10
+ spec.email = ['sugawara@cookpad.com']
11
+ spec.summary = %q{It is a simple client of cybozu kintone.}
12
+ spec.description = %q{It is a simple client of cybozu kintone.}
13
+ spec.homepage = ''
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_dependency 'faraday', '>= 0.8'
22
+ spec.add_dependency 'faraday_middleware'
23
+ spec.add_development_dependency 'bundler'
24
+ spec.add_development_dependency 'rake'
25
+ spec.add_development_dependency 'rspec', '>= 3.0.0'
26
+ spec.add_development_dependency 'http-dump'
27
+ end
@@ -0,0 +1,130 @@
1
+ class Kintone::Client
2
+ ENDPOINT = 'https://%s.cybozu.com'
3
+
4
+ def initialize(options)
5
+ @auth = {}
6
+
7
+ [:login_name, :password, :api_token].each do |k|
8
+ @auth[k] = options.delete(k)
9
+ end
10
+
11
+ options[:url] ||= ENDPOINT % options.delete(:subdomein)
12
+
13
+ @conn = Faraday.new(options) do |faraday|
14
+ faraday.request :url_encoded
15
+ faraday.response :form, :content_type => /\bjson$/ # must set before :json
16
+ faraday.response :json, :content_type => /\bjson$/
17
+
18
+ yield(faraday) if block_given?
19
+
20
+ required_adapters = [Faraday::Adapter::NetHttp, Faraday::Adapter::Test]
21
+
22
+ unless required_adapters.any? {|i| faraday.builder.handlers.include?(i) }
23
+ faraday.adapter Faraday.default_adapter
24
+ end
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def method_missing(method_name, *args)
31
+ unless args.length.zero?
32
+ raise ArgumentError, "wrong number of arguments (#{args.length} for 0)"
33
+ end
34
+
35
+ Path.new(@conn, @auth, method_name.to_s)
36
+ end
37
+
38
+ class Path
39
+ BASE_PATH = '/k/v1'
40
+
41
+ def initialize(conn, auth, path)
42
+ @conn = conn
43
+ @auth = auth
44
+ @path = path
45
+ end
46
+
47
+ private
48
+
49
+ def request(method_name, params)
50
+ response = @conn.send(method_name) do |req|
51
+ req.url BASE_PATH + '/' + @path + '.json'
52
+ req.params = expand_params_array(params || {})
53
+ authorize(req)
54
+ yield(req) if block_given?
55
+ end
56
+
57
+ body = response.body
58
+
59
+ if response.status != 200
60
+ raise body.kind_of?(Hash) ? Kintone::Error.new(body) : body.inspect
61
+ end
62
+
63
+ body
64
+ end
65
+
66
+ def expand_params_array(params)
67
+ params.keys.each do |key|
68
+ value = params[key]
69
+
70
+ if can_be_expanded?(value)
71
+ params.delete(key)
72
+
73
+ value.each_with_index do |v, i|
74
+ params["#{key}[#{i}]"] = v
75
+ end
76
+ else
77
+ params[key] = expand_params_array0(value)
78
+ end
79
+ end
80
+
81
+ params
82
+ end
83
+
84
+ def expand_params_array0(value)
85
+ case value
86
+ when Array
87
+ value.map {|v| expand_params_array0(v) }
88
+ when Hash
89
+ expand_params_array(value)
90
+ else
91
+ value
92
+ end
93
+ end
94
+
95
+ def can_be_expanded?(value)
96
+ value.kind_of?(Array) &&
97
+ value.all? {|v| not v.kind_of?(Array) and not v.kind_of?(Hash) }
98
+ end
99
+
100
+ def authorize(req)
101
+ if @auth[:api_token]
102
+ req.headers['X-Cybozu-API-Token'] = Base64.strict_encode64(@auth[:api_token])
103
+ elsif @auth[:login_name] and @auth[:password]
104
+ req.headers['X-Cybozu-Authorization'] = Base64.strict_encode64(
105
+ @auth[:login_name] + ':' + @auth[:password])
106
+ else
107
+ raise 'no auth parameter (:api_token or :login_name,:password)'
108
+ end
109
+ end
110
+
111
+ def method_missing(method_name, *args, &block)
112
+ if [:get, :post, :put, :delete].include?(method_name)
113
+ case args.length
114
+ when 0
115
+ args = nil
116
+ when 1
117
+ args = args.first
118
+ end
119
+
120
+ request(method_name, args, &block)
121
+ else
122
+ unless args.length.zero?
123
+ raise ArgumentError, "wrong number of arguments (#{args.length} for 0)"
124
+ end
125
+
126
+ self.class.new(@conn, @auth, @path + '/' + method_name.to_s)
127
+ end
128
+ end
129
+ end # class Path
130
+ end # class Kintone::Client
@@ -0,0 +1,8 @@
1
+ class Kintone::Error < StandardError
2
+ attr_reader :response
3
+
4
+ def initialize(response)
5
+ super(response['message'])
6
+ @response = response
7
+ end
8
+ end
@@ -0,0 +1,52 @@
1
+ module Kintone::Client::Middleware
2
+ class Form < Faraday::Response::Middleware
3
+ def initialize(app, options = nil)
4
+ super(app)
5
+ end
6
+
7
+ def call(env)
8
+ @app.call(env).on_complete do |env|
9
+ if record = env[:body]['record']
10
+ env[:body] = {
11
+ 'record' => parse_form(record)
12
+ }
13
+ elsif records = env[:body]['records']
14
+ env[:body] = {
15
+ 'records' => records.map {|r| parse_form(r) }
16
+ }
17
+ end
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def parse_form(form)
24
+ parsed = {}
25
+
26
+ form.each do |name, field|
27
+ parsed[name] = parse_field(field)
28
+ end
29
+
30
+ parsed
31
+ end
32
+
33
+ def parse_field(field)
34
+ field_type = field['type']
35
+ field_value = field['value']
36
+
37
+ if field_type == 'SUBTABLE'
38
+ subtable = {}
39
+
40
+ field_value.each do |row|
41
+ subtable[row['id']] = parse_form(row['value'])
42
+ end
43
+
44
+ subtable
45
+ else
46
+ field_value
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ Faraday::Response.register_middleware :form => Kintone::Client::Middleware::Form
@@ -0,0 +1,5 @@
1
+ module Kintone
2
+ class Client
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ require 'base64'
2
+ require 'faraday'
3
+ require 'faraday_middleware'
4
+
5
+ module Kintone; end
6
+ require 'kintone/client/client'
7
+ require 'kintone/client/error'
8
+ require 'kintone/client/middleware/form'
9
+ require 'kintone/client/version'
@@ -0,0 +1,30 @@
1
+ # https://cybozudev.zendesk.com/hc/ja/articles/202931674-%E3%82%A2%E3%83%97%E3%83%AA%E6%83%85%E5%A0%B1%E3%81%AE%E5%8F%96%E5%BE%97#step1
2
+ describe Kintone::Client do
3
+ describe 'アプリ情報の取得(1件)' do
4
+ let(:response) do
5
+ {"appId"=>"1",
6
+ "code"=>"",
7
+ "name"=>"アプリ",
8
+ "description"=>"よいアプリです",
9
+ "spaceId"=>"2",
10
+ "threadId"=>"3",
11
+ "createdAt"=>"2014-05-02T05:14:05.000Z",
12
+ "creator"=>{"code"=>"", "name"=>""},
13
+ "modifiedAt"=>"2014-06-02T05:14:05.000Z",
14
+ "modifier"=>{"code"=>"jenkins", "name"=>"ボウズマン"}}
15
+ end
16
+
17
+ it do
18
+ client = kintone_client do |stub|
19
+ stub.get('/k/v1/app.json') do |env|
20
+ expect(params_from_url(env)).to eq "id=4"
21
+ expect(env.request_headers['X-Cybozu-Authorization']).to eq TEST_AUTH_HEADER
22
+ [200, {'Content-Type' => 'json'}, JSON.dump(response)]
23
+ end
24
+ end
25
+
26
+ result = client.app.get(id: 4)
27
+ expect(result).to eq response
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,77 @@
1
+ # https://cybozudev.zendesk.com/hc/ja/articles/202931674-%E3%82%A2%E3%83%97%E3%83%AA%E6%83%85%E5%A0%B1%E3%81%AE%E5%8F%96%E5%BE%97#step2
2
+ describe Kintone::Client do
3
+ describe 'アプリ情報の一括取得' do
4
+ let(:response) do
5
+ {"apps"=>
6
+ [{"appId"=>"1",
7
+ "code"=>"BAR",
8
+ "name"=>"MyTestApp",
9
+ "description"=>"",
10
+ "spaceId"=>nil,
11
+ "threadId"=>nil,
12
+ "createdAt"=>"2014-06-02T05:14:05.000Z",
13
+ "creator"=>{"code"=>"user1", "name"=>"user1"},
14
+ "modifiedAt"=>"2014-06-02T05:14:05.000Z",
15
+ "modifier"=>{"code"=>"user1", "name"=>"user1"}},
16
+ {"appId"=>"2",
17
+ "code"=>"FOO",
18
+ "name"=>"TEST",
19
+ "description"=>"",
20
+ "spaceId"=>"123",
21
+ "threadId"=>"456",
22
+ "createdAt"=>"2014-06-03T05:14:05.000Z",
23
+ "creator"=>{"code"=>"user2", "name"=>"user2"},
24
+ "modifiedAt"=>"2014-06-03T05:14:05.000Z",
25
+ "modifier"=>{"code"=>"user2", "name"=>"user2"}}]}
26
+ end
27
+
28
+ context 'where params is passed' do
29
+ it do
30
+ client = kintone_client do |stub|
31
+ stub.get('/k/v1/apps.json') do |env|
32
+ expect(params_from_url(env)).to eq "codes[0]=FOO&codes[1]=BAR&name=TEST"
33
+ expect(env.request_headers['X-Cybozu-Authorization']).to eq TEST_AUTH_HEADER
34
+ [200, {'Content-Type' => 'json'}, JSON.dump(response)]
35
+ end
36
+ end
37
+
38
+ result = client.apps.get(codes: ["FOO", "BAR"], name: "TEST")
39
+ expect(result).to eq response
40
+ end
41
+ end
42
+
43
+ context 'where params is not passed' do
44
+ it do
45
+ client = kintone_client do |stub|
46
+ stub.get('/k/v1/apps.json') do |env|
47
+ expect(params_from_url(env)).to be_nil
48
+ expect(env.request_headers['X-Cybozu-Authorization']).to eq TEST_AUTH_HEADER
49
+ [200, {'Content-Type' => 'json'}, JSON.dump(response)]
50
+ end
51
+ end
52
+
53
+ result = client.apps.get
54
+ expect(result).to eq response
55
+ end
56
+ end
57
+
58
+ context 'where there is no result' do
59
+ let(:response) do
60
+ {"apps"=>[]}
61
+ end
62
+
63
+ it do
64
+ client = kintone_client do |stub|
65
+ stub.get('/k/v1/apps.json') do |env|
66
+ expect(params_from_url(env)).to be_nil
67
+ expect(env.request_headers['X-Cybozu-Authorization']).to eq TEST_AUTH_HEADER
68
+ [200, {'Content-Type' => 'json'}, JSON.dump(response)]
69
+ end
70
+ end
71
+
72
+ result = client.apps.get
73
+ expect(result).to eq response
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,94 @@
1
+ # https://cybozudev.zendesk.com/hc/ja/articles/202331474-%E3%83%AC%E3%82%B3%E3%83%BC%E3%83%89%E3%81%AE%E5%8F%96%E5%BE%97-GET-#step1
2
+ describe Kintone::Client do
3
+ describe 'アプリ情報の取得(1件)' do
4
+ let(:response) do
5
+ {"record"=>
6
+ {"文字列__1行"=>{"type"=>"SINGLE_LINE_TEXT", "value"=>"テスト"},
7
+ "文字列__複数行"=>{"type"=>"MULTI_LINE_TEXT", "value"=>"テスト\nテスト2"},
8
+ "リッチエディター"=>
9
+ {"type"=>"RICH_TEXT",
10
+ "value"=>"<span style=\"color: rgb(0,0,255);\">テスト</span>"},
11
+ "$id"=>{"type"=>"__ID__", "value"=>"1"},
12
+ "$revision"=>{"type"=>"__REVISION__", "value"=>"7"},
13
+ "日付"=>{"type"=>"DATE", "value"=>"2014-02-16"},
14
+ "数値"=>{"type"=>"NUMBER", "value"=>"20"},
15
+ "Table"=>
16
+ {"type"=>"SUBTABLE",
17
+ "value"=>
18
+ [{"id"=>"33347",
19
+ "value"=>
20
+ {"ルックアップ"=>{"type"=>"SINGLE_LINE_TEXT", "value"=>""},
21
+ "テーブル文字列"=>{"type"=>"SINGLE_LINE_TEXT", "value"=>"テスト"},
22
+ "テーブル数値"=>{"type"=>"NUMBER", "value"=>"1000"}}},
23
+ {"id"=>"33354",
24
+ "value"=>
25
+ {"ルックアップ"=>{"type"=>"SINGLE_LINE_TEXT", "value"=>""},
26
+ "テーブル文字列"=>{"type"=>"SINGLE_LINE_TEXT", "value"=>"テスト2"},
27
+ "テーブル数値"=>{"type"=>"NUMBER", "value"=>"2000"}}}]},
28
+ "日時"=>{"type"=>"DATETIME", "value"=>"2014-02-16T08:57:00Z"},
29
+ "ユーザー選択"=>
30
+ {"type"=>"USER_SELECT", "value"=>[{"code"=>"sato", "name"=>"佐藤 昇"}]},
31
+ "時刻"=>{"type"=>"TIME", "value"=>"17:57"},
32
+ "作成日時"=>{"type"=>"CREATED_TIME", "value"=>"2014-02-16T08:59:00Z"},
33
+ "チェックボックス"=>{"type"=>"CHECK_BOX", "value"=>["sample1", "sample2"]},
34
+ "複数選択"=>{"type"=>"MULTI_SELECT", "value"=>["sample1", "sample2"]},
35
+ "更新日時"=>{"type"=>"UPDATED_TIME", "value"=>"2014-02-17T02:35:00Z"},
36
+ "作成者"=>{"type"=>"CREATOR", "value"=>{"code"=>"sato", "name"=>"佐藤 昇"}},
37
+ "更新者"=>{"type"=>"MODIFIER", "value"=>{"code"=>"sato", "name"=>"佐藤 昇"}},
38
+ "レコード番号"=>{"type"=>"RECORD_NUMBER", "value"=>"1"},
39
+ "ドロップダウン"=>{"type"=>"DROP_DOWN", "value"=>"sample2"},
40
+ "リンク_ウェブ"=>{"type"=>"LINK", "value"=>"https://www.cybozu.com"},
41
+ "添付ファイル"=>
42
+ {"type"=>"FILE",
43
+ "value"=>
44
+ [{"contentType"=>"image/png",
45
+ "fileKey"=>"20140216085901A05579B4196F4968AE26262EE889BD58086",
46
+ "name"=>"2014-01-30_No-0001.png",
47
+ "size"=>"30536"}]}}}
48
+ end
49
+
50
+ let(:parsed_response) do
51
+ {"record"=>
52
+ {"文字列__1行"=>"テスト",
53
+ "文字列__複数行"=>"テスト\nテスト2",
54
+ "リッチエディター"=>"<span style=\"color: rgb(0,0,255);\">テスト</span>",
55
+ "$id"=>"1",
56
+ "$revision"=>"7",
57
+ "日付"=>"2014-02-16",
58
+ "数値"=>"20",
59
+ "Table"=>
60
+ {"33347"=>{"ルックアップ"=>"", "テーブル文字列"=>"テスト", "テーブル数値"=>"1000"},
61
+ "33354"=>{"ルックアップ"=>"", "テーブル文字列"=>"テスト2", "テーブル数値"=>"2000"}},
62
+ "日時"=>"2014-02-16T08:57:00Z",
63
+ "ユーザー選択"=>[{"code"=>"sato", "name"=>"佐藤 昇"}],
64
+ "時刻"=>"17:57",
65
+ "作成日時"=>"2014-02-16T08:59:00Z",
66
+ "チェックボックス"=>["sample1", "sample2"],
67
+ "複数選択"=>["sample1", "sample2"],
68
+ "更新日時"=>"2014-02-17T02:35:00Z",
69
+ "作成者"=>{"code"=>"sato", "name"=>"佐藤 昇"},
70
+ "更新者"=>{"code"=>"sato", "name"=>"佐藤 昇"},
71
+ "レコード番号"=>"1",
72
+ "ドロップダウン"=>"sample2",
73
+ "リンク_ウェブ"=>"https://www.cybozu.com",
74
+ "添付ファイル"=>
75
+ [{"contentType"=>"image/png",
76
+ "fileKey"=>"20140216085901A05579B4196F4968AE26262EE889BD58086",
77
+ "name"=>"2014-01-30_No-0001.png",
78
+ "size"=>"30536"}]}}
79
+ end
80
+
81
+ it do
82
+ client = kintone_client do |stub|
83
+ stub.get('/k/v1/record.json') do |env|
84
+ expect(params_from_url(env)).to eq "app=8&id=100"
85
+ expect(env.request_headers['X-Cybozu-Authorization']).to eq TEST_AUTH_HEADER
86
+ [200, {'Content-Type' => 'json'}, JSON.dump(response)]
87
+ end
88
+ end
89
+
90
+ result = client.record.get(app: 8, id: 100)
91
+ expect(result).to eq parsed_response
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,50 @@
1
+ # https://cybozudev.zendesk.com/hc/ja/articles/202331474-%E3%83%AC%E3%82%B3%E3%83%BC%E3%83%89%E3%81%AE%E5%8F%96%E5%BE%97-GET-#step2
2
+ describe Kintone::Client do
3
+ describe 'アプリ情報の取得(1件)' do
4
+ let(:response) do
5
+ {"records"=>
6
+ [{"record_id"=>{"type"=>"RECORD_NUMBER", "value"=>"1"},
7
+ "created_time"=>{"type"=>"CREATED_TIME", "value"=>"2012-02-03T08:50:00Z"},
8
+ "dropdown"=>{"type"=>"DROP_DOWN", "value"=>nil},
9
+ "$revision"=>{"type"=>"__REVISION__", "value"=>"4"}},
10
+ {"record_id"=>{"type"=>"RECORD_NUMBER", "value"=>"2"},
11
+ "created_time"=>{"type"=>"CREATED_TIME", "value"=>"2012-02-03T09:22:00Z"},
12
+ "dropdown"=>{"type"=>"DROP_DOWN", "value"=>nil},
13
+ "$revision"=>{"type"=>"__REVISION__", "value"=>"4"}}]}
14
+ end
15
+
16
+ let(:parsed_response) do
17
+ {"records"=>
18
+ [{"record_id"=>"1",
19
+ "created_time"=>"2012-02-03T08:50:00Z",
20
+ "dropdown"=>nil,
21
+ "$revision"=>"4"},
22
+ {"record_id"=>"2",
23
+ "created_time"=>"2012-02-03T09:22:00Z",
24
+ "dropdown"=>nil,
25
+ "$revision"=>"4"}]}
26
+ end
27
+
28
+ context 'when there is result' do
29
+ it do
30
+ client = kintone_client do |stub|
31
+ stub.get('/k/v1/record.json') do |env|
32
+ expect(params_from_url(env)).to eq <<-EOS.strip
33
+ app=8&fields[0]=record_id&fields[1]=created_time&fields[2]=dropdown&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
34
+ EOS
35
+ expect(env.request_headers['X-Cybozu-Authorization']).to eq TEST_AUTH_HEADER
36
+ [200, {'Content-Type' => 'json'}, JSON.dump(response)]
37
+ end
38
+ end
39
+
40
+ result = client.record.get(
41
+ app: 8,
42
+ 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',
43
+ fields: ["record_id", "created_time", "dropdown"]
44
+ )
45
+
46
+ expect(result).to eq parsed_response
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,61 @@
1
+ # https://cybozudev.zendesk.com/hc/ja/articles/202931674-%E3%82%A2%E3%83%97%E3%83%AA%E6%83%85%E5%A0%B1%E3%81%AE%E5%8F%96%E5%BE%97#step1
2
+ describe Kintone::Client do
3
+ describe 'アプリ情報の取得(1件)' do
4
+ let(:response) do
5
+ {"id"=>"1",
6
+ "name"=>"全体連絡スペース",
7
+ "defaultThread"=>"3",
8
+ "isPrivate"=>true,
9
+ "creator"=>{"code"=>"tanaka", "name"=>"田中太郎"},
10
+ "modifier"=>{"code"=>"tanaka", "name"=>"田中太郎"},
11
+ "memberCount"=>10,
12
+ "coverType"=>"PRESET",
13
+ "coverKey"=>"GREEN",
14
+ "coverUrl"=>"https://*******/green.jpg",
15
+ "body"=>"<b>全体</b>のスペースです。",
16
+ "useMultiThread"=>true,
17
+ "isGuest"=>false,
18
+ "attachedApps"=>
19
+ [{"threadId"=>"1",
20
+ "appId"=>"1",
21
+ "code"=>"TASK",
22
+ "name"=>"タスク管理",
23
+ "description"=>"タスクを管理するアプリです。",
24
+ "createdAt"=>"2012-02-03T09:22:00Z",
25
+ "creator"=>{"name"=>"佐藤昇", "code"=>"sato"},
26
+ "modifiedAt"=>"2012-04-15T10:08:00Z",
27
+ "modifier"=>{"name"=>"佐藤昇", "code"=>"sato"}},
28
+ {"threadId"=>"3",
29
+ "appId"=>"10",
30
+ "code"=>"",
31
+ "name"=>"アンケートフォーム",
32
+ "description"=>"アンケートアプリです。",
33
+ "createdAt"=>"2012-02-03T09:22:00Z",
34
+ "creator"=>{"name"=>"佐藤昇", "code"=>"sato"},
35
+ "modifiedAt"=>"2012-04-15T10:08:00Z",
36
+ "modifier"=>{"name"=>"佐藤昇", "code"=>"sato"}},
37
+ {"threadId"=>"3",
38
+ "appId"=>"11",
39
+ "code"=>"",
40
+ "name"=>"日報",
41
+ "description"=>"日報アプリです。",
42
+ "createdAt"=>"2012-02-03T09:22:00Z",
43
+ "creator"=>{"name"=>"加藤美咲", "code"=>"kato"},
44
+ "modifiedAt"=>"2012-04-15T10:08:00Z",
45
+ "modifier"=>{"name"=>"加藤美咲", "code"=>"kato"}}]}
46
+ end
47
+
48
+ it do
49
+ client = kintone_client do |stub|
50
+ stub.get('/k/v1/space.json') do |env|
51
+ expect(params_from_url(env)).to eq "id=1"
52
+ expect(env.request_headers['X-Cybozu-Authorization']).to eq TEST_AUTH_HEADER
53
+ [200, {'Content-Type' => 'json'}, JSON.dump(response)]
54
+ end
55
+ end
56
+
57
+ result = client.space.get(id: 1)
58
+ expect(result).to eq response
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,18 @@
1
+ require 'kintone/client'
2
+
3
+ TEST_AUTH_HEADER = 'c2NvdHQ6dGlnZXI='
4
+
5
+ def kintone_client
6
+ stubs = Faraday::Adapter::Test::Stubs.new
7
+
8
+ Kintone::Client.new(subdomein: 'foo', login_name: 'scott', password: 'tiger') do |faraday|
9
+ faraday.adapter :test, stubs do |stub|
10
+ yield(stub)
11
+ end
12
+ end
13
+ end
14
+
15
+ def params_from_url(env)
16
+ query = URI.parse(env.url.to_s).query
17
+ query ? URI.decode(query) : query
18
+ end
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kintone-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Genki Sugawara
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-07 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'
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'
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'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '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: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
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: 3.0.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 3.0.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: http-dump
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: It is a simple client of cybozu kintone.
98
+ email:
99
+ - sugawara@cookpad.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-client.gemspec
111
+ - lib/kintone/client.rb
112
+ - lib/kintone/client/client.rb
113
+ - lib/kintone/client/error.rb
114
+ - lib/kintone/client/middleware/form.rb
115
+ - lib/kintone/client/version.rb
116
+ - spec/kintone/client/app_spec.rb
117
+ - spec/kintone/client/apps_spec.rb
118
+ - spec/kintone/client/record_spec.rb
119
+ - spec/kintone/client/records_spec.rb
120
+ - spec/kintone/client/space_spec.rb
121
+ - spec/spec_helper.rb
122
+ homepage: ''
123
+ licenses:
124
+ - MIT
125
+ metadata: {}
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 2.6.8
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: It is a simple client of cybozu kintone.
146
+ test_files:
147
+ - spec/kintone/client/app_spec.rb
148
+ - spec/kintone/client/apps_spec.rb
149
+ - spec/kintone/client/record_spec.rb
150
+ - spec/kintone/client/records_spec.rb
151
+ - spec/kintone/client/space_spec.rb
152
+ - spec/spec_helper.rb