diff options
author | Collin Guarino <collin.guarino@gmail.com> | 2016-02-13 15:38:28 -0500 |
---|---|---|
committer | Collin Guarino <collin.guarino@gmail.com> | 2016-02-13 15:38:28 -0500 |
commit | 53ff4073d99569177348dbc3a6e46c9008767e93 (patch) | |
tree | a97f62a7640daf0dc71827a746805039b3861595 /bridge.go | |
parent | 22608c316da825445dddd5e42adc3f771506ffe2 (diff) |
Cleaned up Bridge.CreateUser
Diffstat (limited to 'bridge.go')
-rw-r--r-- | bridge.go | 20 |
1 files changed, 7 insertions, 13 deletions
@@ -129,6 +129,9 @@ func HandleResponse(resp *http.Response) ([]byte, io.Reader, error) { reader := bytes.NewReader(body) log.Println("Handled response:\n--------------------\n", string(body) + "\n--------------------\n") + if strings.Contains(string(body), "error") { + return []byte{}, nil, errors.New(string(body)) + } return body, reader, nil } @@ -175,22 +178,13 @@ func (self *Bridge) GetInfo() (BridgeInfo, error) { } // CreateUser posts to ./api on the bridge to create a new whitelisted user. -func (bridge *Bridge) CreateUser(deviceType string) (string, error) { - // Send an HTTP POST with the body content +func (bridge *Bridge) CreateUser(deviceType string) error { params := map[string]string{"devicetype": deviceType} - body, _, err := bridge.Post("/api", params) + _, _, err := bridge.Post("/api", params) if err != nil { - return "", err - } - - // Parse the result and return it - result := string(body) - errFound := strings.Contains(result, "error") - noLink := strings.Contains(result, "link button not pressed") - if errFound && noLink { - return "", errors.New("Bridge link button not pressed.") + return err } - return "", nil + return nil } // Log the date, time, file location, line number, and function. |