forked from llun/sensibo-golang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpods.go
52 lines (43 loc) · 1.09 KB
/
pods.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package sensibo
import (
"encoding/json"
"errors"
"net/url"
)
type RemoteCapabilities struct {
Modes map[string]interface{} `json:"modes"`
}
type Room struct {
Name string `json:"name"`
Icon string `json:"icon"`
}
type Pod struct {
ID string `json:"id"`
Room Room `json:"room"`
MacAddress string `json:"macAddress"`
ProductModel string `json:"productModel"`
RemoteCapabilities RemoteCapabilities `json:"remoteCapabilities"`
}
type PodResult struct {
Status string `json:"status"`
Result []Pod `json:"result"`
}
// GetPods gets information on all pods on account
func (s *Sensibo) GetPods() ([]Pod, error) {
values := url.Values{
"fields": []string{"id,room,productModel,macAddress,remoteCapabilities"},
}
data, err := s.get("users/me/pods", values)
if err != nil {
return nil, err
}
var result PodResult
err = json.Unmarshal(data, &result)
if err != nil {
return nil, err
}
if result.Status != "success" {
return nil, errors.New("Cannot get pods")
}
return result.Result, nil
}