-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdevices.go
49 lines (40 loc) · 852 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package dexcomClient
import (
"encoding/json"
"io/ioutil"
"net/http"
)
type Device struct {
Model string
LastUploadDate string
AlertSettings []AlertSetting
}
type AlertSetting struct {
AlertName string
Value int
Unit string
Snooze int
Delay int
Enabled bool
SystemTime string
DisplayTime string
}
func (client *DexcomClient) GetDevices() ([]*Device, error) {
url := client.config.getBaseUrl() + "/v1/users/self/devices"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("authorization", "Bearer ")
resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
var devices []*Device
err = json.Unmarshal(body, &devices)
if err != nil {
return nil, err
}
return devices, err
}