Skip to main content

ddapi_rs/api/
ddstats.rs

1use crate::api::{DDApi, DDstatsClient, HasApiCore};
2use crate::error::Result;
3use crate::scheme::ddstats::{Map, Player, Profile, StatsMap, Teero};
4use std::future::Future;
5
6pub trait DDstats {
7    fn player(&self, player: &str) -> impl Future<Output = Result<Player>> + Send;
8    fn map(&self, map: &str) -> impl Future<Output = Result<Map>> + Send;
9    fn maps(&self) -> impl Future<Output = Result<Vec<StatsMap>>> + Send;
10    fn profile(&self, player: &str) -> impl Future<Output = Result<Profile>> + Send;
11    fn teero(&self, player: &str) -> impl Future<Output = Result<Teero>> + Send;
12}
13
14impl DDstats for DDApi {
15    /// # Examples
16    ///
17    /// ```rust,ignore
18    /// use ddapi_rs::prelude::*;
19    /// use ddapi_rs::prelude::ddstats::*;
20    ///
21    /// let api = DDApi::new();
22    /// let player: Player = api.player("Aoe").await?;
23    /// println!("{}: {} | {}", player.profile.name, player.profile.points, player.profile.clan.unwrap_or(String::default()));
24    /// ```
25    async fn player(&self, player: &str) -> Result<Player> {
26        self.generator(&Player::api(player)).await
27    }
28
29    /// # Examples
30    ///
31    /// ```rust,ignore
32    /// use ddapi_rs::prelude::*;
33    /// use ddapi_rs::prelude::ddstats::*;
34    ///
35    /// let api = DDApi::new();
36    /// let map: Map = api.map("Fox").await?;
37    /// println!("{}: {} | {}", map.info.map.map, map.info.map.stars, map.info.finishes);
38    /// ```
39    async fn map(&self, map: &str) -> Result<Map> {
40        self.generator(&Map::api(map)).await
41    }
42
43    /// # Examples
44    ///
45    /// ```rust,ignore
46    /// use ddapi_rs::prelude::*;
47    /// use ddapi_rs::prelude::ddstats::*;
48    ///
49    /// let api = DDApi::new();
50    /// let maps: Vec<StatsMap> = api.maps().await?;
51    /// for map in &maps {
52    ///     println!("{}: {} | {}", map.map, map.stars, map.points);
53    /// }
54    /// ```
55    async fn maps(&self) -> Result<Vec<StatsMap>> {
56        self.generator(&StatsMap::api()).await
57    }
58
59    /// # Examples
60    ///
61    /// ```rust,ignore
62    /// use ddapi_rs::prelude::*;
63    /// use ddapi_rs::prelude::ddstats::*;
64    ///
65    /// let api = DDApi::new();
66    /// let player: Profile = api.profile("ByFox").await?;
67    /// println!("{}: {}", player.name, player.clan.unwrap_or(String::default()));
68    /// ```
69    async fn profile(&self, player: &str) -> Result<Profile> {
70        self.generator(&Profile::api(player)).await
71    }
72
73    /// # Examples
74    ///
75    /// ```rust,ignore
76    /// use ddapi_rs::prelude::*;
77    /// use ddapi_rs::prelude::ddstats::*;
78    ///
79    /// let api = DDApi::new();
80    /// let teero: Teero = api.teero("Cor").await?;
81    /// println!("{:?}", teero.most_played_maps_gametype);
82    /// ```
83    async fn teero(&self, player: &str) -> Result<Teero> {
84        self.generator(&Teero::api(player)).await
85    }
86}
87
88impl DDstats for DDstatsClient {
89    async fn player(&self, player: &str) -> Result<Player> {
90        self.core().generator(&Player::api(player)).await
91    }
92
93    async fn map(&self, map: &str) -> Result<Map> {
94        self.core().generator(&Map::api(map)).await
95    }
96
97    async fn maps(&self) -> Result<Vec<StatsMap>> {
98        self.core().generator(&StatsMap::api()).await
99    }
100
101    async fn profile(&self, player: &str) -> Result<Profile> {
102        self.core().generator(&Profile::api(player)).await
103    }
104
105    async fn teero(&self, player: &str) -> Result<Teero> {
106        self.core().generator(&Teero::api(player)).await
107    }
108}