bw_web_api_rs/endpoints/
matchmaker_gameinfo_by_toon.rs

1use crate::endpoints::Endpoint;
2use crate::error::ApiError;
3use crate::models::MatchmakerGameInfo;
4use crate::types::Gateway;
5
6pub struct MatchmakerGameInfoEndpoint {
7    toon: String,
8    gateway: Gateway,
9    gamemode: u32,
10    season: u32,
11    offset: Option<u32>,
12    limit: Option<u32>,
13}
14
15impl MatchmakerGameInfoEndpoint {
16    pub fn new(
17        toon: String,
18        gateway: Gateway,
19        gamemode: u32,
20        season: u32,
21        offset: Option<u32>,
22        limit: Option<u32>,
23    ) -> Self {
24        Self {
25            toon,
26            gateway,
27            gamemode,
28            season,
29            offset,
30            limit,
31        }
32    }
33}
34
35impl Endpoint for MatchmakerGameInfoEndpoint {
36    type Request = ();
37    type Response = MatchmakerGameInfo;
38
39    fn endpoint(&self) -> String {
40        let mut url = format!(
41            "/web-api/v1/matchmaker-gameinfo-by-toon/{}/{}/{}/{}",
42            urlencoding::encode(&self.toon),
43            self.gateway as i32,
44            self.gamemode,
45            self.season
46        );
47
48        if let Some(offset) = self.offset {
49            url.push_str(&format!("?offset={}", offset));
50            if let Some(limit) = self.limit {
51                url.push_str(&format!("&limit={}", limit));
52            }
53        } else if let Some(limit) = self.limit {
54            url.push_str(&format!("?limit={}", limit));
55        }
56
57        url
58    }
59}
60
61impl crate::client::ApiClient {
62    /// Get matchmaker game information for a specific player
63    ///
64    /// Endpoint: /web-api/v1/matchmaker-gameinfo-by-toon/{toon}/{gateway}/{gamemode}/{season}
65    pub async fn get_matchmaker_gameinfo(
66        &self,
67        toon: String,
68        gateway: Gateway,
69        gamemode: u32,
70        season: u32,
71        offset: Option<u32>,
72        limit: Option<u32>,
73    ) -> Result<MatchmakerGameInfo, ApiError> {
74        let endpoint =
75            MatchmakerGameInfoEndpoint::new(toon, gateway, gamemode, season, offset, limit);
76        self.request(&endpoint, &()).await
77    }
78}