use crate::api::http;
use crate::objects::{
BoostersResponse,
Booster,
PlayerCountResponse,
PlayerDistribution,
LeaderboardsResponse,
Leaderboards,
PunishmentStats
};
use crate::Error;
pub struct Client<'a> {
key: &'a str
}
impl<'a> Client<'a> {
pub fn login(key: &'a str) -> Self {
Self { key: key }
}
pub async fn boosters(&self) -> Result<Vec<Booster>, Error> {
let res = http::fetch::<BoostersResponse> (
&format!("boosters?key={}", &self.key)
).await?;
Ok(res.boosters)
}
pub async fn player_count(&self) -> Result<usize, Error> {
let res = http::fetch::<PlayerCountResponse>(
&format!("counts?key={}", &self.key)
).await?;
Ok(res.player_count)
}
pub async fn player_distribution(&self) -> Result<PlayerDistribution, Error> {
let res = http::fetch::<PlayerCountResponse>(
&format!("counts?key={}", &self.key)
).await?;
Ok(res.games)
}
pub async fn leaderboards(&self) -> Result<Leaderboards, Error> {
let res = http::fetch::<LeaderboardsResponse>(
&format!("leaderboards?key={}", &self.key)
).await?;
Ok(res.leaderboards)
}
pub async fn punishment_stats(&self) -> Result<PunishmentStats, Error> {
Ok(http::fetch::<PunishmentStats>(&format!("punishmentstats?key={}", &self.key)).await?)
}
}