kinto_box 0.1.6 → 0.1.7

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: 5246de9ec861fb33f83486fe3f153dfbd184ced5
4
- data.tar.gz: 6f594d8293751c6ce803a17b9107afbeffee5b2c
3
+ metadata.gz: f41cad2d2d36c3deaf4c1804af203d22dfa86a59
4
+ data.tar.gz: 19d61573448b09387cee1acd839c0e5be0f00565
5
5
  SHA512:
6
- metadata.gz: fc70c5827672c871ca69367a27f4d11182ebf26c213c61da7a5eb92997ed2238ab8d5c6834de6aaa26bd671dbffdb4d2bbcc1a3ad7c074600cfe72bb84755447
7
- data.tar.gz: 44b7608328143c88c9671209f3a476622b784fc04f35d83ec6ea27e8ea9346a0a8ccd1394d71b97472a0f8232da2e3084bebcf02c76ec5a03632f2425b5833cb
6
+ metadata.gz: 48009280a182692c987a599f913847a2b96539d9394595bed282c6e01ed03f8136935f48155783b18c9beac23d06aac25e7f1b3e2fbdcc0233358b4364570481
7
+ data.tar.gz: dfc240b5ac5970a1c1bcce4368b6f9f8930f9171fe36df89787918dcf8e2f04d69442ccf892b958ece98fa55e3ab8987e84db81d4d22d74d52002568f09b470a
data/README.md CHANGED
@@ -19,8 +19,197 @@ Or install it yourself as:
19
19
  $ gem install kinto_box
20
20
 
21
21
  ## Usage
22
+ To use kinto_box, add `require 'kinto_box'` to your file.
22
23
 
23
- TODO: Write usage instructions here
24
+
25
+ ### Connection and Authentication
26
+
27
+
28
+ To connect to a kinto server, you can pass the username and password to the client
29
+
30
+ ```
31
+ kinto_client = KintoBox::KintoClient.new('https://kinto.dev.mozaws.net', {:username => 'token', :password => 'my-secret'})
32
+ ```
33
+
34
+ If no credentials are passed, the gem looks for `KINTO_API_TOKEN` environment variable. The environment variable should store the Base64 encoding of `username:password` string, for this to work.
35
+
36
+
37
+ ### Buckets
38
+
39
+ #### Creating a new bucket
40
+
41
+ To create a new bucket named `TestBucket`
42
+
43
+ ```
44
+ bucket = kinto_client.create_bucket('TestBucket')
45
+ ```
46
+
47
+ #### Using a bucket
48
+
49
+ To connect to a bucket named `TestBucket`
50
+
51
+ ```
52
+ bucket = kinto_client.bucket('TestBucket')
53
+ ```
54
+
55
+ > Note: This does not create the bucket nor check if the bucket exists on the server.
56
+
57
+ To check if the bucket exists use
58
+
59
+ ```
60
+ bucket.exists?
61
+ ```
62
+
63
+ To get information about the bucket, use
64
+
65
+ ```
66
+ bucket.info
67
+ ```
68
+
69
+ #### Bucket permissions
70
+
71
+ To get permissions set on the bucket, use
72
+
73
+ ```
74
+ bucket.permissions
75
+ ```
76
+
77
+ To add permission to the bucket, use `add_permission(principal, permission)`
78
+
79
+ See `http://kinto.readthedocs.io/en/stable/api/1.x/permissions.html#api-permissions` to see valid principals and permissions
80
+
81
+ For convenience, the following are supported. `everyone` and `anonymous` is the same as `System.Everyone`. And `authenticated` is the same as `System.Authenticated`
82
+
83
+ #### Deleting bucket
84
+ To delete a bucket, use
85
+
86
+ ```
87
+ bucket.delete
88
+ ```
89
+
90
+ ### Collections
91
+
92
+ #### Creating a collection
93
+
94
+ To create a collection named `TestCollection`, use
95
+
96
+ ```
97
+ collection = bucket.create_collection('TestCollection')
98
+ ```
99
+
100
+ #### Using a collection
101
+
102
+ To connect to a collection named `TestCollection`
103
+
104
+ ```
105
+ collection = bucket.collection('TestCollection')
106
+ ```
107
+
108
+ > Note: This does not create the collectiont nor check if the collection exists on the server.
109
+
110
+ To check if the collection exists use
111
+
112
+ ```
113
+ collection.exists?
114
+ ```
115
+
116
+ To get information about the bucket, use
117
+
118
+ ```
119
+ collection.info
120
+ ```
121
+
122
+ #### Collection permissions
123
+
124
+ To get permissions set on the collection, use
125
+
126
+ ```
127
+ collection.permissions
128
+ ```
129
+
130
+ To add permission to the bucket, use `collection.add_permission(principal, permission)`
131
+
132
+
133
+ #### Deleting a collection
134
+ To delete a bucket, use
135
+
136
+ ```
137
+ collection.delete
138
+ ```
139
+
140
+ To read from the collection
141
+
142
+ ```
143
+ records = collection.list_records
144
+ ```
145
+
146
+ To delete all records from the collection
147
+
148
+ ```
149
+ records = collection.delete_records
150
+ ```
151
+
152
+ ### Records
153
+
154
+ To add an object to the collection
155
+
156
+ ```
157
+ data = { 'foo' => 'value1' }
158
+ collection.create_record(data)
159
+ ```
160
+
161
+ #### Deleting a record
162
+ ```
163
+ record.delete
164
+ ```
165
+
166
+ #### Update data in a record
167
+
168
+ ```
169
+ record.update({'bar' => new_value})
170
+ ```
171
+
172
+ This add a value bar to the record
173
+
174
+ To replace the data entirely, use
175
+
176
+ ```
177
+ record.replace({'bar' => new_value})
178
+ ```
179
+
180
+ This drops the property food taht existed before the update.
181
+
182
+
183
+ ### Groups
184
+
185
+ #### Creatinga group
186
+
187
+ ```
188
+ group = bucket.create_group(group_name, member)
189
+ ```
190
+
191
+ Member can be any valid principal
192
+
193
+
194
+ #### Deleting a group
195
+ ```
196
+ group.delete
197
+ ```
198
+
199
+ #### Manging members
200
+
201
+ ```
202
+ group.add_member(user)
203
+ group.remove_member(user)
204
+ ```
205
+
206
+ To replace all members, use
207
+
208
+ ```
209
+ group.update_members(users)
210
+ ```
211
+
212
+ See `test/kinto_box_test` for more usages
24
213
 
