This repository was 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 pathreadiness.go
62 lines (54 loc) · 1.86 KB
/
readiness.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
package oura
import (
"context"
"fmt"
"net/http"
"net/url"
)
// Readiness represents a single readiness entry.
type Readiness struct {
PeriodID int `json:"period_id"`
RestModeState int `json:"rest_mode_state"`
Score int `json:"score"`
ScoreActivityBalance int `json:"score_activity_balance"`
ScoreHrvBalance int `json:"score_hrv_balance"`
ScorePreviousDay int `json:"score_previous_day"`
ScorePreviousNight int `json:"score_previous_night"`
ScoreRecoveryIndex int `json:"score_recovery_index"`
ScoreRestingHr int `json:"score_resting_hr"`
ScoreSleepBalance int `json:"score_sleep_balance"`
ScoreTemperature int `json:"score_temperature"`
SummaryDate string `json:"summary_date"`
}
// ReadinessSummaries represents all readiness periods for the period requested.
type ReadinessSummaries struct {
ReadinessSummaries []Readiness `json:"readiness"`
}
// GetReadiness gets all of the readiness entries for a specified period of time.
// If a start and end date are not provided, ie are empty strings, we fall back to Oura which states:
//
// "If you omit the start date, it will be set to one week ago.
// If you omit the end date, it will be set to the current day."
func (c *Client) GetReadiness(ctx context.Context, start, end string) (*ReadinessSummaries, *http.Response, error) {
path := "v1/readiness"
params := url.Values{}
if start != "" {
params.Add("start", start)
}
if end != "" {
params.Add("end", end)
}
if len(params) > 0 {
path += fmt.Sprintf("?%s", params.Encode())
}
req, err := c.NewRequest(ctx, "GET", path, nil)
if err != nil {
return nil, nil, err
}
var readinessSummaries *ReadinessSummaries
resp, err := c.do(req, &readinessSummaries)
if err != nil {
return readinessSummaries, resp, err
}
return readinessSummaries, resp, nil
}