Simple client for Cloud Firestore
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
Pass environment variables for Firestore authentication
see https://cloud.google.com/ruby/docs/reference/google-cloud-firestore/latest/AUTHENTICATION
Firestore CRUD(Create/Read/Update/Delete) requires at least the following IAM Role
- Cloud Datastore User (
roles/datastore.user
)
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
https://sue445.github.io/kagaribi/Kagaribi/Collection
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.
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
Bug reports and pull requests are welcome on GitHub at https://github.com/sue445/kagaribi.
The gem is available as open source under the terms of the MIT License.