This repository has been archived by the owner on Oct 12, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathheartrate.go
51 lines (43 loc) · 1.4 KB
/
heartrate.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
package oura
import (
"context"
"net/http"
)
// Heartrate represents the data returned from the Oura API for a single heart rate measurement.
type Heartrate struct {
// Beats per minute
Bpm int `json:"bpm"`
// The supported heart rate types:
// * `awake`
// * `rest`
// * `sleep`
// * `session`
// * `live`
Source string `json:"source"`
// ISO 8601 formatted local timestamp indicating when the heart rate data was collected
Timestamp string `json:"timestamp"`
}
// Heartrates represents the data returned from the Oura API for a list of heart rate measurements.
type Heartrates struct {
Data []Heartrate `json:"data"`
// Pagination token
NextToken *string `json:"next_token,omitempty"`
}
// Heartrates gets the heart rate data for a specified Oura user within a given timeframe.
// If a start and end date are not provided, ie are empty strings, we fall back to Oura's defaults which are:
//
// startDatetime: endDatetime - 1 day
// endDatetime: current UTC date
func (c *Client) Heartrates(ctx context.Context, startDatetime, endDatetime, nextToken string) (*Heartrates, *http.Response, error) {
path := parametiseDatetime("v2/usercollection/heartrate", startDatetime, endDatetime, nextToken)
req, err := c.NewRequest(ctx, "GET", path, nil)
if err != nil {
return nil, nil, err
}
var data *Heartrates
resp, err := c.do(req, &data)
if err != nil {
return data, resp, err
}
return data, resp, nil
}