• Stars
    star
    688
  • Rank 65,712 (Top 2 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 12 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Ruby wrapper for Firebase

firebase Build Status Gem Version

Ruby wrapper for the Firebase REST API.

Changes are sent to all subscribed clients automatically, so you can update your clients in realtime from the backend.

See a video demo of what's possible.

Installation

gem install firebase

Usage

base_uri = 'https://<your-firebase>.firebaseio.com/'

firebase = Firebase::Client.new(base_uri)

response = firebase.push("todos", { :name => 'Pick the milk', :'.priority' => 1 })
response.success? # => true
response.code # => 200
response.body # => { 'name' => "-INOQPH-aV_psbk3ZXEX" }
response.raw_body # => '{"name":"-INOQPH-aV_psbk3ZXEX"}'

Authentication

If you have a read-only namespace, you need to authenticate your Firebase client. firebase-ruby will attempt to determine if you are using the old or new authentication method by whether your auth string is a valid JSON string or not.

Using Firebase Database Secret (deprecated)

# Using Firebase Database Secret (deprecated)
firebase = Firebase::Client.new(base_uri, db_secret)

Using Firebase Admin SDK private key

Go to the Firebase console and under Project Settings -> Service Accounts -> Firebase Admin SDK click on GENERATE NEW PRIVATE KEY. Save the json file and use it like this:

# Using Firebase Admin SDK private key
private_key_json_string = File.open('/path/to/your/generated/json').read
firebase = Firebase::Client.new(base_uri, private_key_json_string)

You can now pass custom query options to firebase:

response = firebase.push("todos", :limit => 1)

To populate a value with a Firebase server timestamp, you can set Firebase::ServerValue::TIMESTAMP as a normal value. This is analogous to passing Firebase.ServerValue.TIMESTAMP in the official JavaScript client.

response = firebase.push("todos", {
  :name => 'Pick the milk',
  :created => Firebase::ServerValue::TIMESTAMP
})

To update multiple values that are not direct descendants, supply their paths as keys in the payload to update:

# note the empty path string here as the first argument
firebase.update('', {
  "users/posts/#{postID}" => true,
  "posts/#{postID}" => text
})

So far, supported methods are:

set(path, data, query_options)
get(path, query_options)
push(path, data, query_options)
delete(path, query_options)
update(path, data, query_options)

Configuring HTTP options

httpclient is used under the covers to make HTTP requests. You may find yourself wanting to tweak the timeout settings. By default, httpclient uses some sane defaults, but it is quite easy to change them by modifying the request object directly:

firebase = Firebase::Client.new(base_uri)
# firebase.request is a regular httpclient object
firebase.request.connect_timeout = 30

More information about Firebase and the Firebase API is available at the official website.

Copyright

Copyright (c) 2013 Oscar Del Ben. See LICENSE.txt for further details.

More Repositories

1

Color-Picker-Pro

Color Detection Tool for Designers and Developers
Objective-C
506
star
2

sheet

Text snippets for the command line
Ruby
261
star
3

rawler

Rawler is a tool that crawls the links of your website
Ruby
248
star
4

words-about-code

My technical blog
172
star
5

RailsOneClick

Rails One Click installer for Mac Os X
Objective-C
157
star
6

DateCalculations

Date Calculations for Cocoa Inspired by Ruby on Rails
Objective-C
125
star
7

git-diff-grep

Run grep across git diffs history
Shell
93
star
8

github-trends

Provides a RSS Feed for most watched and most forked repos on Github
Ruby
43
star
9

Mongo-Shortener

Shortener application that uses MongoDB, cucumber and rspec
Ruby
40
star
10

CameraGun

Point And Fire Augmented Reality App for iPhone
Objective-C
37
star
11

MenuBarApplicationTemplate

A common template for kick starting your menu bar mac application
Objective-C
36
star
12

iPhoneCalculator

Proof of Concept iPhone Calculator App
Objective-C
34
star
13

GithubBrowser

A Github Browser For iPad
Objective-C
27
star
14

json_formatter

Simple JSON formatter command line utility
Ruby
22
star
15

CocoaNavigationGestures

Recognize two and three fingers scroll and swipe gestures in Leopard and Lion
Objective-C
21
star
16

NSScreen-PointConversion

Utility class for working with multiple screens in Cocoa
20
star
17

rubyxp

Ruby regular expression tester
Ruby
16
star
18

UIWebViewBasicAuth

Add basic auth headers to your UIWebView
13
star
19

pow-client

Pow wrapper for the command line
Ruby
12
star
20

UIRightButtonCell

UITableViewCell with right button that detects touches. Similar to the one in the App Store
Objective-C
12
star
21

FRDynamicScrollView

Dynamic Scroll View for iOS
Objective-C
10
star
22

cocoa-gitignore

Gitignore sample for Cocoa projects
10
star
23

rake_notifier

Notify of Rake exceptions via email
Ruby
8
star
24

routes

Routes library for ruby
Ruby
8
star
25

CocoaYoutubeUploader

Upload videos to Youtube from Cocoa
Objective-C
7
star
26

Snake4iPhone

Snake for iPhone
Objective-C
6
star
27

newsite

newsite is a command line generator for static websites
Ruby
4
star
28

CoreGraphicExamples

CG Examples
Objective-C
4
star
29

Personal-Development

Personal Development Wiki
4
star
30

dot-files

My dot files
Vim Script
4
star
31

httpmock

A Go http://golang.org/ Http Mocking Library
Go
2
star
32

NSFileManager-DirectoryLocations

2
star
33

Fructivity-Website

Fructivity Source code
JavaScript
2
star
34

apue

Code from apue
C
2
star
35

GreenBoardPro

Green Board Pro is an iphone app for keeping track of ideas
Objective-C
2
star
36

Rails-One-Click-Website

Rails One Click Website
CSS
2
star
37

FoodReminder

Objective-C
2
star
38

Ruby-Stat

Stats for Ruby Code
Ruby
2
star
39

tokyocabinet_rails

An example app that uses Tokyo Cabinet for storing records
Ruby
2
star
40

Hare

Toy webserver in Ruby
Ruby
1
star
41

oscardelben.github.com

HTML
1
star
42

acts_as_restricted_subdomain

Allows a Rails application to run multiple subdomain sites transparently inside of a single Rails instance
Ruby
1
star
43

tokyocabinet_cache

An example of fragment caching implementation for Rails
1
star
44

capo

Run multiple commands at the same time
Go
1
star
45

Crazy-Tests

Having fun with test unit
Ruby
1
star