This repository has been archived by the owner on Feb 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 67
/
gear.go
85 lines (69 loc) · 1.44 KB
/
gear.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
83
84
85
package strava
import (
"encoding/json"
)
type GearDetailed struct {
GearSummary
BrandName string `json:"brand_name"`
ModelName string `json:"model_name"`
FrameType FrameType `json:"frame_type"`
Description string `json:"description"`
}
type GearSummary struct {
Id string `json:"id"`
Name string `json:"name"`
Primary bool `json:"primary"`
Distance float64 `json:"distance"`
}
type FrameType int
var FrameTypes = struct {
MountainBike FrameType
Cyclocross FrameType
Road FrameType
TimeTrial FrameType
}{1, 2, 3, 4}
type GearService struct {
client *Client
}
func NewGearService(client *Client) *GearService {
return &GearService{client}
}
/*********************************************************/
type GearGetCall struct {
service *GearService
id string
}
func (s *GearService) Get(gearId string) *GearGetCall {
return &GearGetCall{
service: s,
id: gearId,
}
}
func (c *GearGetCall) Do() (*GearDetailed, error) {
data, err := c.service.client.run("GET", "/gear/"+c.id, nil)
if err != nil {
return nil, err
}
var gear GearDetailed
err = json.Unmarshal(data, &gear)
if err != nil {
return nil, err
}
return &gear, nil
}
func (f FrameType) Id() int {
return int(f)
}
func (f FrameType) String() string {
switch f.Id() {
case 1:
return "Mountain Bike"
case 2:
return "Cyclocross"
case 3:
return "Road"
case 4:
return "Time Trial"
}
return "Bike Frame"
}