Skip to main content

strava_wrapper/filters/
athlete.rs

1use crate::models::{Activity, DetailedAthlete, SummaryClub};
2use crate::query::{
3    get_with_query_and_path, put_form, After, Before, Endpoint, ErrorWrapper, Page, PathQuery,
4    PerPage, Query, Sendable,
5};
6use async_trait::async_trait;
7use serde::Serialize;
8use std::collections::HashMap;
9use strava_wrapper_macros::{After, Before, Endpoint, Page, PathQuery, PerPage, Query};
10
11#[derive(Debug, Clone, Endpoint, Query, PathQuery)]
12#[must_use = "this request is not executed until you call .send().await"]
13pub struct GetAthlete {
14    url: String,
15    token: String,
16    path: String,
17    query: Vec<(String, String)>,
18    path_params: Vec<(String, String)>,
19}
20
21#[async_trait]
22impl Sendable<DetailedAthlete> for GetAthlete {
23    async fn send(self) -> Result<DetailedAthlete, ErrorWrapper> {
24        let token = self.token.clone();
25        get_with_query_and_path(self, &token).await
26    }
27}
28
29#[derive(Debug, Clone, Endpoint, Query, PathQuery)]
30#[must_use = "this request is not executed until you call .send().await"]
31pub struct ListAthleteClubs {
32    url: String,
33    token: String,
34    path: String,
35    query: Vec<(String, String)>,
36    path_params: Vec<(String, String)>,
37}
38
39#[async_trait]
40impl Sendable<Vec<SummaryClub>> for ListAthleteClubs {
41    async fn send(self) -> Result<Vec<SummaryClub>, ErrorWrapper> {
42        let token = self.token.clone();
43        get_with_query_and_path(self, &token).await
44    }
45}
46
47#[derive(Debug, Clone, Endpoint, Query, PathQuery, Before, After, Page, PerPage)]
48#[must_use = "this request is not executed until you call .send().await"]
49pub struct ListAthleteActivities {
50    url: String,
51    token: String,
52    path: String,
53    query: Vec<(String, String)>,
54    path_params: Vec<(String, String)>,
55}
56
57#[async_trait]
58impl Sendable<Vec<Activity>> for ListAthleteActivities {
59    async fn send(self) -> Result<Vec<Activity>, ErrorWrapper> {
60        let token = self.token.clone();
61        get_with_query_and_path(self, &token).await
62    }
63}
64
65#[derive(Debug, Clone, Serialize)]
66struct UpdateAthleteBody {
67    weight: f32,
68}
69
70/// Builder for `PUT /athlete`. Strava currently only allows updating the
71/// athlete's weight via the public API.
72#[must_use = "this request is not executed until you call .send().await"]
73pub struct UpdateAthlete {
74    url: String,
75    token: String,
76    weight: f32,
77}
78
79impl UpdateAthlete {
80    pub fn new(url: impl Into<String>, token: impl Into<String>, weight: f32) -> Self {
81        Self {
82            url: url.into(),
83            token: token.into(),
84            weight,
85        }
86    }
87}
88
89#[async_trait]
90impl Sendable<DetailedAthlete> for UpdateAthlete {
91    async fn send(self) -> Result<DetailedAthlete, ErrorWrapper> {
92        let url = format!("{}/v3/athlete", self.url);
93        put_form(
94            &url,
95            &self.token,
96            &UpdateAthleteBody {
97                weight: self.weight,
98            },
99        )
100        .await
101    }
102}