Ruby Client for Fauna API
Add this line to your application's Gemfile:
gem 'fauna'
And then execute:
$ bundle
Or install it yourself as:
$ gem install fauna
This library has been tested in the next rubies:
- MRI 1.9.3
- MRI 2.0.0-rc1
- JRuby 1.6.8
- Rubinius 2.0.0-rc1
Reports about other rubies are welcome.
To get started configure the client with your publisher key:
Fauna.configure do |config|
config.publisher_key = 'AQAASaskOlAAAQBJqyQLYAABe4PIuvsylBEAUrLuxtKJ8A'
end
The classes can be managed through the Fauna::Class
wrapper class,
this can be used to create, find, update and delete classes:
# Create henwen class
Fauna::Class.create("henwen")
# You can also add arbitrary data to classes on creation
Fauna::Class.create("henwen", "name" => "Hen Wen")
# Update henwen class data
Fauna::Class.update("henwen", "name" => "Henwen")
# Find all classes
classes = Fauna::Class.find("classes")
# Find henwen class
henwen = Fauna::Class.find("classes/henwen")
# Delete henwen class
henwen = Fauna::Class.delete("classes/henwen")
Instances of classes can be managed with the Fauna::Instance
wrapper:
# Create an instance of henwen class
Fauna::Instance.create("henwen")
# Create an instance of henwen class with arbritary data
instance = Fauna::Instance.create("henwen", "used" => false)
# Save ref for use in future (ex. instances/20735848002617345)
ref = instance['resource']['ref']
# Update an instance using the ref
Fauna::Instance.update(ref, "used" => true)
# Delete an instance using the ref
Fauna::Instance.delete(ref)
Custom Timelines can be managed with the Fauna::TimelineSettings
wrapper:
# Create a timeline named comments and set permission for actions
Fauna::TimelineSettings.create("comments", "read" => "everyone", "write" => "follows", "notify" => "followers")
# Update settings of a timeline
Fauna::TimelineSettings.update("timelines/comments", "read" => "everyone", "write" => "everyone", "notify" => "followers"))
# Delete a timeline using the ref
Fauna::TimelineSettings.delete("timelines/comments")
Events are added to timelines with the Fauna::Event
wrapper, a full
example of use with other resources:
Fauna::TimelineSettings.create("comments", "read" => "everyone", "write" => "follows", "notify" => "followers")
Fauna::Class.create("post")
Fauna::Class.create("comment")
post = Fauna::Instance.create("post", "title" => "My first post", "content" => "Hello World")
post_ref = post["resource"]["ref"]
comment = Fauna::Instance.create("post", "body" => "Comment")
comment_ref = comment["resource"]["ref"]
# Add event to a timeline
Fauna::Event.create("#{post_ref}/timelines/comments", comment_ref)
# Retrieve all the events of the timeline
events = Fauna::Event.find("#{post_ref}/timelines/comments")
# Delete event from timeline
Fauna::Event.delete("#{post_ref}/timelines/comments", comment_ref)
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Copyright 2013 Fauna, Inc.
Licensed under the Mozilla Public License, Version 2.0 (the "License"); you may not use this software except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.