aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCollin Guarino <collin.guarino@gmail.com>2016-01-28 20:08:26 -0500
committerCollin Guarino <collin.guarino@gmail.com>2016-01-28 20:08:26 -0500
commit27b9932aa92b7cf92d782aedbfb891747e52ea43 (patch)
treeffb0c0a399a52e7013775556a31e11f977e3387d
parent726f39d58986ad0b72dc0a94f0ad9d0138fb73a7 (diff)
Condensed BridgeInfo struct into one with embedded structs.
-rw-r--r--bridge.go40
1 files changed, 23 insertions, 17 deletions
diff --git a/bridge.go b/bridge.go
index 1106682..eda2f25 100644
--- a/bridge.go
+++ b/bridge.go
@@ -20,22 +20,20 @@ type Bridge struct {
}
type BridgeInfo struct {
- XMLName xml.Name `xml:"root"`
- Device Device `xml:"device"`
-}
-
-type Device struct {
- XMLName xml.Name `xml:"device"`
- DeviceType string `xml:"deviceType"`
- FriendlyName string `xml:"friendlyName"`
- Manufacturer string `xml:"manufacturer"`
- ManufacturerURL string `xml:"manufacturerURL"`
- ModelDescription string `xml:"modelDescription"`
- ModelName string `xml:"modelName"`
- ModelNumber string `xml:"modelNumber"`
- ModelURL string `xml:"modelURL"`
- SerialNumber string `xml:"serialNumber"`
- UDN string `xml:"UDN"`
+ Info struct {
+ Info struct {
+ DeviceType string `xml:"deviceType"`
+ FriendlyName string `xml:"friendlyName"`
+ Manufacturer string `xml:"manufacturer"`
+ ManufacturerURL string `xml:"manufacturerURL"`
+ ModelDescription string `xml:"modelDescription"`
+ ModelName string `xml:"modelName"`
+ ModelNumber string `xml:"modelNumber"`
+ ModelURL string `xml:"modelURL"`
+ SerialNumber string `xml:"serialNumber"`
+ UDN string `xml:"UDN"`
+ } `xml:"device"`
+ } `xml:"root"`
}
// NewBridge defines hardware that is compatible with Hue.
@@ -104,7 +102,15 @@ func CreateUser(bridge *Bridge, deviceType string) (string, error) {
}
defer response.Body.Close()
body, err := ioutil.ReadAll(response.Body)
- fmt.Println(string(body))
+ log.Println(string(body))
+
+ data := []Error{}
+ err = json.Unmarshal(body, &data)
+ if err != nil {
+ trace("", err)
+ os.Exit(1)
+ }
+ fmt.Println(data)
// TODO: decode and return
// TODO: handle errors. http://www.developers.meethue.com/documentation/error-messages