Skip to content
This repository has been archived by the owner on Mar 31, 2019. It is now read-only.

Commit

Permalink
Merge pull request #41 from rakyll/merge
Browse files Browse the repository at this point in the history
Do not partition the code into multiple file if unnecessary
  • Loading branch information
zabawaba99 committed Apr 19, 2016
2 parents 19091c9 + d0980f1 commit 10eda08
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 82 deletions.
11 changes: 0 additions & 11 deletions auth.go

This file was deleted.

69 changes: 69 additions & 0 deletions firebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package firego

import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
Expand Down Expand Up @@ -53,6 +54,74 @@ type Firebase struct {
stopWatching chan struct{}
}

// Auth sets the custom Firebase token used to authenticate to Firebase.
func (fb *Firebase) Auth(token string) {
fb.params.Set(authParam, token)
}

// Unauth removes the current token being used to authenticate to Firebase.
func (fb *Firebase) Unauth() {
fb.params.Del(authParam)
}

// Push creates a reference to an auto-generated child location.
func (fb *Firebase) Push(v interface{}) (*Firebase, error) {
bytes, err := json.Marshal(v)
if err != nil {
return nil, err
}
bytes, err = fb.doRequest("POST", bytes)
if err != nil {
return nil, err
}
var m map[string]string
if err := json.Unmarshal(bytes, &m); err != nil {
return nil, err
}
return &Firebase{
url: fb.url + "/" + m["name"],
client: fb.client,
}, err
}

// Remove the Firebase reference from the cloud.
func (fb *Firebase) Remove() error {
_, err := fb.doRequest("DELETE", nil)
if err != nil {
return err
}
return nil
}

// Set the value of the Firebase reference.
func (fb *Firebase) Set(v interface{}) error {
bytes, err := json.Marshal(v)
if err != nil {
return err
}
_, err = fb.doRequest("PUT", bytes)
return err
}

// Update the specific child with the given value.
func (fb *Firebase) Update(v interface{}) error {
bytes, err := json.Marshal(v)
if err != nil {
return err
}
_, err = fb.doRequest("PATCH", bytes)
return err
}

// Value gets the value of the Firebase reference.
func (fb *Firebase) Value(v interface{}) error {
bytes, err := fb.doRequest("GET", nil)
if err != nil {
return err
}
return json.Unmarshal(bytes, v)
}

func sanitizeURL(url string) string {
if !strings.HasPrefix(url, "https://") && !strings.HasPrefix(url, "http://") {
url = "https://" + url
Expand Down
23 changes: 0 additions & 23 deletions push.go

This file was deleted.

10 changes: 0 additions & 10 deletions remove.go

This file was deleted.

13 changes: 0 additions & 13 deletions set.go

This file was deleted.

13 changes: 0 additions & 13 deletions update.go

This file was deleted.

12 changes: 0 additions & 12 deletions value.go

This file was deleted.

0 comments on commit 10eda08

Please sign in to comment.