Skip to main content

strava_wrapper/
endpoints.rs

1use crate::filters::activities::{CreateActivityRequest, GetActivity, UpdateActivityRequest};
2use crate::filters::activity_zones::ListActivityZones;
3use crate::filters::athlete::{GetAthlete, ListAthleteActivities, ListAthleteClubs, UpdateAthlete};
4use crate::filters::athlete_zones::GetAthleteZones;
5use crate::filters::clubs::{GetClub, GetClubMembers, ListClubActivities, ListClubAdmins};
6use crate::filters::comments::ListActivityComments;
7use crate::filters::gear::GetGear;
8use crate::filters::kudos::ListActivityKudoers;
9use crate::filters::laps::ListActivityLaps;
10use crate::filters::routes::{ExportGPXRoute, ExportTCXRoute, GetRoute, ListAthleteRoutes};
11use crate::filters::segment_efforts::{GetSegmentEffort, ListSegmentEfforts};
12use crate::filters::segments::{ExploreSegments, GetSegment, ListStarredSegments, StarSegment};
13use crate::filters::stats::GetAthleteStats;
14use crate::filters::streams::{
15    GetActivityStreams, GetRouteStreams, GetSegmentEffortStreams, GetSegmentStreams,
16};
17use crate::filters::uploads::{GetUpload, UploadActivity, UploadDataType};
18use crate::models::{CreateActivity, UpdatableActivity};
19use crate::query::Endpoint;
20
21pub struct ActivitiesEndpoint {
22    url: String,
23    token: String,
24}
25
26impl ActivitiesEndpoint {
27    pub fn new(url: impl Into<String>, token: impl Into<String>) -> Self {
28        Self {
29            url: url.into(),
30            token: token.into(),
31        }
32    }
33
34    pub fn get(&self) -> GetActivity {
35        GetActivity::new(&self.url, &self.token, "v3/activities/{id}")
36    }
37
38    pub fn comments(&self) -> ListActivityComments {
39        ListActivityComments::new(&self.url, &self.token, "v3/activities/{id}/comments")
40    }
41
42    pub fn kudos(&self) -> ListActivityKudoers {
43        ListActivityKudoers::new(&self.url, &self.token, "v3/activities/{id}/kudos")
44    }
45
46    pub fn laps(&self) -> ListActivityLaps {
47        ListActivityLaps::new(&self.url, &self.token, "v3/activities/{id}/laps")
48    }
49
50    pub fn zones(&self) -> ListActivityZones {
51        ListActivityZones::new(&self.url, &self.token, "v3/activities/{id}/zones")
52    }
53
54    pub fn create(&self, body: CreateActivity) -> CreateActivityRequest {
55        CreateActivityRequest::new(&self.url, &self.token, body)
56    }
57
58    pub fn update(&self, id: u64, body: UpdatableActivity) -> UpdateActivityRequest {
59        UpdateActivityRequest::new(&self.url, &self.token, id, body)
60    }
61}
62
63pub struct AthleteEndpoint {
64    url: String,
65    token: String,
66}
67
68impl AthleteEndpoint {
69    pub fn new(url: impl Into<String>, token: impl Into<String>) -> Self {
70        Self {
71            url: url.into(),
72            token: token.into(),
73        }
74    }
75
76    pub fn get(&self) -> GetAthlete {
77        GetAthlete::new(&self.url, &self.token, "v3/athlete")
78    }
79
80    pub fn zones(&self) -> GetAthleteZones {
81        GetAthleteZones::new(&self.url, &self.token, "v3/athlete/zones")
82    }
83
84    pub fn clubs(&self) -> ListAthleteClubs {
85        ListAthleteClubs::new(&self.url, &self.token, "v3/athlete/clubs")
86    }
87
88    pub fn activities(&self) -> ListAthleteActivities {
89        ListAthleteActivities::new(&self.url, &self.token, "v3/athlete/activities")
90    }
91
92    /// Update the authenticated athlete's weight.
93    pub fn update(&self, weight: f32) -> UpdateAthlete {
94        UpdateAthlete::new(&self.url, &self.token, weight)
95    }
96}
97
98pub struct AthletesEndpoint {
99    url: String,
100    token: String,
101}
102
103impl AthletesEndpoint {
104    pub fn new(url: impl Into<String>, token: impl Into<String>) -> Self {
105        Self {
106            url: url.into(),
107            token: token.into(),
108        }
109    }
110
111    pub fn stats(&self) -> GetAthleteStats {
112        GetAthleteStats::new(&self.url, &self.token, "v3/athletes/{id}/stats")
113    }
114
115    pub fn routes(&self) -> ListAthleteRoutes {
116        ListAthleteRoutes::new(&self.url, &self.token, "v3/athletes/{id}/routes")
117    }
118}
119
120pub struct ClubsEndpoint {
121    url: String,
122    token: String,
123}
124
125impl ClubsEndpoint {
126    pub fn new(url: impl Into<String>, token: impl Into<String>) -> Self {
127        Self {
128            url: url.into(),
129            token: token.into(),
130        }
131    }
132
133    pub fn activities(&self) -> ListClubActivities {
134        ListClubActivities::new(&self.url, &self.token, "v3/clubs/{id}/activities")
135    }
136
137    pub fn admins(&self) -> ListClubAdmins {
138        ListClubAdmins::new(&self.url, &self.token, "v3/clubs/{id}/admins")
139    }
140
141    pub fn get(&self) -> GetClub {
142        GetClub::new(&self.url, &self.token, "v3/clubs/{id}")
143    }
144
145    pub fn members(&self) -> GetClubMembers {
146        GetClubMembers::new(&self.url, &self.token, "v3/clubs/{id}/members")
147    }
148}
149
150pub struct GearEndpoint {
151    url: String,
152    token: String,
153}
154
155impl GearEndpoint {
156    pub fn new(url: impl Into<String>, token: impl Into<String>) -> Self {
157        Self {
158            url: url.into(),
159            token: token.into(),
160        }
161    }
162
163    pub fn get(&self) -> GetGear {
164        GetGear::new(&self.url, &self.token, "v3/gear/{id}")
165    }
166}
167
168pub struct RoutesEndpoint {
169    url: String,
170    token: String,
171}
172
173impl RoutesEndpoint {
174    pub fn new(url: impl Into<String>, token: impl Into<String>) -> Self {
175        Self {
176            url: url.into(),
177            token: token.into(),
178        }
179    }
180
181    pub fn export(&self) -> ExportRoute {
182        ExportRoute::new(&self.url, &self.token)
183    }
184
185    pub fn get(&self) -> GetRoute {
186        GetRoute::new(&self.url, &self.token, "v3/routes/{id}")
187    }
188}
189
190pub struct ExportRoute {
191    url: String,
192    token: String,
193}
194
195impl ExportRoute {
196    pub fn new(url: impl Into<String>, token: impl Into<String>) -> Self {
197        Self {
198            url: url.into(),
199            token: token.into(),
200        }
201    }
202
203    pub fn tcx(&self) -> ExportTCXRoute {
204        ExportTCXRoute::new(&self.url, &self.token, "v3/routes/{id}/export_tcx")
205    }
206
207    pub fn gpx(&self) -> ExportGPXRoute {
208        ExportGPXRoute::new(&self.url, &self.token, "v3/routes/{id}/export_gpx")
209    }
210}
211
212pub struct SegmentsEndpoint {
213    url: String,
214    token: String,
215}
216
217impl SegmentsEndpoint {
218    pub fn new(url: impl Into<String>, token: impl Into<String>) -> Self {
219        Self {
220            url: url.into(),
221            token: token.into(),
222        }
223    }
224
225    pub fn efforts(&self) -> SegmentEffort {
226        SegmentEffort::new(&self.url, &self.token)
227    }
228
229    pub fn explore(&self) -> ExploreSegments {
230        ExploreSegments::new(&self.url, &self.token, "v3/segments/explore")
231    }
232
233    pub fn starred(&self) -> ListStarredSegments {
234        ListStarredSegments::new(&self.url, &self.token, "v3/segments/starred")
235    }
236
237    pub fn get(&self) -> GetSegment {
238        GetSegment::new(&self.url, &self.token, "v3/segments/{id}")
239    }
240
241    /// Star or unstar a segment. Pass `true` to star, `false` to unstar.
242    pub fn star(&self, id: u64, starred: bool) -> StarSegment {
243        StarSegment::new(&self.url, &self.token, id, starred)
244    }
245}
246
247pub struct SegmentEffort {
248    url: String,
249    token: String,
250}
251
252impl SegmentEffort {
253    pub fn new(url: impl Into<String>, token: impl Into<String>) -> Self {
254        Self {
255            url: url.into(),
256            token: token.into(),
257        }
258    }
259
260    pub fn get(&self) -> GetSegmentEffort {
261        GetSegmentEffort::new(&self.url, &self.token, "v3/segment_efforts/{id}")
262    }
263
264    pub fn list(&self) -> ListSegmentEfforts {
265        ListSegmentEfforts::new(&self.url, &self.token, "v3/segment_efforts")
266    }
267}
268
269pub struct StreamsEndpoint {
270    url: String,
271    token: String,
272}
273
274impl StreamsEndpoint {
275    pub fn new(url: impl Into<String>, token: impl Into<String>) -> Self {
276        Self {
277            url: url.into(),
278            token: token.into(),
279        }
280    }
281
282    pub fn activity(&self) -> GetActivityStreams {
283        GetActivityStreams::new(&self.url, &self.token, "v3/activities/{id}/streams")
284    }
285
286    pub fn route(&self) -> GetRouteStreams {
287        GetRouteStreams::new(&self.url, &self.token, "v3/routes/{id}/streams")
288    }
289
290    pub fn segment_effort(&self) -> GetSegmentEffortStreams {
291        GetSegmentEffortStreams::new(&self.url, &self.token, "v3/segment_efforts/{id}/streams")
292    }
293
294    pub fn segment(&self) -> GetSegmentStreams {
295        GetSegmentStreams::new(&self.url, &self.token, "v3/segments/{id}/streams")
296    }
297}
298
299pub struct UploadsEndpoint {
300    url: String,
301    token: String,
302}
303
304impl UploadsEndpoint {
305    pub fn new(url: impl Into<String>, token: impl Into<String>) -> Self {
306        Self {
307            url: url.into(),
308            token: token.into(),
309        }
310    }
311
312    /// Start a new activity upload. `file` is the raw file bytes;
313    /// `data_type` identifies the format (e.g. `Fit`, `GpxGz`).
314    pub fn upload(&self, file: Vec<u8>, data_type: UploadDataType) -> UploadActivity {
315        UploadActivity::new(&self.url, &self.token, file, data_type)
316    }
317
318    /// Poll the processing status of a previously submitted upload.
319    pub fn get(&self) -> GetUpload {
320        GetUpload::new(&self.url, &self.token, "v3/uploads/{id}")
321    }
322}