kintone 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +26 -0
  3. data/.travis.yml +4 -0
  4. data/Guardfile +10 -0
  5. data/README.md +35 -13
  6. data/Rakefile +9 -1
  7. data/kintone.gemspec +17 -14
  8. data/lib/kintone.rb +2 -2
  9. data/lib/kintone/api.rb +36 -22
  10. data/lib/kintone/api/guest.rb +16 -8
  11. data/lib/kintone/command.rb +11 -2
  12. data/lib/kintone/command/app_acl.rb +4 -8
  13. data/lib/kintone/command/field_acl.rb +4 -8
  14. data/lib/kintone/command/form.rb +4 -8
  15. data/lib/kintone/command/record.rb +6 -10
  16. data/lib/kintone/command/record_acl.rb +4 -8
  17. data/lib/kintone/command/records.rb +11 -15
  18. data/lib/kintone/command/space.rb +15 -0
  19. data/lib/kintone/command/space_body.rb +11 -0
  20. data/lib/kintone/command/template_space.rb +12 -0
  21. data/lib/kintone/version.rb +1 -1
  22. data/spec/kintone/api/guest_spec.rb +134 -0
  23. data/spec/kintone/api_spec.rb +176 -0
  24. data/spec/kintone/command/app_acl_spec.rb +28 -0
  25. data/spec/kintone/command/field_acl_spec.rb +28 -0
  26. data/spec/kintone/command/form_spec.rb +26 -0
  27. data/spec/kintone/command/record_acl_spec.rb +28 -0
  28. data/spec/kintone/command/record_spec.rb +93 -0
  29. data/spec/kintone/command/records_spec.rb +169 -0
  30. data/spec/kintone/command/space_body_spec.rb +28 -0
  31. data/spec/kintone/command/space_spec.rb +53 -0
  32. data/spec/kintone/command/template_space_spec.rb +41 -0
  33. metadata +75 -36
  34. data/spec/api/guest_spec.rb +0 -54
  35. data/spec/api_spec.rb +0 -148
  36. data/spec/command/app_acl_spec.rb +0 -28
  37. data/spec/command/field_acl_spec.rb +0 -28
  38. data/spec/command/form_spec.rb +0 -25
  39. data/spec/command/record_acl_spec.rb +0 -28
  40. data/spec/command/record_spec.rb +0 -92
  41. data/spec/command/records_spec.rb +0 -162
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 802b3540fa57136b666301320c4a78bb5254084f
4
- data.tar.gz: 101a717cecfbd0c2f2db6793aeb37444a7b71379
3
+ metadata.gz: 24a441e5a7cd395f4b7e77d1ef6c8c5fc450ec57
4
+ data.tar.gz: d2c412b23b6685dde86ae1e68bee11897dc1f1ed
5
5
  SHA512:
6
- metadata.gz: 85af72a3f02848b43e58286fc938858f488bf750da800a69133839b0ad92f5ee8165321420060df870dd9dd83cde7eaf5810d0f364d6ec4d044fd229e099ed8e
7
- data.tar.gz: 7c58ccadb6289b95ba65fdc27d34869e2c7c320eb8c2ecbfe33853e78a55cf1803fb6870598d54743bfe553c7e29ff2dd7d12a0281f7039313194aeff329161a
6
+ metadata.gz: 1e255c61c186000b3f8071555158bda3289b73e2bc4be110ca50403ac464bbbe1b86af3e6a0b302722f94f7568fe7cba4a8c4cf5734741359d86f38da0c4adf3
7
+ data.tar.gz: 8ff4d97a4355fc50a22080bee96331a7c0a662567faf5755abd79a1a59b7d4ad85395646aca1885b74eb5072891ecb38c5cf9f5415be0d35481df43fef1242da
data/.rubocop.yml ADDED
@@ -0,0 +1,26 @@
1
+ # This configuration was generated by `rubocop --auto-gen-config`
2
+ # on 2014-07-24 11:44:58 +0900 using RuboCop version 0.24.1.
3
+ # The point is for the user to remove these configuration records
4
+ # one by one as the offenses are removed from the code base.
5
+ # Note that changes in the inspected code, or installation of new
6
+ # versions of RuboCop, may require this file to be generated again.
7
+
8
+ AllCops:
9
+ Exclude:
10
+ - 'Guardfile'
11
+
12
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
13
+ Style/ClassAndModuleChildren:
14
+ EnforcedStyle: compact
15
+
16
+ Style/Documentation:
17
+ Enabled: false
18
+
19
+ # Configuration parameters: AllowURI.
20
+ Style/LineLength:
21
+ Max: 1_00
22
+
23
+ # Cop supports --auto-correct.
24
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
25
+ Style/StringLiterals:
26
+ EnforcedStyle: single_quotes
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.2
data/Guardfile ADDED
@@ -0,0 +1,10 @@
1
+ guard :rspec, all_after_pass: false, all_on_start: false do
2
+ watch(%r{spec/.+_spec\.rb$})
3
+ watch(%r{lib/(.+)\.rb$}) {|m| "spec/#{m[1]}_spec.rb"}
4
+ watch(%r{lib/(.+)/.+\.rb$}) {|m| "spec/#{m[1]}_spec.rb"}
5
+ end
6
+
7
+ guard :rubocop, all_on_start: false do
8
+ watch(%r{.+\.rb$})
9
+ watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
10
+ end
data/README.md CHANGED
@@ -18,14 +18,15 @@ api = Kintone::Api.new("example.cybozu.com", "Administrator", "cybozu")
18
18
  ```
19
19
 
20
20
  ### Supported API
21
- - Record retrieval
22
- - Record register
23
- - Record update
24
- - Record delete
25
- - Format retrieval
26
- - Permissions
21
+ - [Record retrieval](#record_retrieval)
22
+ - [Record register](#record_register)
23
+ - [Record update](#record_update)
24
+ - [Record delete](#record_delete)
25
+ - [Format retrieval](#format_retrieval)
26
+ - [Permissions](#permissions)
27
+ - [Space management]("space_management")
27
28
 
28
- ### Record retrieval
29
+ ### <a name="record_retrieval"> Record retrieval
29
30
 
30
31
  ```ruby
