From d5d85fa56a9ec8c44b3e7642586c3cd1fc3aa952 Mon Sep 17 00:00:00 2001 From: Collin Guarino Date: Sun, 14 Feb 2016 23:13:17 -0500 Subject: Implemented Bridge.GetScene with ID. --- README.md | 4 ++-- scene.go | 15 +++++++++++++++ scene_test.go | 3 +++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7ba8494..748992e 100644 --- a/README.md +++ b/README.md @@ -50,12 +50,12 @@ Pull requests happily accepted on GitHub - [ ] Delete schedule ##### Scenes -- [ ] Get all scenes +- [x] Get all scenes +- [x] Get scene by ID - [ ] Create scene - [ ] Modify scene - [ ] Recall scene - [ ] Delete scene -- [ ] Get scene ##### Sensors - [ ] Get all sensors diff --git a/scene.go b/scene.go index fdc4fcd..95fac29 100644 --- a/scene.go +++ b/scene.go @@ -52,3 +52,18 @@ func (bridge *Bridge) GetScenes() ([]Scene, error) { } return scenesList, nil } + +func (bridge *Bridge) GetScene(id string) (Scene, error) { + uri := fmt.Sprintf("/api/%s/scenes/%s", bridge.Username, id) + body, _, err := bridge.Get(uri) + if err != nil { + return Scene{}, err + } + + scene := Scene{} + err = json.Unmarshal(body, &scene) + if err != nil { + return Scene{}, err + } + return scene, nil +} diff --git a/scene_test.go b/scene_test.go index 82646d6..27998f6 100644 --- a/scene_test.go +++ b/scene_test.go @@ -18,4 +18,7 @@ func TestGetScenes(t *testing.T) { for scene := range scenes { fmt.Println("SCENE: ", scenes[scene]) } + + individual, _ := bridge.GetScene(scenes[0].ID) + fmt.Println("Individual scene: ", individual) } -- cgit v1.2.3