diff --git a/README.md b/README.md index a309efb..5739359 100755 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ This module is based on [Firebase's REST API](https://firebase.google.com/docs/r | Table of contents | | :--- | | [**1) Properties**](https://github.com/marckrenn/framer-Firebase#1-properties) | -| \|--- [firebase**.projectID**, **.secret**, **.server**](https://github.com/marckrenn/framer-Firebase#-firebaseprojectid-firebasesecret-firebaseserver) | +| \|--- [firebase**.projectID**, **.secret**](https://github.com/marckrenn/framer-Firebase#-firebaseprojectid-firebasesecret) | | \|--- [firebase**.debug**](https://github.com/marckrenn/framer-Firebase#-firebasedebug) | | \|--- [firebase**.status**](https://github.com/marckrenn/framer-Firebase#-firebasestatus-read-only) | | [**2) Methods**](https://github.com/marckrenn/framer-Firebase#2-methods) | @@ -92,7 +92,7 @@ This module is based on [Firebase's REST API](https://firebase.google.com/docs/r ### 1) Properties -#### • firebase.projectID, firebase.secret, firebase.server +#### • firebase.projectID, firebase.secret --- The properties **projectID**, **secret** and **server** are required for the module to function properly. @@ -102,13 +102,12 @@ The required information is located at https://firebase.google.com → *Console* firebase = new Firebase projectID: ___________ # 1) ... Database → first part of URL secret: ______________ # 2) ... Project Settings → Database → Database Secrets - server: ______________ # 3) Get this info by setting `server: undefined´ first ``` -| 1) projectID | 2) secret | 3) server | -| :---: | :---: | :---: | -| ![gif for ants I](http://i.giphy.com/xT4uQFz8q6HAHKkfi8.gif) | ![gif for ants II](http://i.giphy.com/l3E6oeWMBJMc9Sk7u.gif) | ![gif for ants III](http://i.giphy.com/l3E6EnKJt8bySmMkU.gif) | +| 1) projectID | 2) secret | +| :---: | :---: | +| ![gif for ants I](http://i.giphy.com/xT4uQFz8q6HAHKkfi8.gif) | ![gif for ants II](http://i.giphy.com/l3E6oeWMBJMc9Sk7u.gif) | > **Protip:** Contrary to what I did in the gif, I advise you **NOT** to share your Firebase *secret* publicly, as it allow others to alter the data stored in your database. If you do so by accident, you can always revoke access by deleting the shared *secret* and creating a new one at https://firebase.google.com → *Console* → *Project Settings* → *Database* → *Database Secrets*. diff --git a/firebase.coffee b/firebase.coffee index 007e8e9..375e793 100644 --- a/firebase.coffee +++ b/firebase.coffee @@ -1,8 +1,8 @@ -# 'Firebase REST API Class' module v1.0 -# by Marc Krenn, June 22nd, 2016 | marc.krenn@gmail.com | @marc_krenn +# 'Firebase REST API Class' module v1.1 +# by Marc Krenn, September 21st, 2016 | marc.krenn@gmail.com | @marc_krenn # Documentation of this Module: https://github.com/marckrenn/framer-Firebase # ------ : ------- Firebase REST API: https://firebase.google.com/docs/reference/rest/database/ @@ -18,35 +18,18 @@ class exports.Firebase extends Framer.BaseClass - - getCORSurl = (server, path, secret, project) -> - - switch Utils.isWebKit() - when true then url = "https://#{server}#{path}.json?auth=#{secret}&ns=#{project}&sse=true" # Webkit XSS workaround - else url = "https://#{project}.firebaseio.com#{path}.json?auth=#{secret}" - - return url - - @.define "status", get: -> @_status # readOnly constructor: (@options={}) -> @projectID = @options.projectID ?= null @secret = @options.secret ?= null - @server = @options.server ?= undefined # required for WebKit XSS workaround @debug = @options.debug ?= false @_status ?= "disconnected" super - if @server is undefined - Utils.domLoadJSON "https://#{@projectID}.firebaseio.com/.settings/owner.json", (a,server) -> - print msg = "Add ______ server:" + ' "' + server + '"' + " _____ to your instance of Firebase." - console.log "Firebase: #{msg}" if @debug - - - console.log "Firebase: Connecting to Firebase Project '#{@projectID}' ... \n URL: '#{getCORSurl(@server, "/", @secret, @projectID)}'" if @debug + console.log "Firebase: Connecting to Firebase Project '#{@projectID}' ... \n URL: 'https://#{@projectID}.firebaseio.com'" if @debug @.onChange "connection" @@ -117,7 +100,7 @@ class exports.Firebase extends Framer.BaseClass if path is "connection" - url = getCORSurl(@server, "/", @secret, @projectID) + url = "https://#{@projectID}.firebaseio.com/.json?auth=#{@secret}" currentStatus = "disconnected" source = new EventSource(url) @@ -138,7 +121,7 @@ class exports.Firebase extends Framer.BaseClass else - url = getCORSurl(@server, path, @secret, @projectID) + url = "https://#{@projectID}.firebaseio.com#{path}.json?auth=#{@secret}" source = new EventSource(url) console.log "Firebase: Listening to changes made to '#{path}' \n URL: '#{url}'" if @debug @@ -148,4 +131,4 @@ class exports.Firebase extends Framer.BaseClass source.addEventListener "patch", (ev) => callback(JSON.parse(ev.data).data, "patch", JSON.parse(ev.data).path, _.tail(JSON.parse(ev.data).path.split("/"),1)) if callback? - console.log "Firebase: Received changes made to '#{path}' via 'PATCH': #{JSON.parse(ev.data).data} \n URL: '#{url}'" if @debug + console.log "Firebase: Received changes made to '#{path}' via 'PATCH': #{JSON.parse(ev.data).data} \n URL: '#{url}'" if @debug \ No newline at end of file