kintone-client 0.1.3 → 0.1.4

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: f8405538519f116448d017e5c80731bff2914fa5
4
- data.tar.gz: faf00bbceed1434aec64b54f004d2a7f589c3621
3
+ metadata.gz: f45e8aea8f3bbfbd363bf255b787f1ebad043ff7
4
+ data.tar.gz: 302ba4e89536b92386c2212b7e3f2c614f6045ea
5
5
  SHA512:
6
- metadata.gz: 9335cace6fe308ed569b8578c430e23fcc2d40bdfa7caf69c51437ccfc28fb258695bbc6ae8eac420d6801570a993e959ef546c38402a1bf9181ef5c2c554067
7
- data.tar.gz: b5607d1e1afb62d4b58819fd147642badb3fddf12abebfb4abaaa814532c4f16dbe66c8a1e6033e3abba9ff9c65a6dff93b83553e602176df3a06cf2f94bea5a
6
+ metadata.gz: 2a45e6ba3a2ad346d196baa3116604ab9aa3a621d341f1b1a301f51871878c537e037477bde705bc78e95052e1a6479ed36dd7f07fbe9b62a297d1a356fdafad
7
+ data.tar.gz: 231119937b7e73b04c25e062b35d6835349aa993849e3c2dce4af077d2f13160b5a9b814a3ab3bc9a92037652ad82b9ff91cddcc94483a363875e922f125505b
data/README.md CHANGED
@@ -31,6 +31,20 @@ p client.records.get(app: 211)
31
31
 
32
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
33
  p client.space.members.get(id: 4)
