diff options
| author | Collin Guarino <collin.guarino@gmail.com> | 2016-01-25 22:20:11 -0500 | 
|---|---|---|
| committer | Collin Guarino <collin.guarino@gmail.com> | 2016-01-25 22:20:11 -0500 | 
| commit | 152c47f8a7eb85b8b728c738accfc15e308ba672 (patch) | |
| tree | a780042776d4deb106ef461bc39d1522f9e83de9 /bridge.go | |
| parent | d339d6e37fb3522623fb1f0b96c2005de5a27a63 (diff) | |
Working implementation for CreateUser with unit tests.
Diffstat (limited to 'bridge.go')
| -rw-r--r-- | bridge.go | 21 | 
1 files changed, 18 insertions, 3 deletions
| @@ -5,10 +5,12 @@ import (      "log"      "os"      "encoding/xml" +    "encoding/json"      "net/http"      "io/ioutil"      "runtime"      "fmt" +    "bytes"  )  type Bridge struct { @@ -75,14 +77,27 @@ func GetBridgeInfo(self *Bridge) {  }  func CreateUser(bridge *Bridge, deviceType string) (string, error) { +    // Construct the http POST +    params := map[string]string{"devicetype": deviceType} +    request, err := json.Marshal(params) +    if err != nil { +        return "", err +    } + +    // Send the request to create the user and read the response      uri := fmt.Sprintf("http://%s/api", bridge.IPAddress) -    response, err := http.PostForm(uri, uurl.Values{"deviceType": deviceType}) +    response, err := http.Post(uri, "text/json", bytes.NewReader(request))      if err != nil { -        // TODO: handle error +        return "", err      } -    defer response.Body.Close +    defer response.Body.Close()      body, err := ioutil.ReadAll(response.Body)      fmt.Printf(string(body)) + +    // TODO: handle description saying "link button not pressed" +    // ^ handle "error":{"type":101} + +    return string(body), err  }  // Log the date, time, file location, line number, and function. | 