25
214
  ## Development
26
215
 
@@ -31,9 +31,5 @@ module KintoBox
31
31
  members.delete(member)
32
32
  update({ 'members' => members })
33
33
  end
34
-
35
- def delete_records
36
- @kinto_client.delete("#{@url_path}/records")
37
- end
38
34
  end
39
35
  end
@@ -22,12 +22,12 @@ module KintoBox
22
22
  end
23
23
 
24
24
  def add_permission(principal, permission)
25
- @kinto_client.patch(@url_path, {'permissions' => { permission_name(permission) => [principal_name(principal)] }})
25
+ @kinto_client.patch(@url_path, {'permissions' => { permission => [principal_name(principal)] }})
26
26
  return self
27
27
  end
28
28
 
29
29
  def replace_permission(principal, permission)
30
- @kinto_client.put(@url_path, {'permissions' => { permission_name(permission) => [principal_name(principal)] }})
30
+ @kinto_client.put(@url_path, {'permissions' => { permission => [principal_name(principal)] }})
31
31
  return self
32
32
  end
33
33
 
@@ -37,22 +37,6 @@ module KintoBox
37
37
 
38
38
  private
39
39
 
40
- def permission_name(permission)
41
- case permission.downcase
42
- when 'read'
43
- return 'read'
44
- when 'write'
45
- return 'write'
46
- when 'create'
47
- return 'collection:create' if self.kind_of? KintoBucket
48
- return 'record:create' if self.kind_of? KintoCollection
49
- when 'group:create'
50
- return 'group:create'
51
- else
52
- raise Exception 'not a valid permission'
53
- end
54
- end
55
-
56
40
  def principal_name(principal)
57
41
  case principal.downcase
58
42
  when 'authenticated'
@@ -1,3 +1,3 @@
1
1
  module KintoBox
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
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.6
4
+ version: 0.1.7
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-07-20 00:00:00.000000000 Z
11
+ date: 2016-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty