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
/
workout.go
72 lines (58 loc) · 2.14 KB
/
workout.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
67
68
69
70
71
72
package oura
import (
"context"
"net/http"
"time"
)
// Workout represents the data returned from the Oura API for a single workout.
type Workout struct {
// The workout activity type
Activity string `json:"activity"`
// The number of calories (kcal) burned during the workout
Calories *float32 `json:"calories,omitempty"`
// The `YYYY-MM-DD` formatted local date indicating when the workout was recorded
Day string `json:"day"`
// The distance (measured in meters) traveled during the workout
Distance *float32 `json:"distance,omitempty"`
// ISO 8601 formatted local timestamp indicating when the workout ended
EndDatetime time.Time `json:"end_datetime"`
// The workout intensity:
// * `easy`
// * `moderate`
// * `hard`
Intensity string `json:"intensity"`
// User-defined label for the workout
Label *string `json:"label,omitempty"`
// The data source where the Workout data was collected from:
// * `manual` Workouts which were manually entered by the user
// * `autodetected` Workouts autodetected by Oura
// * `confirmed` Workouts autodetected by Oura and confirmed by the user
// * `workout_heart_rate` Workouts recorded with the Workout HR feature
Source string `json:"source"`
// ISO 8601 formatted local timestamp indicating when the workout started
StartDatetime time.Time `json:"start_datetime"`
}
// Workouts represents the workout data within a given timeframe.
type Workouts struct {
Data []Workout `json:"data"`
// Pagination token
NextToken *string `json:"next_token,omitempty"`
}
// Workouts gets the workout data 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:
//
// startDate: endDate - 1 day
// endDate: current UTC date
func (c *Client) Workouts(ctx context.Context, startDate, endDate, nextToken string) (*Workouts, *http.Response, error) {
path := parametiseDate("v2/usercollection/workout", startDate, endDate, nextToken)
req, err := c.NewRequest(ctx, "GET", path, nil)
if err != nil {
return nil, nil, err
}
var data *Workouts
resp, err := c.do(req, &data)
if err != nil {
return data, resp, err
}
return data, resp, nil
}