voxmedia/kinto_box

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

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Kinto Box Gem Version

Kinto Box is a ruby client for Kinto

Installation

Add this line to your application's Gemfile:

'kinto_box'

And then execute:

$ bundle

Or install it yourself as:

$ gem install kinto_box
Usage

To use kinto_box, add require 'kinto_box' to your file.

Connection and Authentication

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.

Buckets
Creating a new bucket

To create a new bucket named TestBucket

et = kinto_client.create_bucket('TestBucket')
Using a bucket

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
Bucket permissions

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

Deleting bucket

To delete a bucket, use

et.delete
Collections
Creating a collection

To create a collection named TestCollection, use

ection = bucket.create_collection('TestCollection')
Using a collection

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
Collection permissions

To get permissions set on the collection, use

ection.permissions

To add permission to the bucket, use collection.add_permission(principal, permission)

Deleting a collection

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
Records

To add an object to the collection

 = { 'foo' => 'value1' }
ection.create_record(data)
Deleting a record
rd.delete
Update data in a record
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.

Groups
Creatinga group
group = bucket.create_group(group_name, member)

Member can be any valid principal

Deleting a group
group.delete
Manging members
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

Development

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.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/kavyasukumar/kinto_box.

License

The gem is available as open source under the terms of the MIT License.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.