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
/
session.go
73 lines (60 loc) · 2.02 KB
/
session.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
73
package oura
import (
"context"
"net/http"
"time"
)
// Session represents the data returned from the Oura API for a single session.
type Session struct {
// The date when the session occurred
Day string `json:"day"`
// The end datetime when the session occurred
EndDatetime time.Time `json:"end_datetime"`
// Timeseries data represented by an array of numbers; this data is available for sessions longer than 5 minutes
HeartRate *timeSeriesData `json:"heart_rate,omitempty"`
// Timeseries data represented by an array of numbers; this data is available for sessions longer than 3 minutes
HeartRateVariability *timeSeriesData `json:"heart_rate_variability,omitempty"`
// The user's selected mood after the session:
// * `bad`
// * `worse`
// * `same`
// * `good`
// * `great`
Mood *string `json:"mood,omitempty"`
// Timeseries data represented by an array of numbers
MotionCount *timeSeriesData `json:"motion_count,omitempty"`
// The start datetime when the session occurred
StartDatetime time.Time `json:"start_datetime"`
// The session type:
// * `breathing`
// * `meditation`
// * `nap`
// * `relaxation`
// * `rest`
// * `body_status`
Type string `json:"type"`
}
// Sessions represents the data returned from the Oura API for a list of sessions.
type Sessions struct {
Data []Session `json:"data"`
// Pagination token
NextToken *string `json:"next_token,omitempty"`
}
// Sessions gets the session 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) Sessions(ctx context.Context, startDate, endDate, nextToken string) (*Sessions, *http.Response, error) {
path := parametiseDate("v2/usercollection/session", startDate, endDate, nextToken)
req, err := c.NewRequest(ctx, "GET", path, nil)
if err != nil {
return nil, nil, err
}
var data *Sessions
resp, err := c.do(req, &data)
if err != nil {
return data, resp, err
}
return data, resp, nil
}