Simperuby

A Ruby client for the Simperium API

View the Project on GitHub pheuter/Simperuby

Simperuby

Simperuby is a Ruby client for the Simperium API.

Usage

gem install simperuby

require 'simperuby'
client = Simperuby.new :app_id => 'appid', :api_key => 'apikey'

Creating a new user

client.create 'user@email.com', 'password'
=> {"username"=>"user@email.com", "access_token"=>"9c0624b72a3e4e818dcf7e24ec1a52d8", "userid"=>"06ab494e1bc34cec0dd7ab36c36002fd"}

Note: creating a user automatically authorizes client

Authorizing an existing user

client.authorize 'user@email.com', 'password'
=> {"username"=>"user@email.com", "access_token"=>"9c0624b72a3e4e818dcf7e24ec1a52d8", "userid"=>"06ab494e1bc34cec0dd7ab36c36002fd"}

Create new object

client['testbucket'].new :title => "An Amazing Day", :author => "Anonymous"
=> "wJhn3ZOdZDsgJWt6SLq3oq8zrz4R5zyE"

Retrieve object data

client['testbucket']['wJhn3ZOdZDsgJWt6SLq3oq8zrz4R5zyE']
=> {"author"=>"Anonymous", "title"=>"An Amazing Day"} 

Update an object

client['testbucket']['wJhn3ZOdZDsgJWt6SLq3oq8zrz4R5zyE'] = { :author => "Me", :year => 2012 }
=> {:author=>"Me", :year=>2012}

Note: this does not replace the original object, only updates/inserts provided attributes

Delete object

client['testbucket'].delete 'wJhn3ZOdZDsgJWt6SLq3oq8zrz4R5zyE'

Retrieve items in bucket

client['testbucket'].index
=> {"current"=>"4fab239737a4015dce203f5f", "index"=>[{"id"=>"wJhn3ZOdZDsgJWt6SLq3oq8zrz4R5zyE", "v"=>2}]}

client['testbucket'].index :data => true, :limit => 1
=> {"current"=>"4fab239737a4015dce203f5f", "index"=>[{"d"=>{"year"=>2012, "author"=>"Me", "title"=>"An Amazing Day"}, "id"=>"wJhn3ZOdZDsgJWt6SLq3oq8zrz4R5zyE", "v"=>2}], "mark"=>"4fab239737a4015dce203f5f"}