chino_ruby 1.1 → 1.2
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.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/Gemfile.lock +4 -4
- data/README.md +14 -1
- data/chino_ruby.gemspec +2 -2
- data/config-chino.yml +2 -2
- data/lib/chino_ruby.rb +198 -415
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8246d2d099a9a9bd2523503b198b2364849ea8c
|
4
|
+
data.tar.gz: 9b31b4de7d2b0290081af890459fe577ab199c6f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d41ed00652c5a4e2f50b71295d03170a385dd94439978594b63706d7887081eba5d5cc74886c0a61be540e12239f9d02807ed77b7c14fb39e2e37dc97157e9e
|
7
|
+
data.tar.gz: 5f5f2d6afc96890919018dfda68dafaf4ae469ab75b69aae326b27c8ae776255da09aea02522cc7ad52745fea510e925225f41338b7c387f4fad3cfc2c1dd1a1
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
chino_ruby (1.
|
4
|
+
chino_ruby (1.2)
|
5
5
|
listen (~> 3.0)
|
6
6
|
rails (~> 5.1, >= 5.1.1)
|
7
7
|
|
@@ -97,8 +97,8 @@ GEM
|
|
97
97
|
method_source
|
98
98
|
rake (>= 0.8.7)
|
99
99
|
thor (>= 0.18.1, < 2.0)
|
100
|
-
rake (
|
101
|
-
rb-fsevent (0.10.
|
100
|
+
rake (12.0.0)
|
101
|
+
rb-fsevent (0.10.2)
|
102
102
|
rb-inotify (0.9.10)
|
103
103
|
ffi (>= 0.5.0, < 2)
|
104
104
|
ruby_dep (1.5.0)
|
@@ -126,7 +126,7 @@ PLATFORMS
|
|
126
126
|
DEPENDENCIES
|
127
127
|
bundler (~> 1.15)
|
128
128
|
chino_ruby!
|
129
|
-
rake (~>
|
129
|
+
rake (~> 12.0.0)
|
130
130
|
spring (~> 0)
|
131
131
|
test-unit (~> 3.1.2)
|
132
132
|
|
data/README.md
CHANGED
@@ -48,7 +48,20 @@ content["test_integer"] = 123
|
|
48
48
|
|
49
49
|
@doc = @client.documents.create_document(@schema.schema_id, content)
|
50
50
|
```
|
51
|
-
|
51
|
+
## Running the Tests
|
52
|
+
You have to run the following commands in the terminal in order to run the tests:
|
53
|
+
```
|
54
|
+
$ gem install bundler
|
55
|
+
```
|
56
|
+
```
|
57
|
+
$ bundle install
|
58
|
+
```
|
59
|
+
```
|
60
|
+
$ cd test
|
61
|
+
```
|
62
|
+
```
|
63
|
+
$ bundle exec ruby sdk_test.rb
|
64
|
+
```
|
52
65
|
## Development
|
53
66
|
|
54
67
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/chino_ruby.gemspec
CHANGED
@@ -5,7 +5,7 @@ require "chino_ruby/version"
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "chino_ruby"
|
8
|
-
spec.version = '1.
|
8
|
+
spec.version = '1.2'
|
9
9
|
spec.authors = ["Paolo Prem"]
|
10
10
|
spec.email = ["prempaolo@gmail.com"]
|
11
11
|
|
@@ -34,7 +34,7 @@ Gem::Specification.new do |spec|
|
|
34
34
|
spec.require_paths = ["lib"]
|
35
35
|
|
36
36
|
spec.add_development_dependency "bundler", '~> 1.15'
|
37
|
-
spec.add_development_dependency "rake", '~>
|
37
|
+
spec.add_development_dependency "rake", '~> 12.0.0'
|
38
38
|
spec.add_dependency "listen", '~> 3.0'
|
39
39
|
spec.add_runtime_dependency 'rails', '~> 5.1', '>= 5.1.1'
|
40
40
|
spec.add_development_dependency 'test-unit', "~> 3.1.2"
|
data/config-chino.yml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
development:
|
2
2
|
url: https://kube.chino.io/v1
|
3
|
-
customer_id:
|
4
|
-
customer_key:
|
3
|
+
customer_id: 41dc5f7a-90da-4ad2-8867-d1357758b9d6
|
4
|
+
customer_key: e4df0a03-fb63-43a4-8a6c-259cce55d45e
|
5
5
|
|
6
6
|
development_old:
|
7
7
|
url: https://api.test.chino.io/v1
|
data/lib/chino_ruby.rb
CHANGED
@@ -6,65 +6,35 @@ require "json"
|
|
6
6
|
require "yaml"
|
7
7
|
require "digest"
|
8
8
|
|
9
|
+
# Module for constant values
|
9
10
|
module ChinoRuby
|
10
11
|
QUERY_DEFAULT_LIMIT = 100
|
11
12
|
end
|
12
13
|
|
13
|
-
class ChinoAPI
|
14
|
-
|
15
|
-
attr_accessor :applications, :auth, :repositories, :schemas, :documents, :user_schemas, :users, :groups, :collections, :permissions, :search, :blobs
|
16
|
-
|
17
|
-
def initialize(customer_id, customer_key, host_url)
|
18
|
-
check_string(customer_id)
|
19
|
-
check_string(customer_key)
|
20
|
-
check_string(host_url)
|
21
|
-
@customer_id = customer_id
|
22
|
-
@customer_key = customer_key
|
23
|
-
@host_url = host_url
|
24
|
-
@applications = Applications.new(@customer_id, @customer_key, @host_url)
|
25
|
-
@auth = Auth.new(@customer_id, @customer_key, @host_url)
|
26
|
-
@repositories = Repositories.new(@customer_id, @customer_key, @host_url)
|
27
|
-
@schemas = Schemas.new(@customer_id, @customer_key, @host_url)
|
28
|
-
@documents = Documents.new(@customer_id, @customer_key, @host_url)
|
29
|
-
@user_schemas = UserSchemas.new(@customer_id, @customer_key, @host_url)
|
30
|
-
@users = Users.new(@customer_id, @customer_key, @host_url)
|
31
|
-
@groups = Groups.new(@customer_id, @customer_key, @host_url)
|
32
|
-
@collections = Collections.new(@customer_id, @customer_key, @host_url)
|
33
|
-
@permissions = Permissions.new(@customer_id, @customer_key, @host_url)
|
34
|
-
@search = Search.new(@customer_id, @customer_key, @host_url)
|
35
|
-
@blobs = Blobs.new(@customer_id, @customer_key, @host_url)
|
36
|
-
end
|
37
|
-
|
38
|
-
def check_string(value)
|
39
|
-
if not value.is_a?(String)
|
40
|
-
raise ArgumentError, "{#value} must be a String, got #{value.inspect}"
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def initUser()
|
45
|
-
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
14
|
class CheckValues
|
15
|
+
|
16
|
+
# This function is used to check if a parameter passed to a function is a string, otherwise it raises an error
|
50
17
|
def check_string(value)
|
51
18
|
if not value.is_a?(String)
|
52
19
|
raise ArgumentError, "{#value} must be a String, got #{value.inspect}"
|
53
20
|
end
|
54
21
|
end
|
55
22
|
|
23
|
+
# This function is used to check if a parameter passed to a function is an integer, otherwise it raises an error
|
56
24
|
def check_int(value)
|
57
25
|
if not value.is_a?(Integer)
|
58
26
|
raise ArgumentError, "{#value} must be a Int, got #{value.inspect}"
|
59
27
|
end
|
60
28
|
end
|
61
29
|
|
30
|
+
# This function is used to check if a parameter passed to a function is a boolean, otherwise it raises an error
|
62
31
|
def check_boolean(value)
|
63
32
|
if not !!value == value
|
64
33
|
raise ArgumentError, "{#value} must be a Boolean, got #{value.inspect}"
|
65
34
|
end
|
66
35
|
end
|
67
36
|
|
37
|
+
# This function is used to check if a parameter passed to a function can be converted to json, otherwise it raises an error
|
68
38
|
def check_json(value)
|
69
39
|
if not value.respond_to?(:to_json)
|
70
40
|
raise ArgumentError, "{#value} cannot be converted to json!"
|
@@ -72,9 +42,50 @@ class CheckValues
|
|
72
42
|
end
|
73
43
|
end
|
74
44
|
|
45
|
+
# Class which contains every Chino.io resource as objects. In this way if you create a 'client' variable of this class,
|
46
|
+
# it will contain every function for the creation, update, retrieval... of every resource.
|
47
|
+
# Every function is easily accessible as follow:
|
48
|
+
# name_of_the_client_variable.name_of_the_resource.name_of_the_function()
|
49
|
+
# Example of the creation of a Repository
|
50
|
+
# @client = ChinoAPI.new(...)
|
51
|
+
# @client.repositories.create_repository(...)
|
52
|
+
class ChinoAPI < CheckValues
|
53
|
+
|
54
|
+
attr_accessor :applications, :auth, :repositories, :schemas, :documents, :user_schemas, :users, :groups, :collections, :permissions, :search, :blobs
|
55
|
+
|
56
|
+
# Use this function to initialize your client variable
|
57
|
+
# * customer_id: your customer id value
|
58
|
+
# * customer_key: your customer key value
|
59
|
+
# * host_url: the url of the server, use 'https://api.test.chino.io/v1' for development and 'https://api.chino.io/v1' for the production
|
60
|
+
def initialize(customer_id, customer_key, host_url)
|
61
|
+
check_string(customer_id)
|
62
|
+
check_string(customer_key)
|
63
|
+
check_string(host_url)
|
64
|
+
@customer_id = customer_id
|
65
|
+
@customer_key = customer_key
|
66
|
+
@host_url = host_url
|
67
|
+
@applications = Applications.new(@customer_id, @customer_key, @host_url)
|
68
|
+
@auth = Auth.new(@customer_id, @customer_key, @host_url)
|
69
|
+
@repositories = Repositories.new(@customer_id, @customer_key, @host_url)
|
70
|
+
@schemas = Schemas.new(@customer_id, @customer_key, @host_url)
|
71
|
+
@documents = Documents.new(@customer_id, @customer_key, @host_url)
|
72
|
+
@user_schemas = UserSchemas.new(@customer_id, @customer_key, @host_url)
|
73
|
+
@users = Users.new(@customer_id, @customer_key, @host_url)
|
74
|
+
@groups = Groups.new(@customer_id, @customer_key, @host_url)
|
75
|
+
@collections = Collections.new(@customer_id, @customer_key, @host_url)
|
76
|
+
@permissions = Permissions.new(@customer_id, @customer_key, @host_url)
|
77
|
+
@search = Search.new(@customer_id, @customer_key, @host_url)
|
78
|
+
@blobs = Blobs.new(@customer_id, @customer_key, @host_url)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# Class which defines the fields for the creation of a Schema or a UserSchema
|
75
83
|
class Field < CheckValues
|
76
84
|
attr_accessor :type, :name, :indexed
|
77
85
|
|
86
|
+
# * type: type of the field in the Schema/UserSchema. Ex: 'string'
|
87
|
+
# * name: name of the field in the Schema/UserSchema
|
88
|
+
# * indexed: if true, the field will be indexed on the server. That means it can be used to make a search request
|
78
89
|
def initialize(type, name, indexed)
|
79
90
|
check_string(type)
|
80
91
|
check_string(name)
|
@@ -84,13 +95,16 @@ class Field < CheckValues
|
|
84
95
|
self.indexed = indexed
|
85
96
|
end
|
86
97
|
|
98
|
+
# Returns the values as a json
|
87
99
|
def to_json
|
88
100
|
return {"type": type, "name": name, "indexed": indexed}.to_json
|
89
101
|
end
|
90
102
|
end
|
91
103
|
|
104
|
+
# Base class of every resource class. It contains the functions for the GET, POST, PUT, PATCH and DELETE requests
|
92
105
|
class ChinoBaseAPI < CheckValues
|
93
106
|
|
107
|
+
# Used to inizialize a customer or a user. If you want to authenticate a user, simply pass "" as the customer_id
|
94
108
|
def initialize(customer_id, customer_key, host_url)
|
95
109
|
if customer_id == ""
|
96
110
|
@customer_id = "Bearer "
|
@@ -100,62 +114,35 @@ class ChinoBaseAPI < CheckValues
|
|
100
114
|
@host_url = host_url
|
101
115
|
end
|
102
116
|
|
103
|
-
|
117
|
+
#returns the uri with the proper params if specified
|
118
|
+
def return_uri(path, limit=nil, offset=nil, full_document=nil)
|
104
119
|
uri = URI(@host_url+path)
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
def return_uri_full_document(path, limit, offset)
|
111
|
-
uri = URI(@host_url+path)
|
112
|
-
params = { :"full_document" => true, :"limit" => limit, :"offset" => offset}
|
113
|
-
uri.query = URI.encode_www_form(params)
|
114
|
-
uri
|
115
|
-
end
|
116
|
-
|
117
|
-
def return_uri(path)
|
118
|
-
uri = URI(@host_url+path)
|
119
|
-
uri
|
120
|
-
end
|
121
|
-
|
122
|
-
def get_resource(path)
|
123
|
-
check_string(path)
|
124
|
-
uri = return_uri(path)
|
125
|
-
req = Net::HTTP::Get.new(uri.path)
|
126
|
-
if @customer_id == "Bearer "
|
127
|
-
req.add_field("Authorization", @customer_id+@customer_key)
|
120
|
+
if limit!=nil && offset!=nil
|
121
|
+
if full_document!=nil
|
122
|
+
params = { :"full_document" => true, :"limit" => limit, :"offset" => offset}
|
123
|
+
uri.query = URI.encode_www_form(params)
|
128
124
|
else
|
129
|
-
|
125
|
+
params = { "limit" => limit, :"offset" => offset}
|
126
|
+
uri.query = URI.encode_www_form(params)
|
127
|
+
end
|
130
128
|
end
|
131
|
-
|
132
|
-
http.request(req)
|
133
|
-
}
|
134
|
-
parse_response(res)['data']
|
129
|
+
uri
|
135
130
|
end
|
136
131
|
|
137
|
-
|
132
|
+
#base function to GET a resource with the proper params if specified
|
133
|
+
def get_resource(path, limit=nil, offset=nil, full_document=nil)
|
138
134
|
check_string(path)
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
135
|
+
if (limit==nil) && (offset==nil)
|
136
|
+
uri = return_uri(path)
|
137
|
+
elsif full_document==nil
|
138
|
+
uri = return_uri(path, limit, offset)
|
139
|
+
else
|
140
|
+
uri = return_uri(path, limit, offset, full_document)
|
145
141
|
end
|
146
|
-
|
147
|
-
http.request(req)
|
148
|
-
}
|
149
|
-
parse_response(res)['data']
|
150
|
-
end
|
151
|
-
|
152
|
-
def get_full_content_documents(path, limit, offset)
|
153
|
-
check_string(path)
|
154
|
-
uri = return_uri_full_document(path, limit, offset)
|
155
|
-
req = Net::HTTP::Get.new(uri)
|
142
|
+
req = Net::HTTP::Get.new(uri.path)
|
156
143
|
if @customer_id == "Bearer "
|
157
144
|
req.add_field("Authorization", @customer_id+@customer_key)
|
158
|
-
|
145
|
+
else
|
159
146
|
req.basic_auth @customer_id, @customer_key
|
160
147
|
end
|
161
148
|
res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => true) {|http|
|
@@ -163,46 +150,44 @@ class ChinoBaseAPI < CheckValues
|
|
163
150
|
}
|
164
151
|
parse_response(res)['data']
|
165
152
|
end
|
166
|
-
|
167
|
-
|
153
|
+
|
154
|
+
#base function to POST a resource with the proper params if specified
|
155
|
+
def post_resource(path, data=nil, limit=nil, offset=nil, full_document=nil)
|
168
156
|
check_string(path)
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
157
|
+
if (limit==nil) && (offset==nil)
|
158
|
+
uri = return_uri(path)
|
159
|
+
elsif full_document==nil
|
160
|
+
uri = return_uri(path, limit, offset)
|
161
|
+
else
|
162
|
+
uri = return_uri(path, limit, offset, full_document)
|
175
163
|
end
|
176
|
-
req.body = data
|
177
|
-
res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => true) {|http|
|
178
|
-
http.request(req)
|
179
|
-
}
|
180
|
-
parse_response(res)['data']
|
181
|
-
end
|
182
|
-
|
183
|
-
def post_resource_with_params(path, data, limit, offset)
|
184
|
-
check_string(path)
|
185
|
-
uri = return_uri_with_params(path, limit, offset)
|
186
164
|
req = Net::HTTP::Post.new(uri.path)
|
187
165
|
if @customer_id == "Bearer "
|
188
166
|
req.add_field("Authorization", @customer_id+@customer_key)
|
189
|
-
|
167
|
+
else
|
190
168
|
req.basic_auth @customer_id, @customer_key
|
191
169
|
end
|
192
|
-
|
170
|
+
if data!=nil
|
171
|
+
req.body = data
|
172
|
+
end
|
193
173
|
res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => true) {|http|
|
194
174
|
http.request(req)
|
195
175
|
}
|
196
|
-
|
176
|
+
if data!=nil
|
177
|
+
parse_response(res)['data']
|
178
|
+
else
|
179
|
+
JSON.parse(parse_response(res).to_json)['result']
|
180
|
+
end
|
197
181
|
end
|
198
182
|
|
183
|
+
#base function to POST a resource with string result
|
199
184
|
def post_resource_with_string_result(path, data)
|
200
185
|
check_string(path)
|
201
186
|
uri = return_uri(path)
|
202
187
|
req = Net::HTTP::Post.new(uri.path)
|
203
188
|
if @customer_id == "Bearer "
|
204
189
|
req.add_field("Authorization", @customer_id+@customer_key)
|
205
|
-
|
190
|
+
else
|
206
191
|
req.basic_auth @customer_id, @customer_key
|
207
192
|
end
|
208
193
|
req.body = data
|
@@ -211,29 +196,15 @@ class ChinoBaseAPI < CheckValues
|
|
211
196
|
}
|
212
197
|
JSON.parse(parse_response(res).to_json)['result']
|
213
198
|
end
|
214
|
-
|
215
|
-
|
216
|
-
check_string(path)
|
217
|
-
uri = return_uri(path)
|
218
|
-
req = Net::HTTP::Post.new(uri.path)
|
219
|
-
if @customer_id == "Bearer "
|
220
|
-
req.add_field("Authorization", @customer_id+@customer_key)
|
221
|
-
else
|
222
|
-
req.basic_auth @customer_id, @customer_key
|
223
|
-
end
|
224
|
-
res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => true) {|http|
|
225
|
-
http.request(req)
|
226
|
-
}
|
227
|
-
JSON.parse(parse_response(res).to_json)['result']
|
228
|
-
end
|
229
|
-
|
199
|
+
|
200
|
+
#base function to PUT a resource
|
230
201
|
def put_resource(path, data)
|
231
202
|
check_string(path)
|
232
203
|
uri = return_uri(path)
|
233
204
|
req = Net::HTTP::Put.new(uri.path)
|
234
205
|
if @customer_id == "Bearer "
|
235
206
|
req.add_field("Authorization", @customer_id+@customer_key)
|
236
|
-
|
207
|
+
else
|
237
208
|
req.basic_auth @customer_id, @customer_key
|
238
209
|
end
|
239
210
|
req.body = data
|
@@ -243,13 +214,14 @@ class ChinoBaseAPI < CheckValues
|
|
243
214
|
parse_response(res)['data']
|
244
215
|
end
|
245
216
|
|
217
|
+
#base function to PATCH a resource
|
246
218
|
def patch_resource(path, data)
|
247
219
|
check_string(path)
|
248
220
|
uri = return_uri(path)
|
249
221
|
req = Net::HTTP::Patch.new(uri.path)
|
250
222
|
if @customer_id == "Bearer "
|
251
223
|
req.add_field("Authorization", @customer_id+@customer_key)
|
252
|
-
|
224
|
+
else
|
253
225
|
req.basic_auth @customer_id, @customer_key
|
254
226
|
end
|
255
227
|
req.body = data
|
@@ -259,18 +231,19 @@ class ChinoBaseAPI < CheckValues
|
|
259
231
|
parse_response(res)['data']
|
260
232
|
end
|
261
233
|
|
234
|
+
#base function to DELETE a resource
|
262
235
|
def delete_resource(path, force)
|
263
236
|
check_string(path)
|
264
237
|
check_boolean(force)
|
265
238
|
if force
|
266
239
|
uri = return_uri(path+"?force=true")
|
267
|
-
|
240
|
+
else
|
268
241
|
uri = return_uri(path)
|
269
242
|
end
|
270
243
|
req = Net::HTTP::Delete.new(uri)
|
271
244
|
if @customer_id == "Bearer "
|
272
245
|
req.add_field("Authorization", @customer_id+@customer_key)
|
273
|
-
|
246
|
+
else
|
274
247
|
req.basic_auth @customer_id, @customer_key
|
275
248
|
end
|
276
249
|
res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => true) {|http|
|
@@ -279,6 +252,7 @@ class ChinoBaseAPI < CheckValues
|
|
279
252
|
JSON.parse(parse_response(res).to_json)['result']
|
280
253
|
end
|
281
254
|
|
255
|
+
#base function to parse the response and raise "chino" errors if problems occurred
|
282
256
|
def parse_response(response, raw=false)
|
283
257
|
if response.is_a?(Net::HTTPServerError)
|
284
258
|
raise ChinoError.new("Chino Server Error: #{response} - #{response.body}", response)
|
@@ -312,6 +286,7 @@ end
|
|
312
286
|
|
313
287
|
#------------------------------CHINO ERRORS-----------------------------------#
|
314
288
|
|
289
|
+
#Class for defining common errors
|
315
290
|
class ChinoError < RuntimeError
|
316
291
|
attr_accessor :http_response, :error, :user_error
|
317
292
|
|
@@ -327,25 +302,10 @@ class ChinoError < RuntimeError
|
|
327
302
|
end
|
328
303
|
end
|
329
304
|
|
305
|
+
#Class for defining auth errors
|
330
306
|
class ChinoAuthError < ChinoError
|
331
307
|
end
|
332
308
|
|
333
|
-
class ChinoErrorModel
|
334
|
-
include ActiveModel::Serializers::JSON
|
335
|
-
|
336
|
-
attr_accessor :message, :data, :result, :result_code
|
337
|
-
|
338
|
-
def attributes=(hash)
|
339
|
-
hash.each do |key, value|
|
340
|
-
send("#{key}=", value)
|
341
|
-
end
|
342
|
-
end
|
343
|
-
|
344
|
-
def attributes
|
345
|
-
instance_values
|
346
|
-
end
|
347
|
-
end
|
348
|
-
|
349
309
|
#------------------------------APPLICATIONS-----------------------------------#
|
350
310
|
|
351
311
|
class Application
|
@@ -389,25 +349,13 @@ class Applications < ChinoBaseAPI
|
|
389
349
|
app
|
390
350
|
end
|
391
351
|
|
392
|
-
def list_applications()
|
352
|
+
def list_applications(limit=nil, offset=nil)
|
393
353
|
apps = GetApplicationsResponse.new
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
app = Application.new
|
399
|
-
app.app_id = a['app_id']
|
400
|
-
app.app_name = a['app_name']
|
401
|
-
apps.applications.push(app)
|
354
|
+
if limit==nil && offset==nil
|
355
|
+
apps.from_json(get_resource("/auth/applications", ChinoRuby::QUERY_DEFAULT_LIMIT, 0).to_json)
|
356
|
+
else
|
357
|
+
apps.from_json(get_resource("/auth/applications", limit, offset).to_json)
|
402
358
|
end
|
403
|
-
apps
|
404
|
-
end
|
405
|
-
|
406
|
-
def list_applications_with_params(limit, offset)
|
407
|
-
check_int(limit)
|
408
|
-
check_int(offset)
|
409
|
-
apps = GetApplicationsResponse.new
|
410
|
-
apps.from_json(get_resource_with_params("/auth/applications", limit, offset).to_json)
|
411
359
|
as = apps.applications
|
412
360
|
apps.applications = []
|
413
361
|
as.each do |a|
|
@@ -467,7 +415,7 @@ end
|
|
467
415
|
|
468
416
|
class Auth < ChinoBaseAPI
|
469
417
|
|
470
|
-
def
|
418
|
+
def login_password(username, password, application_id, application_secret)
|
471
419
|
check_string(username)
|
472
420
|
check_string(password)
|
473
421
|
check_string(application_id)
|
@@ -484,7 +432,7 @@ class Auth < ChinoBaseAPI
|
|
484
432
|
usr
|
485
433
|
end
|
486
434
|
|
487
|
-
def
|
435
|
+
def login_authentication_code(code, redirect_url, application_id, application_secret)
|
488
436
|
check_string(code)
|
489
437
|
check_string(redirect_url)
|
490
438
|
check_string(application_id)
|
@@ -501,7 +449,7 @@ class Auth < ChinoBaseAPI
|
|
501
449
|
usr
|
502
450
|
end
|
503
451
|
|
504
|
-
def
|
452
|
+
def refresh_token(refresh_token, application_id, application_secret)
|
505
453
|
check_string(refresh_token)
|
506
454
|
check_string(application_id)
|
507
455
|
check_string(application_secret)
|
@@ -576,24 +524,13 @@ class Repositories < ChinoBaseAPI
|
|
576
524
|
repo
|
577
525
|
end
|
578
526
|
|
579
|
-
def list_repositories()
|
527
|
+
def list_repositories(limit=nil, offset=nil)
|
580
528
|
repos = GetRepositoriesResponse.new
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
repo = Repository.new
|
586
|
-
repo.from_json(r.to_json)
|
587
|
-
repos.repositories.push(repo)
|
529
|
+
if limit==nil && offset==nil
|
530
|
+
repos.from_json(get_resource("/repositories", ChinoRuby::QUERY_DEFAULT_LIMIT, 0).to_json)
|
531
|
+
else
|
532
|
+
repos.from_json(get_resource("/repositories", limit, offset).to_json)
|
588
533
|
end
|
589
|
-
repos
|
590
|
-
end
|
591
|
-
|
592
|
-
def list_repositories_with_params(limit, offset)
|
593
|
-
check_int(limit)
|
594
|
-
check_int(offset)
|
595
|
-
repos = GetRepositoriesResponse.new
|
596
|
-
repos.from_json(get_resource_with_params("/repositories", limit, offset).to_json)
|
597
534
|
rs = repos.repositories
|
598
535
|
repos.repositories = []
|
599
536
|
rs.each do |r|
|
@@ -679,24 +616,13 @@ class UserSchemas < ChinoBaseAPI
|
|
679
616
|
u
|
680
617
|
end
|
681
618
|
|
682
|
-
def list_user_schemas()
|
619
|
+
def list_user_schemas(limit=nil, offset=nil)
|
683
620
|
schemas = GetUserSchemasResponse.new
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
schema = UserSchema.new
|
689
|
-
schema.from_json(u.to_json)
|
690
|
-
schemas.user_schemas.push(schema)
|
621
|
+
if limit==nil && offset==nil
|
622
|
+
schemas.from_json(get_resource("/user_schemas", ChinoRuby::QUERY_DEFAULT_LIMIT, 0).to_json)
|
623
|
+
else
|
624
|
+
schemas.from_json(get_resource("/user_schemas", limit, offset).to_json)
|
691
625
|
end
|
692
|
-
schemas
|
693
|
-
end
|
694
|
-
|
695
|
-
def list_applications_with_params(limit, offset)
|
696
|
-
check_int(limit)
|
697
|
-
check_int(offset)
|
698
|
-
schemas = GetUserSchemasResponse.new
|
699
|
-
schemas.from_json(get_resource_with_params("/user_schemas", limit, offset).to_json)
|
700
626
|
us = schemas.user_schemas
|
701
627
|
schemas.user_schemas = []
|
702
628
|
us.each do |u|
|
@@ -780,26 +706,14 @@ class Users < ChinoBaseAPI
|
|
780
706
|
u
|
781
707
|
end
|
782
708
|
|
783
|
-
def list_users(user_schema_id)
|
709
|
+
def list_users(user_schema_id, limit=nil, offset=nil)
|
784
710
|
check_string(user_schema_id)
|
785
711
|
users = GetUsersResponse.new
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
user = User.new
|
791
|
-
user.from_json(u.to_json)
|
792
|
-
users.users.push(user)
|
712
|
+
if limit==nil && offset==nil
|
713
|
+
users.from_json(get_resource("/user_schemas/#{user_schema_id}/users", ChinoRuby::QUERY_DEFAULT_LIMIT, 0).to_json)
|
714
|
+
else
|
715
|
+
users.from_json(get_resource("/user_schemas/#{user_schema_id}/users", limit, offset).to_json)
|
793
716
|
end
|
794
|
-
users
|
795
|
-
end
|
796
|
-
|
797
|
-
def list_users_with_params(user_schema_id, limit, offset)
|
798
|
-
check_string(user_schema_id)
|
799
|
-
check_int(limit)
|
800
|
-
check_int(offset)
|
801
|
-
users = GetUsersResponse.new
|
802
|
-
users.from_json(get_resource_with_params("/user_schemas/#{user_schema_id}/users", limit, offset).to_json)
|
803
717
|
us = users.users
|
804
718
|
users.users = []
|
805
719
|
us.each do |u|
|
@@ -895,24 +809,13 @@ class Groups < ChinoBaseAPI
|
|
895
809
|
g
|
896
810
|
end
|
897
811
|
|
898
|
-
def list_groups()
|
812
|
+
def list_groups(limit=nil, offset=nil)
|
899
813
|
groups = GetGroupsResponse.new
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
group = Group.new
|
905
|
-
group.from_json(g.to_json)
|
906
|
-
groups.groups.push(group)
|
814
|
+
if limit==nil && offset==nil
|
815
|
+
groups.from_json(get_resource("/groups", ChinoRuby::QUERY_DEFAULT_LIMIT, 0).to_json)
|
816
|
+
else
|
817
|
+
groups.from_json(get_resource("/groups", limit, offset).to_json)
|
907
818
|
end
|
908
|
-
groups
|
909
|
-
end
|
910
|
-
|
911
|
-
def list_groups_with_params(limit, offset)
|
912
|
-
check_int(limit)
|
913
|
-
check_int(offset)
|
914
|
-
groups = GetGroupsResponse.new
|
915
|
-
groups.from_json(get_resource_with_params("/groups", limit, offset).to_json)
|
916
819
|
gs = groups.groups
|
917
820
|
groups.groups = []
|
918
821
|
gs.each do |g|
|
@@ -951,13 +854,13 @@ class Groups < ChinoBaseAPI
|
|
951
854
|
def add_user_to_group(user_id, group_id)
|
952
855
|
check_string(group_id)
|
953
856
|
check_string(user_id)
|
954
|
-
|
857
|
+
post_resource("/groups/#{group_id}/users/#{user_id}")
|
955
858
|
end
|
956
859
|
|
957
860
|
def add_user_schema_to_group(user_schema_id, group_id)
|
958
861
|
check_string(group_id)
|
959
862
|
check_string(user_schema_id)
|
960
|
-
|
863
|
+
post_resource("/groups/#{group_id}/user_schemas/#{user_schema_id}")
|
961
864
|
end
|
962
865
|
|
963
866
|
def remove_user_from_group(user_id, group_id)
|
@@ -1020,26 +923,14 @@ class Schemas < ChinoBaseAPI
|
|
1020
923
|
s
|
1021
924
|
end
|
1022
925
|
|
1023
|
-
def list_schemas(repository_id)
|
926
|
+
def list_schemas(repository_id, limit=nil, offset=nil)
|
1024
927
|
check_string(repository_id)
|
1025
928
|
schemas = GetSchemasResponse.new
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
schema = Schema.new
|
1031
|
-
schema.from_json(s.to_json)
|
1032
|
-
schemas.schemas.push(schema)
|
929
|
+
if limit==nil && offset==nil
|
930
|
+
schemas.from_json(get_resource("/repositories/#{repository_id}/schemas", ChinoRuby::QUERY_DEFAULT_LIMIT, 0).to_json)
|
931
|
+
else
|
932
|
+
schemas.from_json(get_resource("/repositories/#{repository_id}/schemas", limit, offset).to_json)
|
1033
933
|
end
|
1034
|
-
schemas
|
1035
|
-
end
|
1036
|
-
|
1037
|
-
def list_applications_with_params(repository_id, limit, offset)
|
1038
|
-
check_string(repository_id)
|
1039
|
-
check_int(limit)
|
1040
|
-
check_int(offset)
|
1041
|
-
schemas = GetSchemasResponse.new
|
1042
|
-
schemas.from_json(get_resource_with_params("/repositories/#{repository_id}/schemas", limit, offset).to_json)
|
1043
934
|
ss = schemas.schemas
|
1044
935
|
schemas.schemas = []
|
1045
936
|
ss.each do |s|
|
@@ -1128,35 +1019,22 @@ class Documents < ChinoBaseAPI
|
|
1128
1019
|
d
|
1129
1020
|
end
|
1130
1021
|
|
1131
|
-
def list_documents(schema_id, full_document)
|
1022
|
+
def list_documents(schema_id, full_document, limit=nil, offset=nil)
|
1132
1023
|
check_string(schema_id)
|
1133
1024
|
check_boolean(full_document)
|
1134
1025
|
docs = GetDocumentsResponse.new
|
1135
|
-
if
|
1136
|
-
|
1137
|
-
|
1138
|
-
|
1139
|
-
|
1140
|
-
|
1141
|
-
|
1142
|
-
|
1143
|
-
|
1144
|
-
|
1145
|
-
docs.documents.
|
1146
|
-
|
1147
|
-
docs
|
1148
|
-
end
|
1149
|
-
|
1150
|
-
def list_documents_with_params(schema_id, full_document, limit, offset)
|
1151
|
-
check_string(schema_id)
|
1152
|
-
check_boolean(full_document)
|
1153
|
-
check_int(limit)
|
1154
|
-
check_int(offset)
|
1155
|
-
docs = GetDocumentsResponse.new
|
1156
|
-
if full_document
|
1157
|
-
docs.from_json(get_full_content_documents("/schemas/#{schema_id}/documents", limit, offset).to_json)
|
1158
|
-
else
|
1159
|
-
docs.from_json(get_resource_with_params("/schemas/#{schema_id}/documents", limit, offset).to_json)
|
1026
|
+
if limit==nil && offset==nil
|
1027
|
+
if full_document
|
1028
|
+
docs.from_json(get_resource("/schemas/#{schema_id}/documents", ChinoRuby::QUERY_DEFAULT_LIMIT, 0, true).to_json)
|
1029
|
+
else
|
1030
|
+
docs.from_json(get_resource("/schemas/#{schema_id}/documents", ChinoRuby::QUERY_DEFAULT_LIMIT, 0).to_json)
|
1031
|
+
end
|
1032
|
+
else
|
1033
|
+
if full_document
|
1034
|
+
docs.from_json(get_resource("/schemas/#{schema_id}/documents", limit, offset, true).to_json)
|
1035
|
+
else
|
1036
|
+
docs.from_json(get_resource("/schemas/#{schema_id}/documents", limit, offset).to_json)
|
1037
|
+
end
|
1160
1038
|
end
|
1161
1039
|
ds = docs.documents
|
1162
1040
|
docs.documents = []
|
@@ -1240,30 +1118,19 @@ class Collections < ChinoBaseAPI
|
|
1240
1118
|
col
|
1241
1119
|
end
|
1242
1120
|
|
1243
|
-
def list_collections()
|
1121
|
+
def list_collections(limit=nil, offset=nil)
|
1244
1122
|
cols = GetCollectionsResponse.new
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
|
1249
|
-
col = Collection.new
|
1250
|
-
col.from_json(c.to_json)
|
1251
|
-
cols.collections.push(col)
|
1123
|
+
if limit==nil && offset==nil
|
1124
|
+
cols.from_json(get_resource("/collections", ChinoRuby::QUERY_DEFAULT_LIMIT, 0).to_json)
|
1125
|
+
else
|
1126
|
+
cols.from_json(get_resource("/collections", limit, offset).to_json)
|
1252
1127
|
end
|
1253
|
-
cols
|
1254
|
-
end
|
1255
|
-
|
1256
|
-
def list_repositories_with_params(limit, offset)
|
1257
|
-
check_int(limit)
|
1258
|
-
check_int(offset)
|
1259
|
-
cols = GetCollectionsResponse.new
|
1260
|
-
cols.from_json(get_resource_with_params("/collections", limit, offset).to_json)
|
1261
1128
|
cs = cols.collections
|
1262
1129
|
cols.collections = []
|
1263
1130
|
cs.each do |c|
|
1264
1131
|
col = Collection.new
|
1265
1132
|
col.from_json(c.to_json)
|
1266
|
-
cols.
|
1133
|
+
cols.collections.push(col)
|
1267
1134
|
end
|
1268
1135
|
cols
|
1269
1136
|
end
|
@@ -1294,7 +1161,7 @@ class Collections < ChinoBaseAPI
|
|
1294
1161
|
def add_document(document_id, collection_id)
|
1295
1162
|
check_string(document_id)
|
1296
1163
|
check_string(collection_id)
|
1297
|
-
|
1164
|
+
post_resource("/collections/#{collection_id}/documents/#{document_id}")
|
1298
1165
|
end
|
1299
1166
|
|
1300
1167
|
def remove_document(document_id, collection_id)
|
@@ -1303,24 +1170,14 @@ class Collections < ChinoBaseAPI
|
|
1303
1170
|
delete_resource("/collections/#{collection_id}/documents/#{document_id}", false)
|
1304
1171
|
end
|
1305
1172
|
|
1306
|
-
def list_documents(collection_id)
|
1173
|
+
def list_documents(collection_id, limit=nil, offset=nil)
|
1307
1174
|
check_string(collection_id)
|
1308
1175
|
docs = GetDocumentsResponse.new
|
1309
|
-
|
1310
|
-
|
1311
|
-
|
1312
|
-
|
1313
|
-
doc = Document.new
|
1314
|
-
doc.from_json(d.to_json)
|
1315
|
-
docs.documents.push(doc)
|
1176
|
+
if limit==nil && offset==nil
|
1177
|
+
docs.from_json(get_resource("/collections/#{collection_id}/documents", ChinoRuby::QUERY_DEFAULT_LIMIT, 0).to_json)
|
1178
|
+
else
|
1179
|
+
docs.from_json(get_resource("/collections/#{collection_id}/documents", limit, offset).to_json)
|
1316
1180
|
end
|
1317
|
-
docs
|
1318
|
-
end
|
1319
|
-
|
1320
|
-
def list_documents_with_params(collection_id, limit, offset)
|
1321
|
-
check_string(collection_id)
|
1322
|
-
docs = GetDocumentsResponse.new
|
1323
|
-
docs.from_json(get_resource_with_params("/collections/#{collection_id}/documents", limit, offset).to_json)
|
1324
1181
|
ds = docs.documents
|
1325
1182
|
docs.documents = []
|
1326
1183
|
ds.each do |d|
|
@@ -1367,24 +1224,13 @@ class GetPermissionsResponse
|
|
1367
1224
|
end
|
1368
1225
|
|
1369
1226
|
class Permissions < ChinoBaseAPI
|
1370
|
-
def
|
1227
|
+
def list_permissions(limit=nil, offset=nil)
|
1371
1228
|
perms = GetPermissionsResponse.new
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1376
|
-
perm = Permission.new
|
1377
|
-
perm.from_json(p.to_json)
|
1378
|
-
perms.permissions.push(perm)
|
1229
|
+
if limit==nil && offset==nil
|
1230
|
+
perms.from_json(get_resource("/perms", ChinoRuby::QUERY_DEFAULT_LIMIT, 0).to_json)
|
1231
|
+
else
|
1232
|
+
perms.from_json(get_resource("/perms", limit, offset).to_json)
|
1379
1233
|
end
|
1380
|
-
perms
|
1381
|
-
end
|
1382
|
-
|
1383
|
-
def read_permissions_with_params(limit, offset)
|
1384
|
-
check_int(limit)
|
1385
|
-
check_int(offset)
|
1386
|
-
perms = GetPermissionsResponse.new
|
1387
|
-
perms.from_json(get_resource_with_params("/perms", limit, offset).to_json)
|
1388
1234
|
ps = perms.permissions
|
1389
1235
|
perms.permissions = []
|
1390
1236
|
ps.each do |p|
|
@@ -1395,26 +1241,14 @@ class Permissions < ChinoBaseAPI
|
|
1395
1241
|
perms
|
1396
1242
|
end
|
1397
1243
|
|
1398
|
-
def read_permissions_on_a_document(document_id)
|
1244
|
+
def read_permissions_on_a_document(document_id, limit=nil, offset=nil)
|
1399
1245
|
check_string(document_id)
|
1400
1246
|
perms = GetPermissionsResponse.new
|
1401
|
-
|
1402
|
-
|
1403
|
-
|
1404
|
-
|
1405
|
-
perm = Permission.new
|
1406
|
-
perm.from_json(p.to_json)
|
1407
|
-
perms.permissions.push(perm)
|
1247
|
+
if limit==nil && offset==nil
|
1248
|
+
perms.from_json(get_resource("/perms/documents/#{document_id}", ChinoRuby::QUERY_DEFAULT_LIMIT, 0).to_json)
|
1249
|
+
else
|
1250
|
+
perms.from_json(get_resource("/perms/documents/#{document_id}", limit, offset).to_json)
|
1408
1251
|
end
|
1409
|
-
perms
|
1410
|
-
end
|
1411
|
-
|
1412
|
-
def read_permissions_on_a_document_with_params(document_id, limit, offset)
|
1413
|
-
check_int(limit)
|
1414
|
-
check_int(offset)
|
1415
|
-
check_string(document_id)
|
1416
|
-
perms = GetPermissionsResponse.new
|
1417
|
-
perms.from_json(get_resource_with_params("/perms/documents/#{document_id}", limit, offset).to_json)
|
1418
1252
|
ps = perms.permissions
|
1419
1253
|
perms.permissions = []
|
1420
1254
|
ps.each do |p|
|
@@ -1425,26 +1259,14 @@ class Permissions < ChinoBaseAPI
|
|
1425
1259
|
perms
|
1426
1260
|
end
|
1427
1261
|
|
1428
|
-
def read_permissions_of_a_user(user_id)
|
1262
|
+
def read_permissions_of_a_user(user_id, limit=nil, offset=nil)
|
1429
1263
|
check_string(user_id)
|
1430
1264
|
perms = GetPermissionsResponse.new
|
1431
|
-
|
1432
|
-
|
1433
|
-
|
1434
|
-
|
1435
|
-
perm = Permission.new
|
1436
|
-
perm.from_json(p.to_json)
|
1437
|
-
perms.permissions.push(perm)
|
1265
|
+
if limit==nil && offset==nil
|
1266
|
+
perms.from_json(get_resource("/perms/users/#{user_id}", ChinoRuby::QUERY_DEFAULT_LIMIT, 0).to_json)
|
1267
|
+
else
|
1268
|
+
perms.from_json(get_resource("/perms/users/#{user_id}", limit, offset).to_json)
|
1438
1269
|
end
|
1439
|
-
perms
|
1440
|
-
end
|
1441
|
-
|
1442
|
-
def read_permissions_of_a_user_with_params(user_id, limit, offset)
|
1443
|
-
check_int(limit)
|
1444
|
-
check_int(offset)
|
1445
|
-
check_string(user_id)
|
1446
|
-
perms = GetPermissionsResponse.new
|
1447
|
-
perms.from_json(get_resource_with_params("/perms/users/#{user_id}", limit, offset).to_json)
|
1448
1270
|
ps = perms.permissions
|
1449
1271
|
perms.permissions = []
|
1450
1272
|
ps.each do |p|
|
@@ -1455,26 +1277,14 @@ class Permissions < ChinoBaseAPI
|
|
1455
1277
|
perms
|
1456
1278
|
end
|
1457
1279
|
|
1458
|
-
def read_permissions_of_a_group(group_id)
|
1280
|
+
def read_permissions_of_a_group(group_id, limit=nil, offset=nil)
|
1459
1281
|
check_string(group_id)
|
1460
1282
|
perms = GetPermissionsResponse.new
|
1461
|
-
|
1462
|
-
|
1463
|
-
|
1464
|
-
|
1465
|
-
perm = Permission.new
|
1466
|
-
perm.from_json(p.to_json)
|
1467
|
-
perms.permissions.push(perm)
|
1283
|
+
if limit==nil && offset==nil
|
1284
|
+
perms.from_json(get_resource("/perms/groups/#{group_id}", ChinoRuby::QUERY_DEFAULT_LIMIT, 0).to_json)
|
1285
|
+
else
|
1286
|
+
perms.from_json(get_resource("/perms/groups/#{group_id}", limit, offset).to_json)
|
1468
1287
|
end
|
1469
|
-
perms
|
1470
|
-
end
|
1471
|
-
|
1472
|
-
def read_permissions_of_a_group_with_params(group_id, limit, offset)
|
1473
|
-
check_int(limit)
|
1474
|
-
check_int(offset)
|
1475
|
-
check_string(group_id)
|
1476
|
-
perms = GetPermissionsResponse.new
|
1477
|
-
perms.from_json(get_resource_with_params("/perms/groups/#{group_id}", limit, offset).to_json)
|
1478
1288
|
ps = perms.permissions
|
1479
1289
|
perms.permissions = []
|
1480
1290
|
ps.each do |p|
|
@@ -1551,7 +1361,7 @@ class FilterOption < CheckValues
|
|
1551
1361
|
end
|
1552
1362
|
|
1553
1363
|
def to_json
|
1554
|
-
|
1364
|
+
{"field": field, "type": type, "value": value}.to_json
|
1555
1365
|
end
|
1556
1366
|
end
|
1557
1367
|
|
@@ -1566,12 +1376,12 @@ class SortOption < CheckValues
|
|
1566
1376
|
end
|
1567
1377
|
|
1568
1378
|
def to_json
|
1569
|
-
|
1379
|
+
{"field": field, "order": order}.to_json
|
1570
1380
|
end
|
1571
1381
|
end
|
1572
1382
|
|
1573
1383
|
class Search < ChinoBaseAPI
|
1574
|
-
def search_documents(schema_id, result_type, filter_type, sort, filter)
|
1384
|
+
def search_documents(schema_id, result_type, filter_type, sort, filter, limit=nil, offset=nil)
|
1575
1385
|
check_string(schema_id)
|
1576
1386
|
check_string(result_type)
|
1577
1387
|
check_string(filter_type)
|
@@ -1579,26 +1389,11 @@ class Search < ChinoBaseAPI
|
|
1579
1389
|
check_json(filter)
|
1580
1390
|
data = {"result_type": result_type, "filter_type": filter_type, "filter": filter, "sort": sort}.to_json
|
1581
1391
|
docs = GetDocumentsResponse.new
|
1582
|
-
|
1583
|
-
|
1584
|
-
|
1585
|
-
|
1586
|
-
doc = Document.new
|
1587
|
-
doc.from_json(d.to_json)
|
1588
|
-
docs.documents.push(doc)
|
1392
|
+
if limit==nil && offset==nil
|
1393
|
+
docs.from_json(post_resource("/search/documents/#{schema_id}", data, ChinoRuby::QUERY_DEFAULT_LIMIT, 0).to_json)
|
1394
|
+
else
|
1395
|
+
docs.from_json(post_resource("/search/documents/#{schema_id}", data, limit, offset).to_json)
|
1589
1396
|
end
|
1590
|
-
docs
|
1591
|
-
end
|
1592
|
-
|
1593
|
-
def search_documents_with_params(schema_id, result_type, filter_type, sort, filter, limit, offset)
|
1594
|
-
check_string(schema_id)
|
1595
|
-
check_string(result_type)
|
1596
|
-
check_string(filter_type)
|
1597
|
-
check_json(sort)
|
1598
|
-
check_json(filter)
|
1599
|
-
data = {"result_type": result_type, "filter_type": filter_type, "filter": filter, "sort": sort}.to_json
|
1600
|
-
docs = GetDocumentsResponse.new
|
1601
|
-
docs.from_json(post_resource_with_params("/search/documents/#{schema_id}", data, limit, offset).to_json)
|
1602
1397
|
ds = docs.documents
|
1603
1398
|
docs.documents = []
|
1604
1399
|
ds.each do |d|
|
@@ -1609,7 +1404,7 @@ class Search < ChinoBaseAPI
|
|
1609
1404
|
docs
|
1610
1405
|
end
|
1611
1406
|
|
1612
|
-
def search_users(user_schema_id, result_type, filter_type, sort, filter)
|
1407
|
+
def search_users(user_schema_id, result_type, filter_type, sort, filter, limit=nil, offset=nil)
|
1613
1408
|
check_string(user_schema_id)
|
1614
1409
|
check_string(result_type)
|
1615
1410
|
check_string(filter_type)
|
@@ -1617,26 +1412,11 @@ class Search < ChinoBaseAPI
|
|
1617
1412
|
check_json(filter)
|
1618
1413
|
data = {"result_type": result_type, "filter_type": filter_type, "filter": filter, "sort": sort}.to_json
|
1619
1414
|
users = GetUsersResponse.new
|
1620
|
-
|
1621
|
-
|
1622
|
-
|
1623
|
-
|
1624
|
-
user = User.new
|
1625
|
-
user.from_json(u.to_json)
|
1626
|
-
users.users.push(user)
|
1415
|
+
if limit==nil && offset==nil
|
1416
|
+
users.from_json(post_resource("/search/users/#{user_schema_id}", data, ChinoRuby::QUERY_DEFAULT_LIMIT, 0).to_json)
|
1417
|
+
else
|
1418
|
+
users.from_json(post_resource("/search/users/#{user_schema_id}", data, limit, offset).to_json)
|
1627
1419
|
end
|
1628
|
-
users
|
1629
|
-
end
|
1630
|
-
|
1631
|
-
def search_users_with_params(user_schema_id, result_type, filter_type, sort, filter, limit, offset)
|
1632
|
-
check_string(user_schema_id)
|
1633
|
-
check_string(result_type)
|
1634
|
-
check_string(filter_type)
|
1635
|
-
check_json(sort)
|
1636
|
-
check_json(filter)
|
1637
|
-
data = {"result_type": result_type, "filter_type": filter_type, "filter": filter, "sort": sort}.to_json
|
1638
|
-
users = GetUsersResponse.new
|
1639
|
-
users.from_json(post_resource_with_params("/search/users/#{user_schema_id}", data, limit, offset).to_json)
|
1640
1420
|
us = users.users
|
1641
1421
|
users.users = []
|
1642
1422
|
us.each do |u|
|
@@ -1710,7 +1490,8 @@ class Blobs < ChinoBaseAPI
|
|
1710
1490
|
blob = init_upload(filename, document_id, field)
|
1711
1491
|
bytes = []
|
1712
1492
|
offset = 0
|
1713
|
-
File.
|
1493
|
+
file_path = File.join File.expand_path("..", File.dirname(__FILE__)), path, filename
|
1494
|
+
File.open(file_path, 'rb') { |file|
|
1714
1495
|
while (buffer = file.read(chunk_size)) do
|
1715
1496
|
upload_chunk(blob.upload_id, buffer, offset)
|
1716
1497
|
offset = offset+buffer.length
|
@@ -1775,7 +1556,9 @@ class Blobs < ChinoBaseAPI
|
|
1775
1556
|
filename = res.header['Content-Disposition'].partition('=').last
|
1776
1557
|
blob.filename = filename
|
1777
1558
|
blob.path = destination
|
1778
|
-
File.
|
1559
|
+
path = File.join File.expand_path("..", File.dirname(__FILE__)), destination
|
1560
|
+
FileUtils.mkdir_p(path) unless File.exist?(path)
|
1561
|
+
File.open(File.join(path+filename), 'wb') { |file|
|
1779
1562
|
file << res.body
|
1780
1563
|
blob.md5 = (Digest::MD5.file file).hexdigest
|
1781
1564
|
blob.sha1 = (Digest::SHA1.file file).hexdigest
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chino_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paolo Prem
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 12.0.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 12.0.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: listen
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|