Simperium Ruby


Auth

init

Initializes a client creating and authenticating users:

>>> require 'simperium'
>>> auth = Simperium::Auth.new('appid', 'apikey')

create

Creates a new user and returns an auth token.

>>> token = auth.create('email@address.com', 'password')
>>> token
=> '25c11ad089dd4c18b84f24bc18c58fe2'

authorize

Authorizes an existing user and returns an access token.

>>> token = auth.authorize('email@address.com', 'password')
>>> token
=> '25c11ad089dd4c18b84f24bc18c58fe2'

Api

init

Initializes a client for interacting with the Simperium syncing api:

>>> require 'simperium'
>>> api = Simperium::Api.new('appid', 'access_token')

getattr/getitem

Returns an instance of a Simperium bucket:

>>> api.todo

Bucket

new

Create a new item in the bucket. Returns the id of the new item.

>>> api.todo.new({'title' => 'Create a startup to kill email', 'done' => false})
=> 'e87881c38a9544eb83d942af928002a5'

set

Set values in an existing item. This merges the keys you are setting with keys that have been currently set:

>>> api.todo.set(_id, {'done' => true})

get

Get the value of an existing item:

>>> api.todo.get(_id)
{'title' => 'Create a startup to kill email', 'done' => true}

delete

Remove an existing item:

>>> api.todo.delete(_id)

index

Retreives a page of the items in this bucket, which have been most recently modified.

data — if true, the current data for each item is returned in the result

mark — set the start of the page of items to be returned to this mark

limit — number of items to return. default is 100. max is 1000.

since — limit the page of items to be returned to those modified since the given mark

>>> api.todo.index(:data=>false, :mark=>nil, :limit=>nil, :since=>nil)

Returns:

{
    'current' =>  # head cv of the most recently modified document,
    'mark' =>     # cv to use to pull the next page of documents. only
                  # included in the repsonse if there are remaining pages
                  # to fetch.
    'count' =>    # the total count of documents available,

    'index' => [{
        'id' =>  # id of the document,
        'v' =>   # current version of the document,
        'd' =>   # optionally current data of the document, if
                 # data is requested
        }, {....}],
    }

changes

Polls Simperium for changes being made for the currently authed user on this bucket.

cv — listen for changes after this cv.

timeout — how long to wait for a new change to be available before returning. By default the changes call will wait forever.

>>> api.todo.changes(:cv=>nil, :timeout=>nil)

all

Polls Simperium for changes all being made on this bucket, regardless of the user who made the change. This call requires an API key with admin privileges when initializing the Api

cv — listen for changes after this cv.

data — if true, also include the latest version of the data for the changed document

username — if true, the username for the user who created the change will also be included

most_recent — if true, then if a document has been modified several times since the last all call, only the most recent change for that document will be returned.

timeout — how long to wait for a new change to be available before returning. By default the all call will wait forever.

>>> api.todo.all(:cv=>nil, :data=>false, :username=>false, :most_recent=>false, :timeout=>nil)