Exemplo n.º 1
0
func ExampleNestAPI_Set() {
	n := nestapi.New("https://someapp.firebaseio.com")

	v := map[string]interface{}{
		"foo": "bar",
		"bar": 1,
		"bez": []string{"hello", "world"},
	}
	if err := n.Set(v); err != nil {
		log.Fatal(err)
	}
}
Exemplo n.º 2
0
func ExampleNestAPI_StopWatching() {
	n := nestapi.New("https://someapp.firebaseio.com/some/value")
	notifications := make(chan nestapi.Event)
	if err := n.Watch(notifications); err != nil {
		log.Fatal(err)
	}

	go func() {
		for _ = range notifications {
		}
		log.Println("Channel closed")
	}()
	time.Sleep(10 * time.Millisecond) // let go routine start

	n.StopWatching()
}
Exemplo n.º 3
0
func ExampleNestAPI_Watch() {
	n := nestapi.New("https://someapp.firebaseio.com/some/value")
	notifications := make(chan nestapi.Event)
	if err := n.Watch(notifications); err != nil {
		log.Fatal(err)
	}

	for event := range notifications {
		log.Println("Event Received")
		log.Printf("Type: %s\n", event.Type)
		log.Printf("Data: %v\n", event.Data)
		if event.Type == nestapi.EventTypeError {
			log.Print("Error occurred, loop ending")
		}
	}
}
Exemplo n.º 4
0
func ExampleNestAPI_Auth() {
	n := nestapi.New("https://someapp.firebaseio.com")
	n.Auth("my-token")
}
Exemplo n.º 5
0
func ExampleNestAPI_Child() {
	n := nestapi.New("https://someapp.firebaseio.com")
	childNestAPI := n.Child("some/child/path")

	log.Printf("My new ref %s\n", childNestAPI)
}