Kagaribi(篝火) :fire:
Simple client for Cloud Firestore
Installation
Install the gem and add to the application’s Gemfile by executing:
$ bundle add kagaribi
If bundler is not being used to manage dependencies, install the gem by executing:
$ gem install kagaribi
Usage
Authentication
Pass environment variables for Firestore authentication
see cloud.google.com/ruby/docs/reference/google-cloud-firestore/latest/AUTHENTICATION
Requirements
Firestore CRUD(Create/Read/Update/Delete) requires at least the following IAM Role
-
Cloud Datastore User (
roles/datastore.user
)
Simple usage
require "kagaribi"
collection = Kagaribi.collection("users")
# or
class UsersCollection < Kagaribi::Collection
def initialize
super("users")
end
end
collection = UsersCollection.new
collection.set("sue445", name: "sue445", url: "https://github.com/sue445")
#=> document is stored in a key named "users/sue445" to Firestore collection
collection.get("sue445")
#=> { name: "sue445", url: "https://github.com/sue445" }
All methods are followings
sue445.github.io/kagaribi/Kagaribi/Collection
Features
Auto retry
The Cloud Firestore API is sometimes unstable.
Error, but retry the same operation and it may succeed.
Therefore, if an error occurs in some operations (e.g. Kagaribi::Collection#get), the retry will be performed automatically.
Development
At first, install Firebase Local Emulator Suite
Mac
brew install firebase-cli
Unix
sudo wget https://firebase.tools/bin/linux/latest -O /usr/local/bin/firebase --quiet
sudo chmod 755 /usr/local/bin/firebase
firebase setup:emulators:firestore
Run tests with Firebase Local Emulator
bundle exec rake spec
Contributing
Bug reports and pull requests are welcome on GitHub at github.com/sue445/kagaribi.
License
The gem is available as open source under the terms of the MIT License.