-
Notifications
You must be signed in to change notification settings - Fork 4
/
activity_summary_day.go
82 lines (77 loc) · 3.11 KB
/
activity_summary_day.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
74
75
76
77
78
79
80
81
82
package fitbit
import (
"encoding/json"
"fmt"
"time"
)
// ActivitiesSummaryDay contains a summary of activities of a requested day
type ActivitiesSummaryDay struct {
Activities []struct {
ActivityID int `json:"activityId"`
ActivityParentID int `json:"activityParentId"`
ActivityParentName string `json:"activityParentName"`
Calories int `json:"calories"`
Description string `json:"description"`
DetailsLink string `json:"detailsLink,omitempty"`
Distance float64 `json:"distance"`
Duration int `json:"duration"`
HasActiveZoneMinutes bool `json:"hasActiveZoneMinutes"`
HasStartTime bool `json:"hasStartTime"`
IsFavorite bool `json:"isFavorite"`
LastModified time.Time `json:"lastModified"`
LogID int64 `json:"logId"`
Name string `json:"name"`
StartDate string `json:"startDate"`
StartTime string `json:"startTime"`
Steps int `json:"steps"`
} `json:"activities"`
Goals struct {
ActiveMinutes int `json:"activeMinutes"`
CaloriesOut int `json:"caloriesOut"`
Distance float64 `json:"distance"`
Floors int `json:"floors"`
Steps int `json:"steps"`
} `json:"goals"`
Summary struct {
ActiveScore int `json:"activeScore"`
ActivityCalories int `json:"activityCalories"`
CalorieEstimationMu int `json:"calorieEstimationMu"`
CaloriesBMR int `json:"caloriesBMR"`
CaloriesOut int `json:"caloriesOut"`
CaloriesOutUnestimated int `json:"caloriesOutUnestimated"`
Distances []struct {
Activity string `json:"activity"`
Distance float64 `json:"distance"`
} `json:"distances"`
Elevation float64 `json:"elevation"`
FairlyActiveMinutes int `json:"fairlyActiveMinutes"`
Floors int `json:"floors"`
HeartRateZones []struct {
CaloriesOut float64 `json:"caloriesOut"`
Max int `json:"max"`
Min int `json:"min"`
Minutes int `json:"minutes"`
Name string `json:"name"`
} `json:"heartRateZones"`
LightlyActiveMinutes int `json:"lightlyActiveMinutes"`
MarginalCalories int `json:"marginalCalories"`
RestingHeartRate int `json:"restingHeartRate"`
SedentaryMinutes int `json:"sedentaryMinutes"`
Steps int `json:"steps"`
UseEstimation bool `json:"useEstimation"`
VeryActiveMinutes int `json:"veryActiveMinutes"`
} `json:"summary"`
}
// ActivitiesDaySummary returns the summary of activities and made exercises
// date must be in the format yyyy-MM-dd
func (m *Session) ActivitiesDaySummary(day string) (ActivitiesSummaryDay, error) {
contents, err := m.makeRequest(fmt.Sprintf("https://api.fitbit.com/1/user/-/activities/date/%s.json", day))
if err != nil {
return ActivitiesSummaryDay{}, err
}
summary := ActivitiesSummaryDay{}
if err := json.Unmarshal(contents, &summary); err != nil {
return ActivitiesSummaryDay{}, err
}
return summary, nil
}