-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathevents.go
48 lines (36 loc) · 1011 Bytes
/
events.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
package dexcomClient
import (
"encoding/json"
"io/ioutil"
"net/http"
)
const eventsUrl = "v1/users/self/events"
type Event struct {
SystemTime string `json:"systemTime"`
DisplayTime string `json:"displayTime"`
EventType string `json:"eventType"`
EventSubType string `json:"eventSubType"`
Value int `json:"value"`
Unit string `json:"unit"`
}
type EventResponse struct {
Events []Event `json:"events"`
}
func (client *DexcomClient) GetEvents(startDate, endDate string) ([]Event, error) {
req, _ := http.NewRequest("GET",
urlWithDateRange(client.config, eventsUrl, startDate, endDate), nil)
token, err := client.GetOauthToken()
if err != nil {
return nil, err
}
req.Header.Add("authorization", "Bearer " + token.AccessToken)
resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
}
body, _ := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
var response EventResponse
json.Unmarshal(body, &response)
return response.Events, nil
}