项目作者: alekcz

项目描述 :
A lightweight clojure client for Firebase based using the REST API. Basically Charmander 2.0
高级语言: Clojure
项目地址: git://github.com/alekcz/fire.git
创建时间: 2020-04-18T08:07:11Z
项目社区:https://github.com/alekcz/fire

开源协议:Eclipse Public License 2.0

下载


fire

A lightweight clojure client for Firebase based on the REST API. Basically Charmander 2.0

Status

master codecov Dependencies Status Clojars Project

Prerequisites

For fire you will need to create a Realtime Database on Firebase and retrieve the service account credentials.

  1. Get the json file containing your service account creditials by following the instruction here https://cloud.google.com/docs/authentication/getting-started
  2. Copy the contents of your .json into the GOOGLE_APPLICATION_CREDENTIALS environment variable. In your ~/.bash_profile and in Travis CI you should escape your credentials using singe quotes (‘).

Usage

[alekcz/fire "0.5.0"]

Interacting with Realtime Database

Creating your auth token

  1. (require '[fire.core :as fire]
  2. '[fire.auth :as auth])
  3. (def auth (auth/create-token "GOOGLE_APPLICATION_CREDENTIALS"))

Write to the specified location (will overwrite any existing data):

  1. (fire/write! "protected-db-name" "/path" {:map "with data"} auth)
  2. (fire/write! "public-db-name" "/path" {:map "with data"} nil)
  3. ; => {:map "with data"}

Read data from the specified location:

  1. (fire/read "protected-db-name" "/path" auth)
  2. (fire/read "public-db-name" "/path" nil)
  3. ; => {:map "with data"}

Update data at the specified location (only updates the specified fields):

  1. (fire/update! "protected-db-name" "/path" {:more "data"} auth)
  2. (fire/update! "public-db-name" "/path" {:more "data"} nil)
  3. ; => {:map "with data" :more "data"}

Add data at the specified location with an automatically generated key:

  1. (fire/push! "protected-db-name" "/path" {:map "with data"} auth)
  2. (fire/push! "public-db-name" "/path" {:map "with data"} nil)
  3. ; => {"name" "-IoZ3DZlTTQIkR0c7iVK"}

Delete at the specified locations:

  1. (fire/delete! "protected-db-name" "/path" auth)
  2. (fire/delete! "public-db-name" "/path" nil)
  3. ; => nil

Query data at the specified locations:
Note that if the child key is not indexed firebase will respond with error 400. Also :orderBy is required for all queries.
See the Firebase query docs for more info.

  1. (fire/read "protected-db-name" "/path" auth {:query {:orderBy "child-key" :startAt 10 :endAt 50}})
  2. (fire/read "protected-db-name" "/path" auth {:query {:orderBy "child-key" :equalTo 10}})
  3. (fire/read "public-db-name" "/path" nil {:query {:orderBy "child-key" :limitToFirst 10}})
  4. (fire/read "public-db-name" "/path" nil {:query {:orderBy "child-key" :limitToLast 3}})
  5. ; => nil

Interacting with Firebase Storage

Creating your auth token

  1. (require '[fire.storage :as storage]
  2. '[fire.auth :as auth])
  3. (def auth (auth/create-token "GOOGLE_APPLICATION_CREDENTIALS"))

Upload data or a file to Firebase Storage

  1. (spit "path/on/firebase.txt" "this is fire")
  2. (storage/upload! "path/on/firebase.txt" "path/on/disk/storage.txt" "text/plain" auth)
  3. (storage/upload! "path/on/firebase.txt" non-string-data-in-memory "text/plain" auth)

Download data to memory or a file from Firebase Storage

  1. (store/download "path/on/firebase.txt" auth) ;=> "this is fire"
  2. (store/download-to-file "path/on/firebase.txt" "downloads/storage.txt" auth)
  3. (slurp "downloads/storage.txt") ;=> "this is fire"

Add data at the specified location with an automatically generated key:

  1. (store/delete! "path/on/firebase.txt" auth)

Thanks

Special thanks to:

License

Copyright © 2020 Alexander Oloo

This program and the accompanying materials are made available under the
terms of the Eclipse Public License 2.0 which is available at
http://www.eclipse.org/legal/epl-2.0.

This Source Code may also be made available under the following Secondary
Licenses when the conditions for such availability set forth in the Eclipse
Public License, v. 2.0 are satisfied: GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or (at your
option) any later version, with the GNU Classpath Exception which is available
at https://www.gnu.org/software/classpath/license.html.