kinto_box 0.1.10 → 0.1.12
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/lib/kinto_box.rb +42 -0
- data/lib/kinto_box/kinto_batch_request.rb +30 -0
- data/lib/kinto_box/kinto_bucket.rb +19 -9
- data/lib/kinto_box/kinto_collection.rb +22 -14
- data/lib/kinto_box/kinto_group.rb +1 -2
- data/lib/kinto_box/kinto_object.rb +45 -3
- data/lib/kinto_box/kinto_record.rb +2 -2
- data/lib/kinto_box/kinto_request.rb +18 -0
- data/lib/kinto_box/response_handler.rb +7 -1
- data/lib/kinto_box/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32a1ab4c6cd2f76e5a07c2c7df08e281b6ef8ae3
|
4
|
+
data.tar.gz: e4935d11684d5f8a6346c0b9dd7de758ef51548d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84f70e98d251392478f69938e5cfc480bf6ba608af4c03324eedf36d10ba2346bec2a9b69529af9e9f902eb139c175adfe718f5737803cb9cf031959f69871ee
|
7
|
+
data.tar.gz: 802b3bfc51dd2dbbb21357e8b629e919a70e5206082b6e669f2ede5d7df12ac8dade82ac33cbc6ea6de333b61ffe28ef39d048b3c6cb7f58b29684b4a6b5bf9f
|
data/lib/kinto_box.rb
CHANGED
@@ -84,6 +84,39 @@ module KintoBox
|
|
84
84
|
delete '/buckets'
|
85
85
|
end
|
86
86
|
|
87
|
+
# Raw request
|
88
|
+
#
|
89
|
+
def request(path, method, data = {})
|
90
|
+
case method.upcase
|
91
|
+
when 'PUT'
|
92
|
+
self.class.put(path, :body => data.to_json)
|
93
|
+
when 'GET'
|
94
|
+
self.class.get(path)
|
95
|
+
when 'POST'
|
96
|
+
self.class.post(path, :body => data.to_json)
|
97
|
+
when 'DELETE'
|
98
|
+
self.class.delete(path)
|
99
|
+
when 'OPTIONS'
|
100
|
+
self.class.options(path)
|
101
|
+
when 'HEAD'
|
102
|
+
self.class.head(path)
|
103
|
+
when 'MOVE'
|
104
|
+
self.class.move(path, :body => data.to_json)
|
105
|
+
when 'COPY'
|
106
|
+
self.class.copy(path, :body => data.to_json)
|
107
|
+
when 'PATCH'
|
108
|
+
self.class.copy(path, :body => data.to_json)
|
109
|
+
else
|
110
|
+
raise HTTPBadRequest
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
# Make batch requests
|
115
|
+
def create_batch_request
|
116
|
+
KintoBatchRequest.new(self)
|
117
|
+
end
|
118
|
+
|
119
|
+
|
87
120
|
# Calls http PUT on path
|
88
121
|
#
|
89
122
|
# @params [String]path Url path
|
@@ -128,5 +161,14 @@ module KintoBox
|
|
128
161
|
def get(path)
|
129
162
|
ResponseHandler.handle self.class.get(path)
|
130
163
|
end
|
164
|
+
|
165
|
+
# Calls http HEAD on path
|
166
|
+
#
|
167
|
+
# @params [String]path Url path
|
168
|
+
# @params [Hash] data to be sent in the body
|
169
|
+
# @return [Hash] response body
|
170
|
+
def head(path, data = {})
|
171
|
+
ResponseHandler.get_response_head self.class.head(path)
|
172
|
+
end
|
131
173
|
end
|
132
174
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'kinto_box/kinto_collection'
|
2
|
+
require 'kinto_box/kinto_object'
|
3
|
+
require 'kinto_box/kinto_request'
|
4
|
+
|
5
|
+
module KintoBox
|
6
|
+
class KintoBatchRequest
|
7
|
+
|
8
|
+
def initialize(kinto_client)
|
9
|
+
@kinto_client = kinto_client
|
10
|
+
@request_data = {'defaults' => {
|
11
|
+
'method'=> 'POST',
|
12
|
+
'path'=> '/'
|
13
|
+
},
|
14
|
+
'requests' =>[]
|
15
|
+
}
|
16
|
+
@requests = @request_data['requests']
|
17
|
+
end
|
18
|
+
|
19
|
+
def add_request(request)
|
20
|
+
@requests.push(request.hashed_object)
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
24
|
+
def send
|
25
|
+
|
26
|
+
@kinto_client.post('/batch', @request_data)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -2,10 +2,8 @@ require 'kinto_box/kinto_collection'
|
|
2
2
|
require 'kinto_box/kinto_object'
|
3
3
|
require 'kinto_box/kinto_group'
|
4
4
|
module KintoBox
|
5
|
-
class KintoBucket
|
6
|
-
include KintoObject
|
5
|
+
class KintoBucket < KintoObject
|
7
6
|
|
8
|
-
attr_accessor :id
|
9
7
|
attr_reader :kinto_client
|
10
8
|
|
11
9
|
def initialize (client, bucket_id)
|
@@ -14,10 +12,11 @@ module KintoBox
|
|
14
12
|
@kinto_client = client
|
15
13
|
@id = bucket_id
|
16
14
|
@url_path = "/buckets/#{@id}"
|
15
|
+
@child_path = '/collections'
|
17
16
|
end
|
18
17
|
|
19
|
-
def list_collections
|
20
|
-
@kinto_client.get(
|
18
|
+
def list_collections(filters = nil, sort = nil)
|
19
|
+
@kinto_client.get(url_w_qsp(filters, sort))
|
21
20
|
end
|
22
21
|
|
23
22
|
def list_groups
|
@@ -26,16 +25,14 @@ module KintoBox
|
|
26
25
|
|
27
26
|
def collection (collection_id)
|
28
27
|
@collection = KintoCollection.new(self, collection_id)
|
29
|
-
@collection
|
30
28
|
end
|
31
29
|
|
32
30
|
def group(group_id)
|
33
31
|
@group = KintoGroup.new(self, group_id)
|
34
|
-
@group
|
35
32
|
end
|
36
33
|
|
37
34
|
def create_collection(collection_id)
|
38
|
-
@kinto_client.post("#{@url_path}
|
35
|
+
@kinto_client.post("#{@url_path}#{@child_path}", { 'data' => { 'id' => collection_id}})
|
39
36
|
collection(collection_id)
|
40
37
|
end
|
41
38
|
|
@@ -46,7 +43,20 @@ module KintoBox
|
|
46
43
|
end
|
47
44
|
|
48
45
|
def delete_collections
|
49
|
-
@kinto_client.delete(
|
46
|
+
@kinto_client.delete(url_w_qsp)
|
50
47
|
end
|
48
|
+
|
49
|
+
def delete_groups
|
50
|
+
@kinto_client.delete("#{@url_path}/groups")
|
51
|
+
end
|
52
|
+
|
53
|
+
def count_collections(filters = nil)
|
54
|
+
@kinto_client.head(url_w_qsp(filters))['Total-Records'].to_i
|
55
|
+
end
|
56
|
+
|
57
|
+
alias_method :create_collection_request, :create_child_request
|
58
|
+
alias_method :list_collection_request, :list_children_request
|
59
|
+
alias_method :delete_collections_request, :delete_children_request
|
60
|
+
alias_method :count_collections_request, :count_children_request
|
51
61
|
end
|
52
62
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'kinto_box/kinto_record'
|
2
2
|
require 'kinto_box/kinto_object'
|
3
|
+
require 'kinto_box/kinto_batch_request'
|
3
4
|
|
4
5
|
module KintoBox
|
5
|
-
class KintoCollection
|
6
|
-
|
6
|
+
class KintoCollection < KintoObject
|
7
|
+
|
7
8
|
|
8
|
-
attr_accessor :id
|
9
9
|
attr_reader :bucket
|
10
10
|
|
11
11
|
def initialize (bucket, collection_id)
|
@@ -14,31 +14,39 @@ module KintoBox
|
|
14
14
|
@bucket = bucket
|
15
15
|
@id = collection_id
|
16
16
|
@url_path = "/buckets/#{bucket.id}/collections/#{@id}"
|
17
|
+
@child_path = '/records'
|
17
18
|
end
|
18
19
|
|
19
20
|
def record (record_id)
|
20
|
-
|
21
|
-
record
|
21
|
+
KintoRecord.new(self, record_id)
|
22
22
|
end
|
23
23
|
|
24
24
|
|
25
25
|
def list_records(filters = nil, sort = nil)
|
26
|
-
|
27
|
-
query_string += filters unless filters.nil?
|
28
|
-
query_string += '&' unless filters.nil? || sort.nil?
|
29
|
-
query_string += "_sort=#{sort}" unless sort.nil?
|
30
|
-
path = query_string == '?' ? "#{@url_path}/records" : "#{@url_path}/records#{query_string}"
|
31
|
-
@kinto_client.get(path)
|
26
|
+
@kinto_client.get(url_w_qsp(filters, sort))
|
32
27
|
end
|
33
28
|
|
29
|
+
|
34
30
|
def create_record(data)
|
35
|
-
resp = @kinto_client.post("#{@url_path}
|
31
|
+
resp = @kinto_client.post("#{@url_path}#{@child_path}", { 'data' => data})
|
36
32
|
record_id = resp['data']['id']
|
37
33
|
record(record_id)
|
38
34
|
end
|
39
35
|
|
40
|
-
|
41
|
-
|
36
|
+
|
37
|
+
def delete_records(filters = nil)
|
38
|
+
@kinto_client.delete(url_w_qsp(filters))
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
def count_records(filters = nil)
|
43
|
+
@kinto_client.head(url_w_qsp(filters))['Total-Records'].to_i
|
42
44
|
end
|
45
|
+
|
46
|
+
|
47
|
+
alias_method :create_record_request, :create_child_request
|
48
|
+
alias_method :list_records_request, :list_children_request
|
49
|
+
alias_method :delete_records_request, :delete_children_request
|
50
|
+
alias_method :count_records_request, :count_children_request
|
43
51
|
end
|
44
52
|
end
|
@@ -1,5 +1,9 @@
|
|
1
1
|
module KintoBox
|
2
|
-
|
2
|
+
class KintoObject
|
3
|
+
|
4
|
+
attr_accessor :id
|
5
|
+
attr_reader :url_path
|
6
|
+
|
3
7
|
def info
|
4
8
|
@kinto_client.get(@url_path)
|
5
9
|
end
|
@@ -21,20 +25,49 @@ module KintoBox
|
|
21
25
|
true
|
22
26
|
end
|
23
27
|
|
28
|
+
def info_request
|
29
|
+
KintoRequest.new('GET', @url_path)
|
30
|
+
end
|
31
|
+
|
32
|
+
def update_request(data)
|
33
|
+
KintoRequest.new('PATCH', @url_path, {'data' => data})
|
34
|
+
end
|
35
|
+
|
36
|
+
def delete_request
|
37
|
+
KintoRequest.new('DELETE', @url_path)
|
38
|
+
end
|
39
|
+
|
40
|
+
def create_child_request(data)
|
41
|
+
KintoRequest.new('POST', url_w_qsp, { 'data' => data})
|
42
|
+
end
|
43
|
+
|
44
|
+
def list_children_request(filters = nil, sort = nil)
|
45
|
+
KintoRequest.new('GET', url_w_qsp(filters, sort))
|
46
|
+
end
|
47
|
+
|
48
|
+
def delete_children_request(filters = nil)
|
49
|
+
KintoRequest.new('DELETE', url_w_qsp(filters))
|
50
|
+
end
|
51
|
+
|
52
|
+
def count_children_request(filters = nil)
|
53
|
+
KintoRequest.new('HEAD', url_w_qsp(filters))
|
54
|
+
end
|
55
|
+
|
24
56
|
def add_permission(principal, permission)
|
25
57
|
@kinto_client.patch(@url_path, {'permissions' => { permission => [principal_name(principal)] }})
|
26
|
-
|
58
|
+
self
|
27
59
|
end
|
28
60
|
|
29
61
|
def replace_permission(principal, permission)
|
30
62
|
@kinto_client.put(@url_path, {'permissions' => { permission => [principal_name(principal)] }})
|
31
|
-
|
63
|
+
self
|
32
64
|
end
|
33
65
|
|
34
66
|
def permissions
|
35
67
|
info['permissions']
|
36
68
|
end
|
37
69
|
|
70
|
+
|
38
71
|
private
|
39
72
|
|
40
73
|
def principal_name(principal)
|
@@ -49,5 +82,14 @@ module KintoBox
|
|
49
82
|
return principal
|
50
83
|
end
|
51
84
|
end
|
85
|
+
|
86
|
+
def url_w_qsp(filters = nil, sort = nil, add_child = true)
|
87
|
+
url = @child_path.nil? || !add_child ? @url_path : "#{@url_path}#{@child_path}"
|
88
|
+
query_string = ''
|
89
|
+
query_string = filters unless filters.nil?
|
90
|
+
query_string = "#{query_string}&" unless filters.nil? || sort.nil?
|
91
|
+
query_string = "#{query_string}_sort=#{sort}" unless sort.nil?
|
92
|
+
query_string == '' ? url : "#{url}?#{query_string}"
|
93
|
+
end
|
52
94
|
end
|
53
95
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'kinto_box/kinto_object'
|
2
2
|
module KintoBox
|
3
|
-
class KintoRecord
|
4
|
-
include KintoObject
|
3
|
+
class KintoRecord < KintoObject
|
5
4
|
attr_reader :id
|
6
5
|
def initialize (collection, record_id)
|
7
6
|
raise ArgumentError if collection.nil? || record_id.nil?
|
8
7
|
@kinto_client = collection.bucket.kinto_client
|
9
8
|
@id = record_id
|
10
9
|
@url_path = "/buckets/#{collection.bucket.id}/collections/#{collection.id}/records/#{@id}"
|
10
|
+
@child_path = nil
|
11
11
|
end
|
12
12
|
|
13
13
|
def replace(data)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module KintoBox
|
2
|
+
class KintoRequest
|
3
|
+
|
4
|
+
def initialize(method = 'GET', path = nil , body = {}, headers = nil)
|
5
|
+
@method = method
|
6
|
+
@path = path
|
7
|
+
@body = body
|
8
|
+
@headers = headers
|
9
|
+
end
|
10
|
+
|
11
|
+
def hashed_object
|
12
|
+
{ 'method' => @method,
|
13
|
+
'path' => @path,
|
14
|
+
'body' => @body
|
15
|
+
}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/kinto_box/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kinto_box
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kavya Sukumar
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -103,11 +103,13 @@ files:
|
|
103
103
|
- bin/setup
|
104
104
|
- kinto_box.gemspec
|
105
105
|
- lib/kinto_box.rb
|
106
|
+
- lib/kinto_box/kinto_batch_request.rb
|
106
107
|
- lib/kinto_box/kinto_bucket.rb
|
107
108
|
- lib/kinto_box/kinto_collection.rb
|
108
109
|
- lib/kinto_box/kinto_group.rb
|
109
110
|
- lib/kinto_box/kinto_object.rb
|
110
111
|
- lib/kinto_box/kinto_record.rb
|
112
|
+
- lib/kinto_box/kinto_request.rb
|
111
113
|
- lib/kinto_box/response_handler.rb
|
112
114
|
- lib/kinto_box/version.rb
|
113
115
|
homepage: http://github.com/voxmedia/kinto_box
|