-
Notifications
You must be signed in to change notification settings - Fork 27
/
ActivityHrZones.go
41 lines (33 loc) · 1.05 KB
/
ActivityHrZones.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
package connect
import (
"fmt"
"time"
)
// ActivityHrZones describes the heart-rate zones during an activity.
type ActivityHrZones struct {
TimeInZone time.Duration `json:"secsInZone"`
ZoneLowBoundary int `json:"zoneLowBoundary"`
ZoneNumber int `json:"zoneNumber"`
}
// ActivityHrZones returns the reported heart-rate zones for an activity.
func (c *Client) ActivityHrZones(activityID int) ([]ActivityHrZones, error) {
URL := fmt.Sprintf("https://connect.garmin.com/modern/proxy/activity-service/activity/%d/hrTimeInZones",
activityID,
)
var proxy []struct {
TimeInZone float64 `json:"secsInZone"`
ZoneLowBoundary int `json:"zoneLowBoundary"`
ZoneNumber int `json:"zoneNumber"`
}
err := c.getJSON(URL, &proxy)
if err != nil {
return nil, err
}
zones := make([]ActivityHrZones, len(proxy))
for i, p := range proxy {
zones[i].TimeInZone = time.Duration(p.TimeInZone * float64(time.Second))
zones[i].ZoneLowBoundary = p.ZoneLowBoundary
zones[i].ZoneNumber = p.ZoneNumber
}
return zones, nil
}