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
/
clubs.go
163 lines (132 loc) · 3.52 KB
/
clubs.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package strava
import (
"encoding/json"
"fmt"
)
type ClubDetailed struct {
ClubSummary
Description string `json:"description"`
Type ClubType `json:"club_type"`
SportType SportType `json:"sport_type"`
City string `json:"city"`
State string `json:"state"`
Country string `json:"country"`
Private bool `json:"private"`
MemberCount int `json:"member_count"`
}
type ClubSummary struct {
Id int64 `json:"id"`
Name string `json:"name"`
ProfileMedium string `json:"profile_medium"` // URL to a 62x62 pixel profile picture
Profile string `json:"profile"` // URL to a 124x124 pixel profile picture
}
type ClubType string
var ClubTypes = struct {
CasualClub ClubType
RacingTeam ClubType
Shop ClubType
Company ClubType
Other ClubType
}{"casual_club", "racing_team", "shop", "company", "other"}
type SportType string
var SportTypes = struct {
Cycling SportType
Running SportType
Triathlon SportType
Other SportType
}{"cycling", "running", "triathlon", "other"}
type ClubsService struct {
client *Client
}
func NewClubsService(client *Client) *ClubsService {
return &ClubsService{client}
}
/*********************************************************/
type ClubsGetCall struct {
service *ClubsService
id int64
}
func (s *ClubsService) Get(clubId int64) *ClubsGetCall {
return &ClubsGetCall{
service: s,
id: clubId,
}
}
func (c *ClubsGetCall) Do() (*ClubDetailed, error) {
data, err := c.service.client.run("GET", fmt.Sprintf("/clubs/%d", c.id), nil)
if err != nil {
return nil, err
}
var club ClubDetailed
err = json.Unmarshal(data, &club)
if err != nil {
return nil, err
}
return &club, nil
}
/*********************************************************/
type ClubListMembersCall struct {
service *ClubsService
id int64
ops map[string]interface{}
}
func (s *ClubsService) ListMembers(clubId int64) *ClubListMembersCall {
return &ClubListMembersCall{
service: s,
id: clubId,
ops: make(map[string]interface{}),
}
}
func (c *ClubListMembersCall) Page(page int) *ClubListMembersCall {
c.ops["page"] = page
return c
}
func (c *ClubListMembersCall) PerPage(perPage int) *ClubListMembersCall {
c.ops["per_page"] = perPage
return c
}
func (c *ClubListMembersCall) Do() ([]*AthleteSummary, error) {
data, err := c.service.client.run("GET", fmt.Sprintf("/clubs/%d/members", c.id), c.ops)
if err != nil {
return nil, err
}
members := make([]*AthleteSummary, 0)
err = json.Unmarshal(data, &members)
if err != nil {
return nil, err
}
return members, nil
}
/*********************************************************/
type ClubListActivitiesCall struct {
service *ClubsService
id int64
ops map[string]interface{}
}
func (s *ClubsService) ListActivities(clubId int64) *ClubListActivitiesCall {
return &ClubListActivitiesCall{
service: s,
id: clubId,
ops: make(map[string]interface{}),
}
}
func (c *ClubListActivitiesCall) Page(page int) *ClubListActivitiesCall {
c.ops["page"] = page
return c
}
func (c *ClubListActivitiesCall) PerPage(perPage int) *ClubListActivitiesCall {
c.ops["per_page"] = perPage
return c
}
func (c *ClubListActivitiesCall) Do() ([]*ActivitySummary, error) {
data, err := c.service.client.run("GET", fmt.Sprintf("/clubs/%d/activities", c.id), c.ops)
if err != nil {
return nil, err
}
activities := make([]*ActivitySummary, 0)
err = json.Unmarshal(data, &activities)
if err != nil {
return nil, err
}
return activities, nil
}