forked from strava/go.strava
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsegment_efforts.go
75 lines (59 loc) · 1.85 KB
/
segment_efforts.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
package strava
import (
"encoding/json"
"fmt"
"time"
)
type SegmentEffortDetailed struct {
SegmentEffortSummary
}
type SegmentEffortSummary struct {
EffortSummary
Segment SegmentSummary `json:"segment"`
AverageCadence float64 `json:"average_cadence"`
AveragePower float64 `json:"average_watts"`
AverageHeartrate float64 `json:"average_heartrate"`
MaximumHeartrate float64 `json:"max_heartrate"`
KOMRank int `json:"kom_rank"` // 1-10 rank on segment at time of upload
PRRank int `json:"pr_rank"` // 1-3 personal record on segment at time of upload
Hidden bool `json:"hidden"`
}
type SegmentEffortsService struct {
client *Client
}
func NewSegmentEffortsService(client *Client) *SegmentEffortsService {
return &SegmentEffortsService{client}
}
/*********************************************************/
type SegmentEffortsGetCall struct {
service *SegmentEffortsService
id int64
}
func (s *SegmentEffortsService) Get(segmentEffortId int64) *SegmentEffortsGetCall {
return &SegmentEffortsGetCall{
service: s,
id: segmentEffortId,
}
}
func (c *SegmentEffortsGetCall) Do() (*SegmentEffortDetailed, error) {
data, err := c.service.client.run("GET", fmt.Sprintf("/segment_efforts/%d", c.id), nil)
if err != nil {
return nil, err
}
var effort SegmentEffortDetailed
err = json.Unmarshal(data, &effort)
if err != nil {
return nil, err
}
effort.postProcessDetailed()
return &effort, nil
}
/*********************************************************/
func (e *SegmentEffortDetailed) postProcessDetailed() {
e.postProcessSummary()
}
func (e *SegmentEffortSummary) postProcessSummary() {
e.Segment.postProcess()
e.StartDate, _ = time.Parse(timeFormat, e.StartDateString)
e.StartDateLocal, _ = time.Parse(timeFormat, e.StartDateLocalString)
}