-
Notifications
You must be signed in to change notification settings - Fork 6
/
devices.go
34 lines (28 loc) · 855 Bytes
/
devices.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
package fitbit
import (
"encoding/json"
)
type Device struct {
Battery string `json:"battery"`
Id string `json:"id"`
LastSyncTime string `json:"lastSyncTime"`
Type string `json:"type"` //Types: {TRACKER|SCALE}
DeviceVersion string `json:"deviceVersion"` //Types: {Flex|One|Zip|Ultra|Classic|Aria}
}
type GetDevices []*Device
// GetDevices is a method that returns all the devices connected to a specific user
// It returns an collection of 'Device' when succeful
func (c *Client) GetDevices() (GetDevices, error) {
//Build requestURL and GET data
responseBody, err := c.getData("user/-/devices.json")
if err != nil {
return nil, err
}
//Parse data
devicesData := GetDevices{}
err = json.NewDecoder(responseBody).Decode(&devicesData)
if err != nil {
return nil, err
}
return devicesData, nil
}