kintone 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.coveralls.yml +1 -0
  3. data/.rubocop.yml +11 -1
  4. data/.travis.yml +15 -1
  5. data/Guardfile +2 -2
  6. data/README.md +4 -0
  7. data/kintone.gemspec +3 -5
  8. data/lib/kintone/api.rb +18 -24
  9. data/lib/kintone/api/guest.rb +6 -2
  10. data/lib/kintone/command/accessor.rb +1 -1
  11. data/lib/kintone/command/guests.rb +1 -1
  12. data/lib/kintone/command/record.rb +1 -1
  13. data/lib/kintone/command/records.rb +3 -2
  14. data/lib/kintone/kintone_error.rb +11 -0
  15. data/lib/kintone/query.rb +1 -1
  16. data/lib/kintone/version.rb +1 -1
  17. data/spec/kintone/api/guest_spec.rb +98 -10
  18. data/spec/kintone/api_spec.rb +186 -75
  19. data/spec/kintone/command/apis_spec.rb +70 -8
  20. data/spec/kintone/command/app_acl_spec.rb +21 -6
  21. data/spec/kintone/command/app_spec.rb +22 -2
  22. data/spec/kintone/command/apps_spec.rb +25 -2
  23. data/spec/kintone/command/bulk_request_spec.rb +22 -2
  24. data/spec/kintone/command/field_acl_spec.rb +25 -7
  25. data/spec/kintone/command/file_spec.rb +28 -12
  26. data/spec/kintone/command/form_spec.rb +23 -6
  27. data/spec/kintone/command/guests_spec.rb +44 -4
  28. data/spec/kintone/command/record_acl_spec.rb +27 -8
  29. data/spec/kintone/command/record_spec.rb +77 -10
  30. data/spec/kintone/command/records_spec.rb +157 -15
  31. data/spec/kintone/command/space_body_spec.rb +25 -7
  32. data/spec/kintone/command/space_guests_spec.rb +22 -2
  33. data/spec/kintone/command/space_members_spec.rb +47 -13
  34. data/spec/kintone/command/space_spec.rb +49 -19
  35. data/spec/kintone/command/space_thread_spec.rb +26 -2
  36. data/spec/kintone/command/template_space_spec.rb +37 -20
  37. data/spec/kintone/kintone_error_spec.rb +22 -0
  38. data/spec/spec_helper.rb +3 -0
  39. metadata +17 -27
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b117f1c781845b8712805c6ede66ed44d8b44382
4
- data.tar.gz: 2f3151d4228579e118fec2564f55f93b1eef955b
3
+ metadata.gz: 8d0188da83c5ab9e8038ede9d675404c468e1c3c
4
+ data.tar.gz: 4f2f6299034a38c502b3e50274e04569de423072
5
5
  SHA512:
6
- metadata.gz: dd4fb7e33d330c4922c26b16449cd4ea5ef3998c2eda3376f127fafffcefb5193604f9cce5c381f0e86b239b859f1fe23979827c053edcf1f70cdeda8144f232
7
- data.tar.gz: 34b39834c77beddbd95b4ebeff58483663210185a781f1c5e72a2a7213ddb9b67fe66e6a43dd047405f4eb2b23563c7f0a145e33bac209b63cf56ad4c54dd865
6
+ metadata.gz: 84285d30be1e24bf33c3eed5e893d172d9b201d0b0beb8608c519d0fc28468bb5a7225804d6ea50ebac7ebbaf9aa76cc268222bb1777b42b4dcfe9d9cbfc2fda
7
+ data.tar.gz: e29743feaeb25c857a55eb568bd21f0e3161ee9a19abc61a5bbc4d0c1e9d02c23cb49fc9df9bc7db553c17e3cbf410e55a5b2036fd1e8568a0bed0508b9f570b
@@ -0,0 +1 @@
1
+ repo_token: zDaEBy037OST98voxtIsbOPpyrTkqUXxi
@@ -17,7 +17,7 @@ Style/Documentation:
17
17
  Enabled: false
18
18
 
19
19
  # Configuration parameters: AllowURI.
20
- Style/LineLength:
20
+ Metrics/LineLength:
21
21
  Max: 1_00
22
22
 
23
23
  # Cop supports --auto-correct.
@@ -34,3 +34,13 @@ Style/AsciiComments:
34
34
 
35
35
  CyclomaticComplexity:
36
36
  Max: 10
37
+
38
+ Style/FrozenStringLiteralComment:
39
+ Enabled: false
40
+
41
+ Style/SymbolProc:
42
+ Exclude:
43
+ - 'lib/kintone/query.rb'
44
+
45
+ Style/SignalException:
46
+ EnforcedStyle: only_raise
@@ -8,7 +8,21 @@ rvm:
8
8
  - 2.1.4
9
9
  - 2.1.5
10
10
  - 2.1.6
11
+ - 2.1.7
12
+ - 2.1.8
13
+ - 2.1.9
14
+ - 2.1.10
11
15
  - 2.2.0
12
16
  - 2.2.1
13
17
  - 2.2.2
14
- - 2.3.0
18
+ - 2.2.3
19
+ - 2.2.4
20
+ - 2.2.5
21
+ - 2.2.6
22
+ - 2.3.0
23
+ - 2.3.1
24
+ - 2.3.2
25
+ - 2.3.3
26
+ - 2.4.0
27
+ before_install:
28
+ - gem install rainbow
data/Guardfile CHANGED
@@ -1,10 +1,10 @@
1
- guard :rspec, all_after_pass: false, all_on_start: false, cmd: 'bundle exec rspec' do
1
+ guard :rspec, all_after_pass: false, all_on_start: false, cmd: 'rspec' do
2
2
  watch(%r{spec/.+_spec\.rb$})
3
3
  watch(%r{lib/(.+)\.rb$}) {|m| "spec/#{m[1]}_spec.rb"}
4
4
  watch(%r{lib/(.+)/.+\.rb$}) {|m| "spec/#{m[1]}_spec.rb"}
5
5
  end
6
6
 
7
- guard :rubocop, all_on_start: false, cmd: 'bundle exec rubocop' do
7
+ guard :rubocop, all_on_start: false, cmd: 'rubocop' do
8
8
  watch(%r{.+\.rb$})
9
9
  watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
10
10
  end
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # kintone
2
2
 
