Skip to main content

ddapi_rs/api/
ddstats.rs

1use crate::api::DDApi;
2use crate::scheme::ddstats::*;
3use anyhow::Result;
4use std::future::Future;
5
6pub trait DDstats {
7    fn s_player(&self, player: &str) -> impl Future<Output = Result<Player>> + Send;
8    fn s_map(&self, map: &str) -> impl Future<Output = Result<Map>> + Send;
9    fn s_maps(&self) -> impl Future<Output = Result<Vec<StatsMap>>> + Send;
10    fn s_profile(&self, player: &str) -> impl Future<Output = Result<Profile>> + Send;
11}
12
13impl DDstats for DDApi {
14    /// # Examples
15    ///
16    /// ```rust,ignore
17    /// use ddapi_rs::prelude::*;
18    /// use ddapi_rs::prelude::ddstats::*;
19    ///
20    /// let api = DDApi::new();
21    /// let player: Player = api.s_player("Aoe").await?;
22    /// println!("{}: {} | {}", player.profile.name, player.profile.points, player.profile.clan.unwrap_or(String::default()));
23    /// ```
24    async fn s_player(&self, player: &str) -> Result<Player> {
25        self._generator(&Player::api(player)).await
26    }
27
28    /// # Examples
29    ///
30    /// ```rust,ignore
31    /// use ddapi_rs::prelude::*;
32    /// use ddapi_rs::prelude::ddstats::*;
33    ///
34    /// let api = DDApi::new();
35    /// let map: Map = api.s_map("Fox").await?;
36    /// println!("{}: {} | {}", map.info.map.map, map.info.map.stars, map.info.finishes);
37    /// ```
38    async fn s_map(&self, map: &str) -> Result<Map> {
39        self._generator(&Map::api(map)).await
40    }
41
42    /// # Examples
43    ///
44    /// ```rust,ignore
45    /// use ddapi_rs::prelude::*;
46    /// use ddapi_rs::prelude::ddstats::*;
47    ///
48    /// let api = DDApi::new();
49    /// let maps: Vec<StatsMap> = api.s_maps().await?;
50    /// for map in &maps {
51    ///     println!("{}: {} | {}", map.map, map.stars, map.points);
52    /// }
53    /// ```
54    async fn s_maps(&self) -> Result<Vec<StatsMap>> {
55        self._generator(&StatsMap::api()).await
56    }
57
58    /// # Examples
59    ///
60    /// ```rust,ignore
61    /// use ddapi_rs::prelude::*;
62    /// use ddapi_rs::prelude::ddstats::*;
63    ///
64    /// let api = DDApi::new();
65    /// let player: Profile = api.s_profile("ByFox").await?;
66    /// println!("{}: {}", player.name, player.clan.unwrap_or(String::default()));
67    /// ```
68    async fn s_profile(&self, player: &str) -> Result<Profile> {
69        self._generator(&Profile::api(player)).await
70    }
71}