From 779dcafebdca3282c5bcd8855ab006ab7328e49c Mon Sep 17 00:00:00 2001 From: Collin Guarino Date: Sat, 30 Jan 2016 12:11:47 -0500 Subject: Hacky json parsing in CreateUser. Will fix later. --- bridge.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'bridge.go') diff --git a/bridge.go b/bridge.go index eda2f25..90a6f12 100644 --- a/bridge.go +++ b/bridge.go @@ -10,7 +10,9 @@ import ( "io/ioutil" "runtime" "fmt" + "strings" "bytes" + "errors" ) type Bridge struct { @@ -102,20 +104,21 @@ func CreateUser(bridge *Bridge, deviceType string) (string, error) { } defer response.Body.Close() body, err := ioutil.ReadAll(response.Body) - log.Println(string(body)) - - data := []Error{} - err = json.Unmarshal(body, &data) if err != nil { trace("", err) - os.Exit(1) } - fmt.Println(data) + + result := string(body) + errFound := strings.Contains(result, "error") + noLink := strings.Contains(result, "link button not pressed") + if errFound && noLink { + return "", errors.New("Link button not pressed.") + } // TODO: decode and return // TODO: handle errors. http://www.developers.meethue.com/documentation/error-messages - return "", err + return "", nil } // Log the date, time, file location, line number, and function. -- cgit v1.2.3