aboutsummaryrefslogtreecommitdiff
path: root/bridge.go
diff options
context:
space:
mode:
authorCollin Guarino <collin.guarino@gmail.com>2016-02-13 16:25:32 -0500
committerCollin Guarino <collin.guarino@gmail.com>2016-02-13 16:25:32 -0500
commit70cb715f896d605b7ebeb512f6903264fcc79964 (patch)
tree51d581e2f463a8accc1b52a25017a71087805af0 /bridge.go
parent53ff4073d99569177348dbc3a6e46c9008767e93 (diff)
Implemented Bridge.DeleteUser func and tweaked Bridge.CreateUser
Diffstat (limited to 'bridge.go')
-rw-r--r--bridge.go20
1 files changed, 18 insertions, 2 deletions
diff --git a/bridge.go b/bridge.go
index 878494f..5d1ea35 100644
--- a/bridge.go
+++ b/bridge.go
@@ -177,10 +177,26 @@ func (self *Bridge) GetInfo() (BridgeInfo, error) {
return data, nil
}
-// CreateUser posts to ./api on the bridge to create a new whitelisted user.
+// Bridge.CreateUser posts to ./api on the bridge to create a new whitelisted user.
func (bridge *Bridge) CreateUser(deviceType string) error {
params := map[string]string{"devicetype": deviceType}
- _, _, err := bridge.Post("/api", params)
+ body, _, err := bridge.Post("/api", params)
+ if err != nil {
+ return err
+ }
+ content := string(body)
+ username := content[strings.LastIndex(content, ":\"")+2 :
+ strings.LastIndex(content, "\"")]
+ bridge.Username = username
+ return nil
+}
+
+// Bridge.DeleteUser will delete a user given its USER KEY, not the string name.
+// See http://www.developers.meethue.com/documentation/configuration-api
+// for description on `username` deprecation in place of the devicetype key.
+func (bridge *Bridge) DeleteUser(username string) error {
+ uri := fmt.Sprintf("/api/%s/config/whitelist/%s", bridge.Username, username)
+ err := bridge.Delete(uri)
if err != nil {
return err
}