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
/
daily_sleep.go
66 lines (53 loc) · 1.91 KB
/
daily_sleep.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package oura
import (
"context"
"net/http"
"time"
)
// DailySleep represents the sleep data for a single day.
type DailySleep struct {
Contributors SleepContributors `json:"contributors"`
Day string `json:"day"`
Score *int `json:"score,omitempty"`
Timestamp time.Time `json:"timestamp"`
}
// DailySleeps represents the sleep data for a given timeframe.
type DailySleeps struct {
Data []DailySleep `json:"data"`
NextToken *string `json:"next_token,omitempty"`
}
// SleepContributors represents all the contributors to the sleep score.
type SleepContributors struct {
// Contribution of deep sleep in range `[1, 100]`.
DeepSleep *int `json:"deep_sleep"`
// Contribution of sleep efficiency in range `[1, 100]`.
Efficiency *int `json:"efficiency"`
// Contribution of sleep latency in range `[1, 100]`.
Latency *int `json:"latency"`
// Contribution of REM sleep in range `[1, 100]`.
RemSleep *int `json:"rem_sleep"`
// Contribution of sleep restfulness in range `[1, 100]`.
Restfulness *int `json:"restfulness"`
// Contribution of sleep timing in range `[1, 100]`.
Timing *int `json:"timing"`
// Contribution of total sleep in range `[1, 100]`.
TotalSleep *int `json:"total_sleep"`
}
// DailySleeps gets the daily sleep data for a specified period of time.
// If a start and end date are not provided, ie are empty strings, we fall back to Oura's defaults which are:
//
// startDate: endDate - 1 day
// endDate: current UTC date
func (c *Client) DailySleeps(ctx context.Context, startDate, endDate, nextToken string) (*DailySleeps, *http.Response, error) {
path := parametiseDate("/v2/usercollection/daily_sleep", startDate, endDate, nextToken)
req, err := c.NewRequest(ctx, "GET", path, nil)
if err != nil {
return nil, nil, err
}
var data *DailySleeps
resp, err := c.do(req, &data)
if err != nil {
return data, resp, err
}
return data, resp, nil
}