Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Commit

Permalink
Merge pull request #4 from lildude/api-updates
Browse files Browse the repository at this point in the history
Update to accommodate Oura API updates
  • Loading branch information
lildude committed Dec 3, 2021
2 parents 9b3a4c4 + 069332b commit da516f1
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 68 deletions.
50 changes: 28 additions & 22 deletions activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,43 @@ import (

// Activity represents a single activity
type Activity struct {
SummaryDate string `json:"summary_date"`
DayStart time.Time `json:"day_start"`
DayEnd time.Time `json:"day_end"`
Timezone int `json:"timezone"`
Score int `json:"score"`
ScoreStayActive int `json:"score_stay_active"`
ScoreMoveEveryHour int `json:"score_move_every_hour"`
ScoreMeetDailyTargets int `json:"score_meet_daily_targets"`
ScoreTrainingFrequency int `json:"score_training_frequency"`
ScoreTrainingVolume int `json:"score_training_volume"`
ScoreRecoveryTime int `json:"score_recovery_time"`
AverageMet float32 `json:"average_met"`
CalActive int `json:"cal_active"`
CalTotal int `json:"cal_total"`
Class5min string `json:"class_5min"`
DailyMovement int `json:"daily_movement"`
NonWear int `json:"non_wear"`
Rest int `json:"rest"`
DayEnd time.Time `json:"day_end"`
DayStart time.Time `json:"day_start"`
High int `json:"high"`
Inactive int `json:"inactive"`
InactivityAlerts int `json:"inactivity_alerts"`
Low int `json:"low"`
Medium int `json:"medium"`
High int `json:"high"`
Steps int `json:"steps"`
CalTotal int `json:"cal_total"`
CalActive int `json:"cal_active"`
Met1min []float32 `json:"met_1min"`
MetMinHigh int `json:"met_min_high"`
MetMinInactive int `json:"met_min_inactive"`
MetMinLow int `json:"met_min_low"`
MetMinMediumPlus int `json:"met_min_medium_plus"`
MetMinMedium int `json:"met_min_medium"`
MetMinHigh int `json:"met_min_high"`
AverageMet float32 `json:"average_met"`
Class5min string `json:"class_5min"`
Met1min []float32 `json:"met_1min"`
MetMinMediumPlus int `json:"met_min_medium_plus"`
NonWear int `json:"non_wear"`
Rest int `json:"rest"`
RestModeState int `json:"rest_mode_state"`
Score int `json:"score"`
ScoreMeetDailyTargets int `json:"score_meet_daily_targets"`
ScoreMoveEveryHour int `json:"score_move_every_hour"`
ScoreRecoveryTime int `json:"score_recovery_time"`
ScoreStayActive int `json:"score_stay_active"`
ScoreTrainingFrequency int `json:"score_training_frequency"`
ScoreTrainingVolume int `json:"score_training_volume"`
Steps int `json:"steps"`
SummaryDate string `json:"summary_date"`
TargetCalories int `json:"target_calories"`
TargetKm float32 `json:"target_km"`
TargetMiles float32 `json:"target_miles"`
Timezone int `json:"timezone"`
ToTargetKm float32 `json:"to_target_km"`
ToTargetMiles float32 `json:"to_target_miles"`
Total int `json:"total"`
}

// Activities represents all activities for a the period requested
Expand Down
2 changes: 1 addition & 1 deletion bedtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (

// Bedtime represents a single bedtime recommendation
type Bedtime struct {
Date string `json:"date"`
BedtimeWindow struct {
Start int `json:"start"`
End int `json:"end"`
} `json:"bedtime_window"`
Date string `json:"date"`
Status string `json:"status"`
}

Expand Down
2 changes: 1 addition & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestNewRequest(t *testing.T) {
t.Run("valid request", func(tc *testing.T) {

inURL, outURL := "foo", BaseURLV1+"foo"
inBody, outBody := &UserInfo{Age: 99, Weight: 102, Gender: "ano", Email: "user@example.com"}, `{"age":99,"weight":102,"gender":"ano","email":"user@example.com"}`+"\n"
inBody, outBody := &UserInfo{Age: 99, Weight: 102, Gender: "ano", Email: "user@example.com", Height: 184}, `{"age":99,"email":"user@example.com","gender":"ano","height":184,"weight":102}`+"\n"

req, err := c.NewRequest("GET", inURL, inBody)

Expand Down
48 changes: 45 additions & 3 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,56 @@ import (
// See the documentation on [Testing](https://golang.org/pkg/testing/#hdr-Examples)
// for further details.

func Example() {
func Example_getUserInfo() {
godotenv.Load(".env")
ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: os.Getenv("OURA_ACCESS_TOKEN")})
ctx := context.Background()
tc := oauth2.NewClient(ctx, ts)

cl := oura.NewClient(tc)

userInfo, _, _ := cl.GetUserInfo(ctx)
fmt.Println(userInfo.Age, userInfo.Gender, userInfo.Weight, userInfo.Email)
userInfo, httpResp, err := cl.GetUserInfo(ctx)
if err != nil {
fmt.Println(err)
fmt.Println(httpResp)
} else {
fmt.Println(userInfo.Age, userInfo.Gender, userInfo.Weight, userInfo.Email)
}
// Output
}

func Example_getSleep() {
godotenv.Load(".env")
ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: os.Getenv("OURA_ACCESS_TOKEN")})
ctx := context.Background()
tc := oauth2.NewClient(ctx, ts)

cl := oura.NewClient(tc)

sleepInfo, httpResp, err := cl.GetSleep(ctx, "2021-12-02", "2021-12-03")
if err != nil {
fmt.Println(err)
fmt.Println(httpResp)
} else {
fmt.Println(sleepInfo)
}
// Output
}

func Example_getActivities() {
godotenv.Load(".env")
ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: os.Getenv("OURA_ACCESS_TOKEN")})
ctx := context.Background()
tc := oauth2.NewClient(ctx, ts)

cl := oura.NewClient(tc)

activityInfo, httpResp, err := cl.GetActivities(ctx, "2021-12-02", "2021-12-03")
if err != nil {
fmt.Println(err)
fmt.Println(httpResp)
} else {
fmt.Println(activityInfo)
}
// Output
}
12 changes: 6 additions & 6 deletions readiness.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ import (

// Readiness represents a single readiness entry
type Readiness struct {
SummaryDate string `json:"summary_date"`
PeriodID int `json:"period_id"`
RestModeState int `json:"rest_mode_state"`
Score int `json:"score"`
ScorePreviousNight int `json:"score_previous_night"`
ScoreSleepBalance int `json:"score_sleep_balance"`
ScorePreviousDay int `json:"score_previous_day"`
ScoreActivityBalance int `json:"score_activity_balance"`
ScoreRestingHr int `json:"score_resting_hr"`
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"`
RestModeState int `json:"rest_mode_state"`
SummaryDate string `json:"summary_date"`
}

// ReadinessSummaries represents all readiness periods for the period requested
Expand Down
69 changes: 37 additions & 32 deletions sleep.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,43 @@ import (

// Sleep represents a single sleep entry
type Sleep struct {
SummaryDate string `json:"summary_date"`
PeriodID int `json:"period_id"`
IsLongest int `json:"is_longest"`
Timezone int `json:"timezone"`
BedtimeStart time.Time `json:"bedtime_start"`
BedtimeEnd time.Time `json:"bedtime_end"`
Score int `json:"score"`
ScoreTotal int `json:"score_total"`
ScoreDisturbances int `json:"score_disturbances"`
ScoreEfficiency int `json:"score_efficiency"`
ScoreLatency int `json:"score_latency"`
ScoreRem int `json:"score_rem"`
ScoreDeep int `json:"score_deep"`
ScoreAlignment int `json:"score_alignment"`
Total int `json:"total"`
Duration int `json:"duration"`
Awake int `json:"awake"`
Light int `json:"light"`
Rem int `json:"rem"`
Deep int `json:"deep"`
OnsetLatency int `json:"onset_latency"`
Restless int `json:"restless"`
Efficiency int `json:"efficiency"`
MidpointTime int `json:"midpoint_time"`
HrLowest int `json:"hr_lowest"`
HrAverage float32 `json:"hr_average"`
Rmssd int `json:"rmssd"`
BreathAverage float32 `json:"breath_average"`
TemperatureDelta float32 `json:"temperature_delta"`
Hypnogram5Min string `json:"hypnogram_5min"`
Hr5min []int `json:"hr_5min"`
Rmssd5min []int `json:"rmssd_5min"`
Awake int `json:"awake"`
BedtimeEnd time.Time `json:"bedtime_end"`
BedtimeEndDelta int `json:"bedtime_end_delta"`
BedtimeStart time.Time `json:"bedtime_start"`
BedtimeStartDelta int `json:"bedtime_start_delta"`
BreathAverage float32 `json:"breath_average"`
Deep int `json:"deep"`
Duration int `json:"duration"`
Efficiency int `json:"efficiency"`
Hr5min []int `json:"hr_5min"`
HrAverage float32 `json:"hr_average"`
HrLowest float32 `json:"hr_lowest"`
Hypnogram5Min string `json:"hypnogram_5min"`
IsLongest int `json:"is_longest"`
Light int `json:"light"`
MidpointAtDelta int `json:"midpoint_at_delta"`
MidpointTime int `json:"midpoint_time"`
OnsetLatency int `json:"onset_latency"`
PeriodID int `json:"period_id"`
Rem int `json:"rem"`
Restless int `json:"restless"`
Rmssd int `json:"rmssd"`
Rmssd5min []int `json:"rmssd_5min"`
Score int `json:"score"`
ScoreAlignment int `json:"score_alignment"`
ScoreDeep int `json:"score_deep"`
ScoreDisturbances int `json:"score_disturbances"`
ScoreEfficiency int `json:"score_efficiency"`
ScoreLatency int `json:"score_latency"`
ScoreRem int `json:"score_rem"`
ScoreTotal int `json:"score_total"`
SummaryDate string `json:"summary_date"`
TemperatureDelta float32 `json:"temperature_delta"`
TemperatureDeviation float32 `json:"temperature_deviation"`
TemperatureTrendDeviation float32 `json:"temperature_trend_deviation"`
Timezone int `json:"timezone"`
Total int `json:"total"`
}

// Sleeps represents all sleep periods for the period requested
Expand Down
5 changes: 3 additions & 2 deletions userinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (
// UserInfo is the information for the current user
type UserInfo struct {
Age int `json:"age"`
Weight float64 `json:"weight"`
Gender string `json:"gender"`
Email string `json:"email"`
Gender string `json:"gender"`
Height float64 `json:"height"`
Weight float64 `json:"weight"`
}

// GetUserInfo returns the user information for the current user
Expand Down
6 changes: 5 additions & 1 deletion userinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,31 @@ var infoTestCases = []struct {
mock: `{
"age": 27,
"weight": 80,
"height": 180,
"gender": "male",
"email": "john.doe@the.domain"
}`,
expected: UserInfo{
Age: 27,
Weight: 80.0,
Height: 180,
Gender: "male",
Email: "john.doe@the.domain",
},
},
{
name: "Info w/ weight as float",
name: "Info w/ weight & height as float",
mock: `{
"age": 27,
"weight": 80.0,
"height": 180.0,
"gender": "male",
"email": "john.doe@the.domain"
}`,
expected: UserInfo{
Age: 27,
Weight: 80.0,
Height: 180.0,
Gender: "male",
Email: "john.doe@the.domain",
},
Expand Down

0 comments on commit da516f1

Please sign in to comment.