-
Notifications
You must be signed in to change notification settings - Fork 29
/
LifetimeActivities.go
34 lines (27 loc) · 1.05 KB
/
LifetimeActivities.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
package connect
import (
"errors"
)
// LifetimeActivities is describing a basic summary of all activities.
type LifetimeActivities struct {
Activities int `json:"totalActivities"` // The number of activities
Distance float64 `json:"totalDistance"` // The total distance in meters
Duration float64 `json:"totalDuration"` // The duration of all activities in seconds
Calories float64 `json:"totalCalories"` // Energy in C
ElevationGain float64 `json:"totalElevationGain"` // Total elevation gain in meters
}
// LifetimeActivities will return some aggregated data about all activities.
func (c *Client) LifetimeActivities(displayName string) (*LifetimeActivities, error) {
URL := "https://connect.garmin.com/modern/proxy/userstats-service/statistics/" + displayName
var proxy struct {
Activities []LifetimeActivities `json:"userMetrics"`
}
err := c.getJSON(URL, &proxy)
if err != nil {
return nil, err
}
if len(proxy.Activities) != 1 {
return nil, errors.New("unexpected data")
}
return &proxy.Activities[0], err
}