34
+
35
+ # `"文字列__1行"=>"テスト"` -> `"文字列__1行"=>{"value"=>"テスト"}`
36
+ client.record.post_json(
37
+ {"app"=>1972,
38
+ "record"=>
39
+ {"文字列__1行"=>"テスト",
40
+ "文字列__複数行"=>"テスト\nテスト2",
41
+ "数値"=>20,
42
+ "日時"=>"2014-02-16T08:57:00Z",
43
+ "チェックボックス"=>{"value"=>["sample1", "sample2"]},
44
+ "ユーザー選択"=>{"value"=>[{"code"=>"sato"}]},
45
+ "ドロップダウン"=>"sample1",
46
+ "リンク_ウェブ"=>"https://www.cybozu.com",
47
+ "Table"=>{"value"=>[{"value"=>{"テーブル文字列"=>{"value"=>"テスト"}}}]}}})
34
48
  ```
35
49
 
36
50
  ## kintone API
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.add_dependency 'faraday', '>= 0.8'
21
+ spec.add_dependency 'faraday', ENV['FARADAY_VERSION'] ? "= #{ENV['FARADAY_VERSION']}" : '>= 0.8.9'
22
22
  spec.add_dependency 'faraday_middleware'
23
23
  spec.add_development_dependency 'bundler'
24
24
  spec.add_development_dependency 'rake'
@@ -7,13 +7,13 @@ module Kintone::Client::Middleware
7
7
  def call(env)
8
8
  @app.call(env).on_complete do |env|
9
9
  if record = env[:body]['record']
10
- env[:body] = {
11
- 'record' => parse_form(record)
12
- }
10
+ env[:body]['record'] = parse_form(record)
13
11
  elsif records = env[:body]['records']
14
- env[:body] = {
15
- 'records' => records.map {|r| parse_form(r) }
16
- }
12
+ env[:body]['records'] = records.map {|r| parse_form(r) }
13
+ end
14
+
15
+ if totalCount = env[:body]['totalCount']
16
+ env[:body]['totalCount'] = totalCount.to_i
17
17
  end
18
18
  end
19
19
  end
@@ -1,5 +1,5 @@
1
1
  module Kintone
2
2
  class Client
3
- VERSION = '0.1.3'
3
+ VERSION = '0.1.4'
4
4
  end
5
5
  end
@@ -17,8 +17,8 @@ describe Kintone::Client do
17
17
  it do
18
18
  client = kintone_client do |stub|
19
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
20
+ expect(params_from_url(env)).to eq({"id"=>["4"]})
21
+ expect(env[:request_headers]['X-Cybozu-Authorization']).to eq TEST_AUTH_HEADER
22
22
  [200, {'Content-Type' => 'json'}, JSON.dump(response)]
23
23
  end
24
24
  end
@@ -29,8 +29,8 @@ describe Kintone::Client do
29
29
  it do
30
30
  client = kintone_client do |stub|
31
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
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
34
  [200, {'Content-Type' => 'json'}, JSON.dump(response)]
35
35
  end
36
36
  end
@@ -45,7 +45,7 @@ describe Kintone::Client do
45
45
  client = kintone_client do |stub|
46
46
  stub.get('/k/v1/apps.json') do |env|
47
47
  expect(params_from_url(env)).to be_nil
48
- expect(env.request_headers['X-Cybozu-Authorization']).to eq TEST_AUTH_HEADER
48
+ expect(env[:request_headers]['X-Cybozu-Authorization']).to eq TEST_AUTH_HEADER
49
49
  [200, {'Content-Type' => 'json'}, JSON.dump(response)]
50
50
  end
51
51
  end
@@ -64,7 +64,7 @@ describe Kintone::Client do
64
64
  client = kintone_client do |stub|
65
65
  stub.get('/k/v1/apps.json') do |env|
66
66
  expect(params_from_url(env)).to be_nil
67
- expect(env.request_headers['X-Cybozu-Authorization']).to eq TEST_AUTH_HEADER
67
+ expect(env[:request_headers]['X-Cybozu-Authorization']).to eq TEST_AUTH_HEADER
68
68
  [200, {'Content-Type' => 'json'}, JSON.dump(response)]
69
69
  end
70
70
  end
@@ -44,9 +44,9 @@ describe Kintone::Client do
44
44
  it do
45
45
  client = kintone_client do |stub|
46
46
  stub.post('/k/v1/bulkRequest.json') do |env|
47
- expect(env.body).to eq JSON.dump(request)
48
- expect(env.request_headers['X-Cybozu-Authorization']).to eq TEST_AUTH_HEADER
49
- expect(env.request_headers['Content-Type']).to eq 'application/json'
47
+ expect(env[:body]).to eq JSON.dump(request)
48
+ expect(env[:request_headers]['X-Cybozu-Authorization']).to eq TEST_AUTH_HEADER
49
+ expect(env[:request_headers]['Content-Type']).to eq 'application/json'
50
50
  [200, {'Content-Type' => 'json'}, JSON.dump(response)]
51
51
  end
52
52
  end
@@ -58,9 +58,9 @@ describe Kintone::Client do
58
58
  it do
59
59
  client = kintone_client do |stub|
60
60
  stub.post('/k/v1/bulkRequest.json') do |env|
61
- expect(env.body).to eq JSON.dump(request)
62
- expect(env.request_headers['X-Cybozu-Authorization']).to eq TEST_AUTH_HEADER
63
- expect(env.request_headers['Content-Type']).to eq 'application/json'
61
+ expect(env[:body]).to eq JSON.dump(request)
62
+ expect(env[:request_headers]['X-Cybozu-Authorization']).to eq TEST_AUTH_HEADER
63
+ expect(env[:request_headers]['Content-Type']).to eq 'application/json'
64
64
  [200, {'Content-Type' => 'json'}, JSON.dump(response)]
65
65
  end
66
66
  end
@@ -23,10 +23,10 @@ describe Kintone::Client do
23
23
  "数値"=>20,
24
24
  "日時"=>"2014-02-16T08:57:00Z",
25
25
  "チェックボックス"=>{"value"=>["sample1", "sample2"]},
26
- "ユーザー選択"=>{"value"=>[{"code"=>"sato"}]},
26
+ "ユーザー選択"=>{value: [{"code"=>"sato"}]},
27
27
  "ドロップダウン"=>"sample1",
28
28
  "リンク_ウェブ"=>"https://www.cybozu.com",
29
- "Table"=>{"value"=>[{"value"=>{"テーブル文字列"=>{"value"=>"テスト"}}}]}}}
29
+ "Table"=>{value: [{"value"=>{"テーブル文字列"=>{value: "テスト"}}}]}}}
30
30
  end
31
31
 
32
32
  let(:response) do
@@ -36,9 +36,9 @@ describe Kintone::Client do
36
36
  it do
37
37
  client = kintone_client do |stub|
38
38
  stub.post('/k/v1/record.json') do |env|
39
- expect(env.body).to eq JSON.dump(request)
40
- expect(env.request_headers['X-Cybozu-Authorization']).to eq TEST_AUTH_HEADER
41
- expect(env.request_headers['Content-Type']).to eq 'application/json'
39
+ expect(env[:body]).to eq JSON.dump(request)
40
+ expect(env[:request_headers]['X-Cybozu-Authorization']).to eq TEST_AUTH_HEADER
41
+ expect(env[:request_headers]['Content-Type']).to eq 'application/json'
42
42
  [200, {'Content-Type' => 'json'}, JSON.dump(response)]
43
43
  end
44
44
  end
@@ -50,9 +50,9 @@ describe Kintone::Client do
50
50
  it do
51
51
  client = kintone_client do |stub|
52
52
  stub.post('/k/v1/record.json') do |env|
53
- expect(env.body).to eq JSON.dump(request)
54
- expect(env.request_headers['X-Cybozu-Authorization']).to eq TEST_AUTH_HEADER
55
- expect(env.request_headers['Content-Type']).to eq 'application/json'
53
+ expect(env[:body]).to eq JSON.dump(request)
54
+ expect(env[:request_headers]['X-Cybozu-Authorization']).to eq TEST_AUTH_HEADER
55
+ expect(env[:request_headers]['Content-Type']).to eq 'application/json'
56
56
  [200, {'Content-Type' => 'json'}, JSON.dump(response)]
57
57
  end
58
58
  end
@@ -61,6 +61,7 @@ describe Kintone::Client do
61
61
  expect(result).to eq response
62
62
  end
63
63
 
64
+ # https://cybozudev.zendesk.com/hc/ja/articles/201941754-REST-API%E3%81%AE%E5%85%B1%E9%80%9A%E4%BB%95%E6%A7%98#step10
64
65
  context 'when error happens' do
65
66
  let(:request) do
66
67
  {"app"=>1972}
@@ -73,9 +74,9 @@ describe Kintone::Client do
73
74
  it do
74
75
  client = kintone_client do |stub|
75
76
  stub.post('/k/v1/record.json') do |env|
76
- expect(env.body).to eq JSON.dump(request)
77
- expect(env.request_headers['X-Cybozu-Authorization']).to eq TEST_AUTH_HEADER
78
- expect(env.request_headers['Content-Type']).to eq 'application/json'
77
+ expect(env[:body]).to eq JSON.dump(request)
78
+ expect(env[:request_headers]['X-Cybozu-Authorization']).to eq TEST_AUTH_HEADER
79
+ expect(env[:request_headers]['Content-Type']).to eq 'application/json'
79
80
  [400, {'Content-Type' => 'json'}, JSON.dump(response)]
80
81
  end
81
82
  end
@@ -81,8 +81,8 @@ describe Kintone::Client do
81
81
  it do
82
82
  client = kintone_client do |stub|
83
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
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
86
  [200, {'Content-Type' => 'json'}, JSON.dump(response)]
87
87
  end
88
88
  end
@@ -29,10 +29,15 @@ describe Kintone::Client do
29
29
  it do
30
30
  client = kintone_client do |stub|
31
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
32
+ expect(params_from_url(env)).to eq({
33
+ "app"=>["8"],
34
+ "fields[0]"=>["record_id"],
35
+ "fields[1]"=>["created_time"],
36
+ "fields[2]"=>["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
+ })
39
+
40
+ expect(env[:request_headers]['X-Cybozu-Authorization']).to eq TEST_AUTH_HEADER
36
41
  [200, {'Content-Type' => 'json'}, JSON.dump(response)]
37
42
  end
38
43
  end
@@ -46,5 +51,39 @@ describe Kintone::Client do
46
51
  expect(result).to eq parsed_response
47
52
  end
48
53
  end
54
+
55
+ context 'when with totalCount' do
56
+ before do
57
+ response['totalCount'] = '1'
58
+ parsed_response['totalCount'] = 1
59
+ end
60
+
61
+ it do
62
+ client = kintone_client do |stub|
63
+ stub.get('/k/v1/record.json') do |env|
64
+ expect(params_from_url(env)).to eq({
65
+ "app"=>["8"],
66
+ "fields[0]"=>["record_id"],
67
+ "fields[1]"=>["created_time"],
68
+ "fields[2]"=>["dropdown"],
69
+ "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"],
70
+ "totalCount"=>["true"]
71
+ })
72
+
73
+ expect(env[:request_headers]['X-Cybozu-Authorization']).to eq TEST_AUTH_HEADER
74
+ [200, {'Content-Type' => 'json'}, JSON.dump(response)]
75
+ end
76
+ end
77
+
78
+ result = client.record.get(
79
+ app: 8,
80
+ 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',
81
+ fields: ["record_id", "created_time", "dropdown"],
82
+ totalCount: true
83
+ )
84
+
85
+ expect(result).to eq parsed_response
86
+ end
87
+ end
49
88
  end
50
89
  end
@@ -48,8 +48,8 @@ describe Kintone::Client do
48
48
  it do
49
49
  client = kintone_client do |stub|
50
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
51
+ expect(params_from_url(env)).to eq({"id"=>["1"]})
52
+ expect(env[:request_headers]['X-Cybozu-Authorization']).to eq TEST_AUTH_HEADER
53
53
  [200, {'Content-Type' => 'json'}, JSON.dump(response)]
54
54
  end
55
55
  end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'kintone/client'
2
+ require 'cgi'
2
3
 
3
4
  TEST_AUTH_HEADER = 'c2NvdHQ6dGlnZXI='
4
5
 
@@ -13,6 +14,6 @@ def kintone_client
13
14
  end
14
15
 
15
16
  def params_from_url(env)
16
- query = URI.parse(env.url.to_s).query
17
- query ? URI.decode(query) : query
17
+ query = URI.parse(env[:url].to_s).query
18
+ query ? CGI.parse(query) : query
18
19
  end
data/test.sh ADDED
@@ -0,0 +1,8 @@
1
+ #!/bin/sh
2
+ function run_test {
3
+ bundle install
4
+ bundle exec rake
5
+ }
6
+
7
+ FARADAY_VERSION=0.8.9 run_test
8
+ FARADAY_VERSION=0.9.1 run_test
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kintone-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0.8'
19
+ version: 0.8.9
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0.8'
26
+ version: 0.8.9
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: faraday_middleware
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +122,7 @@ files:
122
122
  - spec/kintone/client/records_spec.rb
123
123
  - spec/kintone/client/space_spec.rb
124
124
  - spec/spec_helper.rb
125
+ - test.sh
125
126
  homepage: ''
126
127
  licenses:
127
128
  - MIT