use crate::api;
use chesscom_openapi::apis::configuration::Configuration;
use chesscom_openapi::apis::default_api::*;
use crate::error::Result;
static USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"),);
pub struct ChessApi {
config: Configuration,
}
impl ChessApi {
pub fn new() -> ChessApi {
let mut config = Configuration::new();
config.user_agent = Some(format!("{} chesscom-rs", USER_AGENT));
ChessApi { config }
}
pub async fn get_profile(&self, username: &str) -> Result<api::Profile> {
get_player_profile(&self.config, username).await
}
pub async fn is_player_online(&self, username: &str) -> Result<bool> {
get_player_online_status(&self.config, username)
.await
.map(|resp| resp.online)
}
pub async fn get_titled_players(&self, title: api::Title) -> Result<Vec<String>> {
get_titled_players(&self.config, title).await
}
pub async fn get_player_stats(&self, username: &str) -> Result<api::PlayerStats> {
get_player_stats(&self.config, username).await
}
pub async fn get_daily_chess_games(&self, username: &str) -> Result<Vec<api::DailyGame>> {
get_daily_chess_games(&self.config, username)
.await
.map(|resp| resp.games)
}
pub async fn get_waiting_chess_games(&self, username: &str) -> Result<Vec<api::ToMoveGame>> {
get_daily_chess_games_to_move(&self.config, username)
.await
.map(|resp| resp.games)
}
}