Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing to exclude secret on demand #2

Merged
merged 3 commits into from
Dec 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ This module is based on [Firebase's REST API](https://firebase.google.com/docs/r
| :--- |
| [**1) Properties**](https://github.com/marckrenn/framer-Firebase#1-properties) |
| \|--- [firebase**.projectID**, **.secret**](https://github.com/marckrenn/framer-Firebase#-firebaseprojectid-firebasesecret) |
| \|--- [firebase**.debug**](https://github.com/marckrenn/framer-Firebase#-firebasedebug) |
| \|--- [firebase**.secret**](https://github.com/marckrenn/framer-Firebase#-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) |
| \|--- [firebase**.get**()](https://github.com/marckrenn/framer-Firebase#-firebasegetpath-callback-parameters) |
Expand Down Expand Up @@ -113,6 +114,24 @@ firebase = new Firebase

<br />

#### • firebase.secret
---
If you wish not to share your *secret*, please follow the next steps.

1. Simply, do not use *secret* on your code. (remove it if you have already)
2. Go to *Console* → *YourProject* → *Database* → *RULES*
3. Change the rules of `.read` and `.write` to `true` like the following:
```json
{
"rules": {
".read": "true",
".write": "true"
}
}
```

<br />

#### • firebase.debug
---
If set to **true**, relevant connection messages will be logged to the console.
Expand Down
19 changes: 10 additions & 9 deletions firebase.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@ class exports.Firebase extends Framer.BaseClass
@secret = @options.secret ?= null
@debug = @options.debug ?= false
@_status ?= "disconnected"
super

@secretEndPoint = if @secret then "?auth=#{@secret}" else ""
super

console.log "Firebase: Connecting to Firebase Project '#{@projectID}' ... \n URL: 'https://#{@projectID}.firebaseio.com'" if @debug
@.onChange "connection"


request = (project, secret, path, callback, method, data, parameters, debug) ->

url = "https://#{project}.firebaseio.com#{path}.json?auth=#{secret}"
url = "https://#{project}.firebaseio.com#{path}.json#{secret}"


unless parameters is undefined
Expand Down Expand Up @@ -87,11 +88,11 @@ class exports.Firebase extends Framer.BaseClass

# Available methods

get: (path, callback, parameters) -> request(@projectID, @secret, path, callback, "GET", null, parameters, @debug)
put: (path, data, callback, parameters) -> request(@projectID, @secret, path, callback, "PUT", data, parameters, @debug)
post: (path, data, callback, parameters) -> request(@projectID, @secret, path, callback, "POST", data, parameters, @debug)
patch: (path, data, callback, parameters) -> request(@projectID, @secret, path, callback, "PATCH", data, parameters, @debug)
delete: (path, callback, parameters) -> request(@projectID, @secret, path, callback, "DELETE", null, parameters, @debug)
get: (path, callback, parameters) -> request(@projectID, @secretEndPoint, path, callback, "GET", null, parameters, @debug)
put: (path, data, callback, parameters) -> request(@projectID, @secretEndPoint, path, callback, "PUT", data, parameters, @debug)
post: (path, data, callback, parameters) -> request(@projectID, @secretEndPoint, path, callback, "POST", data, parameters, @debug)
patch: (path, data, callback, parameters) -> request(@projectID, @secretEndPoint, path, callback, "PATCH", data, parameters, @debug)
delete: (path, callback, parameters) -> request(@projectID, @secretEndPoint, path, callback, "DELETE", null, parameters, @debug)



Expand All @@ -100,7 +101,7 @@ class exports.Firebase extends Framer.BaseClass

if path is "connection"

url = "https://#{@projectID}.firebaseio.com/.json?auth=#{@secret}"
url = "https://#{@projectID}.firebaseio.com/.json#{@secretEndPoint}"
currentStatus = "disconnected"
source = new EventSource(url)

Expand All @@ -121,7 +122,7 @@ class exports.Firebase extends Framer.BaseClass

else

url = "https://#{@projectID}.firebaseio.com#{path}.json?auth=#{@secret}"
url = "https://#{@projectID}.firebaseio.com#{path}.json#{@secretEndPoint}"
source = new EventSource(url)
console.log "Firebase: Listening to changes made to '#{path}' \n URL: '#{url}'" if @debug

Expand Down