Name: kinto_box
Owner: Vox Media
Description: A ruby client for Kinto(kinto.readthedocs.io)
Created: 2016-06-24 04:42:19.0
Updated: 2018-05-15 18:25:53.0
Pushed: 2018-05-15 18:25:52.0
Homepage: null
Size: 51
Language: Ruby
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Kinto Box is a ruby client for Kinto
Add this line to your application's Gemfile:
'kinto_box'
And then execute:
$ bundle
Or install it yourself as:
$ gem install kinto_box
To use kinto_box, add require 'kinto_box'
to your file.
To connect to a kinto server, you can pass the username and password to the client
o_client = KintoBox.new('https://kinto.dev.mozaws.net', {:username => 'token', :password => 'my-secret'})
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.
To create a new bucket named TestBucket
et = kinto_client.create_bucket('TestBucket')
To connect to a bucket named TestBucket
et = kinto_client.bucket('TestBucket')
Note: This does not create the bucket nor check if the bucket exists on the server.
To check if the bucket exists use
et.exists?
To get information about the bucket, use
et.info
To get permissions set on the bucket, use
et.permissions
To add permission to the bucket, use add_permission(principal, permission)
See http://kinto.readthedocs.io/en/stable/api/1.x/permissions.html#api-permissions
to see valid principals and permissions
For convenience, the following are supported. everyone
and anonymous
is the same as System.Everyone
. And authenticated
is the same as System.Authenticated
To delete a bucket, use
et.delete
To create a collection named TestCollection
, use
ection = bucket.create_collection('TestCollection')
To connect to a collection named TestCollection
ection = bucket.collection('TestCollection')
Note: This does not create the collection nor check if the collection exists on the server.
To check if the collection exists use
ection.exists?
To get information about the bucket, use
ection.info
To get permissions set on the collection, use
ection.permissions
To add permission to the bucket, use collection.add_permission(principal, permission)
To delete a bucket, use
ection.delete
To read from the collection
rds = collection.list_records
List records support filtering and sorting. It follows the convention described here and here.
rds = collection.list_records('min_val=10','val')
The above line will return all records where val
is at least 10 and sorted ascending on the field val
To delete all records from the collection
rds = collection.delete_records
To add an object to the collection
= { 'foo' => 'value1' }
ection.create_record(data)
rd.delete
rd.update({'bar' => new_value})
This add a value bar to the record
To replace the data entirely, use
rd.replace({'bar' => new_value})
This drops the property food taht existed before the update.
group = bucket.create_group(group_name, member)
Member can be any valid principal
group.delete
p.add_member(user)
p.remove_member(user)
To replace all members, use
p.update_members(users)
See test/kinto_box_test
for more usages
After checking out the repo, run bundle install
to install dependencies. Then, run bundle exec rake test
to run the tests.
To install this gem onto your local machine, run bundle exec rake install
.
Bug reports and pull requests are welcome on GitHub at https://github.com/kavyasukumar/kinto_box.
The gem is available as open source under the terms of the MIT License.