31
32
  # Record retrieval(Assign by Record Number)
@@ -38,7 +39,7 @@ query = "updated_time > \"2012-02-03T09:00:00+0900\" and updated_time < \"2012-0
38
39
  api.records.get(app, query, fields) # => {"records" => [{...}, ...]}
39
40
  ```
40
41
 
41
- ### Record register
42
+ ### <a name="record_register"> Record register
42
43
 
43
44
  ```ruby
44
45
  # Record register(single record)
@@ -52,7 +53,7 @@ records = [{"number" => {"value" => "123456"}}, {"number" => {"value" => "7890"}
52
53
  api.records.create(app, records) # => {"ids" => ["100", "101"]}
53
54
  ```
54
55
 
55
- ### Record update
56
+ ### <a name="record_update"> Record update
56
57
 
57
58
  ```ruby
58
59
  # Record update(single record)
@@ -66,21 +67,21 @@ records = [{"id" => 1, "string_multi" => {"value" => "abcdef"}}, {"id" => 2, "st
66
67
  api.records.update(app, records) # => {}
67
68
  ```
68
69
 
69
- ### Record delete
70
+ ### <a name="record_delete"> Record delete
70
71
 
71
72
  ```ruby
72
73
  app = 8; ids = [100, 80]
73
74
  api.records.delete(app, ids) # => {}
74
75
  ```
75
76
 
76
- ### Format retrieval
77
+ ### <a name="format_retrieval"> Format retrieval
77
78
 
78
79
  ```ruby
79
80
  app = 4
80
81
  api.form.get(app) # => {"properties" => [{...}, ...]}
81
82
  ```
82
83
 
83
- ### Permissions
84
+ ### <a name="permissions"> Permissions
84
85
 
85
86
  ```ruby
86
87
  # App
@@ -99,6 +100,27 @@ rights = [{"code" => "Single_line_text_0", "entities" => [{"entity" => {...}, "a
99
100
  api.field_acl.update(id, rights) # => {}
100
101
  ```
101
102
 
103
+ ### <a name="space_management"> Space management
104
+
105
+ ```ruby
106
+ # Space information reference
107
+ id = 1
108
+ api.space.get(id) # => { "id" => "1", "name" => "space", "defaultThread" => "3", "isPrivate" => true, ...}
109
+
110
+ # Create space
111
+ id = 1; name = "sample space"
112
+ members = [{"entity" => {"type" => "USER", "code" => "user1"}, "isAdmin": true}, ...]
113
+ api.template_space.create(id, name, members, is_guest: true, fixed_member: false) # => {"id" => "1"}
114
+
115
+ # Space body update
116
+ id = 1; body = "<b>awesome space!</b>"
117
+ api.space_body.update(id, body) # => {}
118
+
119
+ # Space delete
120
+ id = 1
121
+ api.space.delete(id) # => {}
122
+ ```
123
+
102
124
  ### Other examples
103
125
 
104
126
  ```ruby
@@ -118,4 +140,4 @@ api.post(url, body) # => {"ids" => ["100","101"]}
118
140
  api.guest(1).record.get(8, 100)
119
141
  ```
120
142
 
121
- see also [kintone developers](https://developers.kintone.com/)
143
+ see also [kintone developers](http://developers.kintone.com/)
data/Rakefile CHANGED
@@ -1 +1,9 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: :travis
9
+ task travis: [:spec, :rubocop]
data/kintone.gemspec CHANGED
@@ -1,28 +1,31 @@
1
1
  # coding: utf-8
2
+ # rubocop:disable Style/RegexpLiteral
2
3
  lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'kintone/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "kintone"
8
+ spec.name = 'kintone'
8
9
  spec.version = Kintone::VERSION
9
- spec.authors = ["Rikiya Kawakami"]
10
- spec.email = ["ricky.k.yang@gmail.com"]
11
- spec.summary = %q{kintone API client for Ruby.}
12
- spec.description = %q{kintone API client for Ruby.}
13
- spec.homepage = "https://github.com/jue58/kintone"
14
- spec.license = "MIT"
10
+ spec.authors = ['Rikiya Kawakami']
11
+ spec.email = ['ricky.k.yang@gmail.com']
12
+ spec.summary = 'kintone API client for Ruby.'
13
+ spec.description = 'kintone API client for Ruby.'
14
+ spec.homepage = 'https://github.com/jue58/kintone'
15
+ spec.license = 'MIT'
15
16
 
16
17
  spec.files = `git ls-files -z`.split("\x0")
17
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
20
+ spec.require_paths = ['lib']
20
21
 
21
- spec.add_runtime_dependency 'faraday', '~>0.8.9'
22
- spec.add_runtime_dependency 'faraday_middleware', '~>0.9.0'
22
+ spec.add_runtime_dependency 'faraday', '>=0.8.9'
23
+ spec.add_runtime_dependency 'faraday_middleware', '>=0.9.0'
23
24
 
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"
25
+ spec.add_development_dependency 'bundler', '~> 1.5'
26
+ spec.add_development_dependency 'rake'
27
+ spec.add_development_dependency 'rspec'
28
+ spec.add_development_dependency 'webmock'
29
+ spec.add_development_dependency 'guard-rspec'
30
+ spec.add_development_dependency 'guard-rubocop'
28
31
  end
data/lib/kintone.rb CHANGED
@@ -1,5 +1,5 @@
1
- require "kintone/version"
2
- require "kintone/api"
1
+ require 'kintone/version'
2
+ require 'kintone/api'
3
3
 
4
4
  module Kintone
5
5
  # Your code goes here...
data/lib/kintone/api.rb CHANGED
@@ -8,92 +8,106 @@ require 'kintone/command/form'
8
8
  require 'kintone/command/app_acl'
9
9
  require 'kintone/command/record_acl'
10
10
  require 'kintone/command/field_acl'
11
+ require 'kintone/command/template_space'
12
+ require 'kintone/command/space'
13
+ require 'kintone/command/space_body'
11
14
  require 'kintone/api/guest'
12
15
 
13
16
  class Kintone::Api
14
- BASE_PATH = "/k/v1/"
15
- COMMAND = "%s.json"
17
+ BASE_PATH = '/k/v1/'
18
+ COMMAND = '%s.json'
16
19
 
17
20
  def initialize(domain, user, password)
18
21
  token = Base64.encode64("#{user}:#{password}")
19
22
  @connection =
20
- Faraday.new(:url => "https://#{domain}",
21
- :headers => {"X-Cybozu-Authorization" => token},
22
- :ssl => false) do |builder|
23
+ Faraday.new(url: "https://#{domain}",
24
+ headers: { 'X-Cybozu-Authorization' => token },
25
+ ssl: false) do |builder|
23
26
  builder.adapter :net_http
24
27
  builder.request :url_encoded
25
28
  builder.response :json
26
- builder.response :logger
27
29
  end
28
30
  end
29
31
 
30
32
  def get_url(command)
31
- return BASE_PATH + (COMMAND % command)
33
+ BASE_PATH + (COMMAND % command)
32
34
  end
33
35
 
34
36
  def guest(space_id)
35
- return Kintone::Api::Guest.new(space_id, self)
37
+ Kintone::Api::Guest.new(space_id, self)
36
38
  end
37
39
 
38
- def get(url, params=nil)
40
+ def get(url, params = nil)
39
41
  response =
40
42
  @connection.get do |request|
41
43
  request.url url
42
44
  request.params = params
43
45
  end
44
- return response.body
46
+ response.body
45
47
  end
46
48
 
47
49
  def post(url, body)
48
50
  response =
49
51
  @connection.post do |request|
50
52
  request.url url
51
- request.headers["Content-Type"] = "application/json"
53
+ request.headers['Content-Type'] = 'application/json'
52
54
  request.body = body.to_json
53
55
  end
54
- return response.body
56
+ response.body
55
57
  end
56
58
 
57
59
  def put(url, body)
58
60
  response =
59
61
  @connection.put do |request|
60
62
  request.url url
61
- request.headers["Content-Type"] = "application/json"
63
+ request.headers['Content-Type'] = 'application/json'
62
64
  request.body = body.to_json
63
65
  end
64
- return response.body
66
+ response.body
65
67
  end
66
68
 
67
- def delete(url, params=nil)
69
+ def delete(url, params = nil)
68
70
  response =
69
71
  @connection.delete do |request|
70
72
  request.url url
71
73
  request.params = params
72
74
  end
73
- return response.body
75
+ response.body
74
76
  end
75
77
 
76
78
  def record
77
- return Kintone::Command::Record.new(self)
79
+ Kintone::Command::Record.new(self)
78
80
  end
79
81
 
80
82
  def records
81
- return Kintone::Command::Records.new(self)
83
+ Kintone::Command::Records.new(self)
82
84
  end
83
85
 
84
86
  def form
85
- return Kintone::Command::Form.new(self)
87
+ Kintone::Command::Form.new(self)
86
88
  end
87
89
 
88
90
  def app_acl
89
- return Kintone::Command::AppAcl.new(self)
91
+ Kintone::Command::AppAcl.new(self)
90
92
  end
91
93
 
92
94
  def record_acl
93
- return Kintone::Command::RecordAcl.new(self)
95
+ Kintone::Command::RecordAcl.new(self)
94
96
  end
95
97
 
96
98
  def field_acl
97
- return Kintone::Command::FieldAcl.new(self)
99
+ Kintone::Command::FieldAcl.new(self)
100
+ end
101
+
102
+ def template_space
103
+ Kintone::Command::TemplateSpace.new(self)
104
+ end
105
+
106
+ def space
107
+ Kintone::Command::Space.new(self)
108
+ end
109
+
110
+ def space_body
111
+ Kintone::Command::SpaceBody.new(self)
98
112
  end
99
113
  end
@@ -5,7 +5,7 @@ class Kintone::Api
5
5
  class Guest
6
6
  extend Forwardable
7
7
 
8
- GUEST_PATH = "/k/guest/%s/v1/"
8
+ GUEST_PATH = '/k/guest/%s/v1/'
9
9
 
10
10
  def initialize(space_id, api)
11
11
  @api = api
@@ -13,31 +13,39 @@ class Kintone::Api
13
13
  end
14
14
 
15
15
  def get_url(command)
16
- return @guest_path + (COMMAND % command)
16
+ @guest_path + (COMMAND % command)
17
17
  end
18
18
 
19
19
  def record
20
- return Kintone::Command::Record.new(self)
20
+ Kintone::Command::Record.new(self)
21
21
  end
22
22
 
23
23
  def records
24
- return Kintone::Command::Records.new(self)
24
+ Kintone::Command::Records.new(self)
25
25
  end
26
26
 
27
27
  def form
28
- return Kintone::Command::Form.new(self)
28
+ Kintone::Command::Form.new(self)
29
29
  end
30
30
 
31
31
  def app_acl
32
- return Kintone::Command::AppAcl.new(self)
32
+ Kintone::Command::AppAcl.new(self)
33
33
  end
34
34
 
35
35
  def record_acl
36
- return Kintone::Command::RecordAcl.new(self)
36
+ Kintone::Command::RecordAcl.new(self)
37
37
  end
38
38
 
39
39
  def field_acl
40
- return Kintone::Command::FieldAcl.new(self)
40
+ Kintone::Command::FieldAcl.new(self)
41
+ end
42
+
43
+ def space
44
+ Kintone::Command::Space.new(self)
45
+ end
46
+
47
+ def space_body
48
+ Kintone::Command::SpaceBody.new(self)
41
49
  end
42
50
 
43
51
  def_delegators :@api, :get, :post, :put, :delete
@@ -1,3 +1,12 @@
1
- module Kintone::Command
2
-
1
+ require 'kintone/api'
2
+
3
+ class Kintone::Command
4
+ def self.path
5
+ '/'
6
+ end
7
+
8
+ def initialize(api)
9
+ @api = api
10
+ @url = @api.get_url(self.class.path)
11
+ end
3
12
  end
@@ -1,15 +1,11 @@
1
1
  require 'kintone/command'
2
- require 'kintone/api'
3
2
 
4
- class Kintone::Command::AppAcl
5
- PATH = "app/acl"
6
-
7
- def initialize(api)
8
- @api = api
9
- @url = @api.get_url(PATH)
3
+ class Kintone::Command::AppAcl < Kintone::Command
4
+ def self.path
5
+ 'app/acl'
10
6
  end
11
7
 
12
8
  def update(app, rights)
13
- @api.put(@url, {:app => app, :rights => rights})
9
+ @api.put(@url, app: app, rights: rights)
14
10
  end
15
11
  end