3
3
  [![Build Status](https://travis-ci.org/jue58/kintone.svg?branch=master)](https://travis-ci.org/jue58/kintone)
4
+ [![codebeat badge](https://codebeat.co/badges/7f66de05-57a4-4712-9706-0f33169f530b)](https://codebeat.co/projects/github-com-jue58-kintone)
5
+ [![Coverage Status](https://coveralls.io/repos/github/jue58/kintone/badge.svg?branch=add-coveralls-settings)](https://coveralls.io/github/jue58/kintone?branch=add-coveralls-settings)
6
+ [![Inline docs](http://inch-ci.org/github/jue58/kintone.svg?branch=master&style=shields)](http://inch-ci.org/github/jue58/kintone)
7
+ [![Gem Version](https://badge.fury.io/rb/kintone.svg)](https://badge.fury.io/rb/kintone)
4
8
 
5
9
  A Ruby gem for communicating with the [kintone](https://kintone.cybozu.com/us/) REST API
6
10
 
@@ -1,5 +1,4 @@
1
1
  # coding: utf-8
2
- # rubocop:disable Style/RegexpLiteral
3
2
  lib = File.expand_path('../lib', __FILE__)
4
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
4
  require 'kintone/version'
@@ -24,10 +23,9 @@ Gem::Specification.new do |spec|
24
23
 
25
24
  spec.add_development_dependency 'bundler', '~> 1.5'
26
25
  spec.add_development_dependency 'rake'
27
- spec.add_development_dependency 'rspec', '~> 3.0.0'
28
- spec.add_development_dependency 'rubocop', '~> 0.24.1'
26
+ spec.add_development_dependency 'rspec', '~> 3'
27
+ spec.add_development_dependency 'rubocop', '~> 0.44.1'
29
28
  spec.add_development_dependency 'webmock', '~> 1.18'
30
- spec.add_development_dependency 'guard-rspec'
31
- spec.add_development_dependency 'guard-rubocop'
32
29
  spec.add_development_dependency 'rspec-parameterized', '~> 0.1.2'
30
+ spec.add_development_dependency 'coveralls'
33
31
  end
@@ -5,29 +5,16 @@ require 'json'
5
5
  require 'kintone/command/accessor'
6
6
  require 'kintone/api/guest'
7
7
  require 'kintone/query'
8
+ require 'kintone/kintone_error'
8
9
 
9
10
  class Kintone::Api
10
- BASE_PATH = '/k/v1/'
11
- COMMAND = '%s.json'
11
+ BASE_PATH = '/k/v1/'.freeze
12
+ COMMAND = '%s.json'.freeze
12
13
  ACCESSIBLE_COMMAND = [
13
- :record,
14
- :records,
15
- :form,
16
- :app_acl,
17
- :record_acl,
18
- :field_acl,
19
- :template_space,
20
- :space,
21
- :space_body,
22
- :space_thread,
23
- :space_members,
24
- :guests,
25
- :app,
26
- :apps,
27
- :apis,
28
- :bulk_request,
29
- :bulk,
30
- :file
14
+ :record, :records, :form, :app_acl, :record_acl,
15
+ :field_acl, :template_space, :space, :space_body, :space_thread,
16
+ :space_members, :guests, :app, :apps, :apis,
17
+ :bulk_request, :bulk, :file
31
18
  ].freeze
32
19
 
33
20
  def initialize(domain, user, password = nil)
@@ -54,6 +41,7 @@ class Kintone::Api
54
41
  request.url url
55
42
  request.params = params
56
43
  end
44
+ raise Kintone::KintoneError.new(response.body, response.status) if response.status != 200
57
45
  response.body
58
46
  end
59
47
 
@@ -64,6 +52,7 @@ class Kintone::Api
64
52
  request.headers['Content-Type'] = 'application/json'
65
53
  request.body = body.to_json
66
54
  end
55
+ raise Kintone::KintoneError.new(response.body, response.status) if response.status != 200
67
56
  response.body
68
57
  end
69
58
 
@@ -74,6 +63,7 @@ class Kintone::Api
74
63
  request.headers['Content-Type'] = 'application/json'
75
64
  request.body = body.to_json
76
65
  end
66
+ raise Kintone::KintoneError.new(response.body, response.status) if response.status != 200
77
67
  response.body
78
68
  end
79
69
 
@@ -84,6 +74,7 @@ class Kintone::Api
84
74
  request.headers['Content-Type'] = 'application/json'
85
75
  request.body = body.to_json
86
76
  end
77
+ raise Kintone::KintoneError.new(response.body, response.status) if response.status != 200
87
78
  response.body
88
79
  end
89
80
 
@@ -92,10 +83,9 @@ class Kintone::Api
92
83
  @connection.post do |request|
93
84
  request.url url
94
85
  request.headers['Content-Type'] = 'multipart/form-data'
95
- request.body = { file: Faraday::UploadIO.new(
96
- path, content_type, original_filename,
97
- 'Content-Disposition' => 'form-data') }
86
+ request.body = { file: Faraday::UploadIO.new(path, content_type, original_filename) }
98
87
  end
88
+ raise Kintone::KintoneError.new(response.body, response.status) if response.status != 200
99
89
  response.body['fileKey']
100
90
  end
101
91
 
@@ -103,10 +93,14 @@ class Kintone::Api
103
93
  if ACCESSIBLE_COMMAND.include?(name)
104
94
  CommandAccessor.send(name, self)
105
95
  else
106
- super(name, *args)
96
+ super
107
97
  end
108
98
  end
109
99
 
100
+ def respond_to_missing?(name, *args)
101
+ ACCESSIBLE_COMMAND.include?(name) || super
102
+ end
103
+
110
104
  class CommandAccessor
111
105
  extend Kintone::Command::Accessor
112
106
  end
@@ -6,7 +6,7 @@ class Kintone::Api
6
6
  class Guest
7
7
  extend Forwardable
8
8
 
9
- GUEST_PATH = '/k/guest/%s/v1/'
9
+ GUEST_PATH = '/k/guest/%s/v1/'.freeze
10
10
  ACCESSIBLE_COMMAND = [
11
11
  :record,
12
12
  :records,
@@ -41,10 +41,14 @@ class Kintone::Api
41
41
  if ACCESSIBLE_COMMAND.include?(name)
42
42
  CommandAccessor.send(name, self)
43
43
  else
44
- super(name, *args)
44
+ super
45
45
  end
46
46
  end
47
47
 
48
+ def respond_to_missing?(name, *args)
49
+ ACCESSIBLE_COMMAND.include?(name) || super
50
+ end
51
+
48
52
  class CommandAccessor
49
53
  extend Kintone::Command::Accessor
50
54
  end
@@ -99,6 +99,6 @@ class Kintone::Command
99
99
  SpaceGuests.new(api)
100
100
  end
101
101
 
102
- alias_method :bulk, :bulk_request
102
+ alias bulk bulk_request
103
103
  end
104
104
  end
@@ -13,5 +13,5 @@ class Kintone::Command::Guests < Kintone::Command
13
13
  @api.delete(@url, guests: guests)
14
14
  end
15
15
 
16
- alias_method :create, :register
16
+ alias create register
17
17
  end
@@ -19,5 +19,5 @@ class Kintone::Command::Record < Kintone::Command
19
19
  @api.put(@url, body)
20
20
  end
21
21
 
22
- alias_method :create, :register
22
+ alias create register
23
23
  end
@@ -5,8 +5,9 @@ class Kintone::Command::Records < Kintone::Command
5
5
  'records'
6
6
  end
7
7
 
8
- def get(app, query, fields)
8
+ def get(app, query, fields, total_count: nil)
9
9
  params = { app: app, query: query.to_s }
10
+ params[:totalCount] = total_count if total_count
10
11
  fields.each_with_index { |v, i| params["fields[#{i}]"] = v }
11
12
  @api.get(@url, params)
12
13
  end
@@ -25,5 +26,5 @@ class Kintone::Command::Records < Kintone::Command
25
26
  @api.delete(@url, params)
26
27
  end
27
28
 
28
- alias_method :create, :register
29
+ alias create register
29
30
  end
@@ -0,0 +1,11 @@
1
+ class Kintone::KintoneError < StandardError
2
+ attr_reader :message_text, :id, :code, :http_status
3
+
4
+ def initialize(messages, http_status)
5
+ @message_text = messages['message']
6
+ @id = messages['id']
7
+ @code = messages['code']
8
+ @http_status = http_status
9
+ super(format('%s [%s] %s(%s)', @http_status, @code, @message_text, @id))
10
+ end
11
+ end
@@ -68,7 +68,7 @@ class Kintone::Query
68
68
  to_s
69
69
  end
70
70
 
71
- alias_method :f, :field
71
+ alias f field
72
72
 
73
73
  private
74
74
 
@@ -1,3 +1,3 @@
1
1
  module Kintone
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.5'.freeze
3
3
  end
@@ -25,8 +25,11 @@ describe Kintone::Api::Guest do
25
25
  headers: { 'X-Cybozu-Authorization' => 'QWRtaW5pc3RyYXRvcjpjeWJvenU=' },
26
26
  query: params
27
27
  )
28
- .to_return(body: "{\"abc\":\"def\"}", status: 200,
29
- headers: { 'Content-type' => 'application/json' })
28
+ .to_return(
29
+ body: '{"abc":"def"}',
30
+ status: 200,
31
+ headers: { 'Content-type' => 'application/json' }
32
+ )
30
33
  end
31
34
 
32
35
  subject { target.get(path, params) }
@@ -35,6 +38,25 @@ describe Kintone::Api::Guest do
35
38
  let(:params) { { p1: 'abc', p2: 'def' } }
36
39
 
37
40
  it { expect(subject).to eq 'abc' => 'def' }
41
+
42
+ context 'fail to request' do
43
+ before(:each) do
44
+ stub_request(
45
+ :get,
46
+ 'https://example.cybozu.com/k/guest/1/v1/path.json'
47
+ )
48
+ .with(
49
+ headers: { 'X-Cybozu-Authorization' => 'QWRtaW5pc3RyYXRvcjpjeWJvenU=' },
50
+ query: params
51
+ )
52
+ .to_return(
53
+ body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
54
+ status: 500
55
+ )
56
+ end
57
+
58
+ it { expect { subject }.to raise_error Kintone::KintoneError }
59
+ end
38
60
  end
39
61
 
40
62
  describe '#post' do
@@ -45,10 +67,13 @@ describe Kintone::Api::Guest do
45
67
  )
46
68
  .with(
47
69
  headers: { 'X-Cybozu-Authorization' => 'QWRtaW5pc3RyYXRvcjpjeWJvenU=' },
48
- body: "{\"p1\":\"abc\",\"p2\":\"def\"}"
70
+ body: '{"p1":"abc","p2":"def"}'
71
+ )
72
+ .to_return(
73
+ body: '{"abc":"def"}',
74
+ status: 200,
75
+ headers: { 'Content-type' => 'application/json' }
49
76
  )
50
- .to_return(body: "{\"abc\":\"def\"}", status: 200,
51
- headers: { 'Content-type' => 'application/json' })
52
77
  end
53
78
 
54
79
  subject { target.post(path, body) }
@@ -57,6 +82,25 @@ describe Kintone::Api::Guest do
57
82
  let(:body) { { 'p1' => 'abc', 'p2' => 'def' } }
58
83
 
59
84
  it { expect(subject).to eq 'abc' => 'def' }
85
+
86
+ context 'fail to request' do
87
+ before(:each) do
88
+ stub_request(
89
+ :post,
90
+ 'https://example.cybozu.com/k/guest/1/v1/path.json'
91
+ )
92
+ .with(
93
+ headers: { 'X-Cybozu-Authorization' => 'QWRtaW5pc3RyYXRvcjpjeWJvenU=' },
94
+ body: '{"p1":"abc","p2":"def"}'
95
+ )
96
+ .to_return(
97
+ body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
98
+ status: 500
99
+ )
100
+ end
101
+
102
+ it { expect { subject }.to raise_error Kintone::KintoneError }
103
+ end
60
104
  end
61
105
 
62
106
  describe '#put' do
@@ -67,10 +111,13 @@ describe Kintone::Api::Guest do
67
111
  )
68
112
  .with(
69
113
  headers: { 'X-Cybozu-Authorization' => 'QWRtaW5pc3RyYXRvcjpjeWJvenU=' },
70
- body: "{\"p1\":\"abc\",\"p2\":\"def\"}"
114
+ body: '{"p1":"abc","p2":"def"}'
115
+ )
116
+ .to_return(
117
+ body: '{"abc":"def"}',
118
+ status: 200,
119
+ headers: { 'Content-type' => 'application/json' }
71
120
  )
72
- .to_return(body: "{\"abc\":\"def\"}", status: 200,
73
- headers: { 'Content-type' => 'application/json' })
74
121
  end
75
122
 
76
123
  subject { target.put(path, body) }
@@ -79,6 +126,25 @@ describe Kintone::Api::Guest do
79
126
  let(:body) { { 'p1' => 'abc', 'p2' => 'def' } }
80
127
 
81
128
  it { expect(subject).to eq 'abc' => 'def' }
129
+
130
+ context 'fail to request' do
131
+ before(:each) do
132
+ stub_request(
133
+ :put,
134
+ 'https://example.cybozu.com/k/guest/1/v1/path.json'
135
+ )
136
+ .with(
137
+ headers: { 'X-Cybozu-Authorization' => 'QWRtaW5pc3RyYXRvcjpjeWJvenU=' },
138
+ body: '{"p1":"abc","p2":"def"}'
139
+ )
140
+ .to_return(
141
+ body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
142
+ status: 500
143
+ )
144
+ end
145
+
146
+ it { expect { subject }.to raise_error Kintone::KintoneError }
147
+ end
82
148
  end
83
149
 
84
150
  describe '#delete' do
@@ -91,8 +157,11 @@ describe Kintone::Api::Guest do
91
157
  body: { 'p1' => 'abc', 'p2' => 'def' }.to_json,
92
158
  headers: { 'X-Cybozu-Authorization' => 'QWRtaW5pc3RyYXRvcjpjeWJvenU=' }
93
159
  )
94
- .to_return(body: "{\"abc\":\"def\"}", status: 200,
95
- headers: { 'Content-type' => 'application/json' })
160
+ .to_return(
161
+ body: '{"abc":"def"}',
162
+ status: 200,
163
+ headers: { 'Content-type' => 'application/json' }
164
+ )
96
165
  end
97
166
 
98
167
  subject { target.delete(path, params) }
@@ -101,6 +170,25 @@ describe Kintone::Api::Guest do
101
170
  let(:params) { { 'p1' => 'abc', 'p2' => 'def' } }
102
171
 
103
172
  it { expect(subject).to eq 'abc' => 'def' }
173
+
174
+ context 'fail to request' do
175
+ before(:each) do
176
+ stub_request(
177
+ :delete,
178
+ 'https://example.cybozu.com/k/guest/1/v1/path.json'
179
+ )
180
+ .with(
181
+ body: { 'p1' => 'abc', 'p2' => 'def' }.to_json,
182
+ headers: { 'X-Cybozu-Authorization' => 'QWRtaW5pc3RyYXRvcjpjeWJvenU=' }
183
+ )
184
+ .to_return(
185
+ body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
186
+ status: 500
187
+ )
188
+ end
189
+
190
+ it { expect { subject }.to raise_error Kintone::KintoneError }
191
+ end
104
192
  end
105
193
 
106
194
  describe '#record' do