strava_wrapper/filters/
kudos.rs1use crate::models::{User};
2use crate::query::{
3 get_with_query_and_path, Endpoint, ErrorWrapper, Page, PageSize, PathQuery, Query,
4 Sendable, ID,
5};
6use async_trait::async_trait;
7use std::collections::HashMap;
8
9#[derive(Debug, Clone)]
10pub struct KudosFilter {
11 url: String,
12 token: String,
13 path: String,
14 query: Vec<(String, String)>,
15 path_params: Vec<(String, String)>,
16}
17
18impl KudosFilter {
19 pub fn new(url: impl Into<String>, token: impl Into<String>, path: impl Into<String>) -> Self {
20 Self {
21 url: url.into(),
22 token: token.into(),
23 path: path.into(),
24 query: Vec::new(),
25 path_params: Vec::new(),
26 }
27 }
28}
29
30impl Endpoint for KudosFilter {
31 fn endpoint(&self) -> String {
32 format!("{}/{}", self.url, self.path)
33 }
34}
35
36#[async_trait]
37impl Sendable<KudosFilter, Vec<User>> for KudosFilter {
38 async fn send(mut self) -> Result<Vec<User>, ErrorWrapper> {
39 get_with_query_and_path(self.clone(), &self.token).await
40 }
41}
42
43impl Query for KudosFilter {
44 fn get_query_params(self) -> Vec<(String, String)> {
45 self.query
46 }
47}
48
49impl PathQuery for KudosFilter {
50 fn get_path_params(&self) -> HashMap<String, String> {
51 self.path_params.iter().cloned().collect()
52 }
53}
54
55impl ID for KudosFilter {
56 fn id(mut self, id: u64) -> Self {
57 self.path_params.push(("id".to_string(), id.to_string()));
58 self
59 }
60}
61
62impl Page for KudosFilter {
63 fn page(mut self, number: u32) -> Self {
64 self.query.push(("page".to_string(), number.to_string()));
65 self
66 }
67}
68
69impl PageSize for KudosFilter {
70 fn page_size(mut self, size: u32) -> Self {
71 self.query.push(("per_page".to_string(), size.to_string()));
72 self
73 }
74}