-
Notifications
You must be signed in to change notification settings - Fork 4
/
devices.go
41 lines (35 loc) · 1.06 KB
/
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
35
36
37
38
39
40
41
package fitbit
import (
"encoding/json"
"fmt"
"strconv"
)
// https://dev.fitbit.com/build/reference/web-api/devices/
// Device contains information about a fitbit device
type Device struct {
Battery string `json:"battery"`
BatteryLevel int `json:"batteryLevel,omitempty"`
DeviceVersion string `json:"deviceVersion"`
Features []interface{} `json:"features"`
ID string `json:"id"`
LastSyncTime string `json:"lastSyncTime"`
Mac string `json:"mac,omitempty"`
Type string `json:"type"`
}
// Devices returns
func (m *Session) Devices(userID uint64) ([]Device, error) {
// Default "-" is current logged in user
requestID := "-"
if userID > 0 {
requestID = strconv.FormatUint(userID, 10)
}
contents, err := m.makeRequest(fmt.Sprintf("https://api.fitbit.com/1/user/%s/devices.json", requestID))
if err != nil {
return []Device{}, err
}
device := []Device{}
if err := json.Unmarshal(contents, &device); err != nil {
return []Device{}, err
}
return device, nil
}