ddapi_rs/api/ddstats.rs
1use crate::api::{DDApi, DDstatsClient, HasApiCore};
2use crate::error::Result;
3use crate::scheme::ddstats::*;
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}
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.player("Aoe").await?;
22 /// println!("{}: {} | {}", player.profile.name, player.profile.points, player.profile.clan.unwrap_or(String::default()));
23 /// ```
24 async fn 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.map("Fox").await?;
36 /// println!("{}: {} | {}", map.info.map.map, map.info.map.stars, map.info.finishes);
37 /// ```
38 async fn 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.maps().await?;
50 /// for map in &maps {
51 /// println!("{}: {} | {}", map.map, map.stars, map.points);
52 /// }
53 /// ```
54 async fn 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.profile("ByFox").await?;
66 /// println!("{}: {}", player.name, player.clan.unwrap_or(String::default()));
67 /// ```
68 async fn profile(&self, player: &str) -> Result<Profile> {
69 self._generator(&Profile::api(player)).await
70 }
71}
72
73impl DDstats for DDstatsClient {
74 async fn player(&self, player: &str) -> Result<Player> {
75 self.core()._generator(&Player::api(player)).await
76 }
77
78 async fn map(&self, map: &str) -> Result<Map> {
79 self.core()._generator(&Map::api(map)).await
80 }
81
82 async fn maps(&self) -> Result<Vec<StatsMap>> {
83 self.core()._generator(&StatsMap::api()).await
84 }
85
86 async fn profile(&self, player: &str) -> Result<Profile> {
87 self.core()._generator(&Profile::api(player)).await
88 }
89}