Kinto Box is a ruby client for Kinto
Add this line to your application's Gemfile:
gem '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
kinto_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
bucket = kinto_client.create_bucket('TestBucket')
To connect to a bucket named TestBucket
bucket = 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
bucket.exists?
To get information about the bucket, use
bucket.info
To get permissions set on the bucket, use
bucket.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
bucket.delete
To create a collection named TestCollection
, use
collection = bucket.create_collection('TestCollection')
To connect to a collection named TestCollection
collection = 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
collection.exists?
To get information about the bucket, use
collection.info
To get permissions set on the collection, use
collection.permissions
To add permission to the bucket, use collection.add_permission(principal, permission)
To delete a bucket, use
collection.delete
To read from the collection
records = collection.list_records
List records support filtering and sorting. It follows the convention described here and here.
records = 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
records = collection.delete_records
To add an object to the collection
data = { 'foo' => 'value1' }
collection.create_record(data)
record.delete
record.update({'bar' => new_value})
This add a value bar to the record
To replace the data entirely, use
record.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
group.add_member(user)
group.remove_member(user)
To replace all members, use
group.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.