hypixel 0.1.0

Rust wrapper for the Hypixel public API.
Documentation
//! Handler for easy access to Hypixel misc information.
//! 
//! Everything here requires and API key so you'll have to create a Client
//! before using anything.
use crate::api::http;
use crate::objects::{
    BoostersResponse,
    Booster,
    PlayerCountResponse,
    PlayerDistribution,
    LeaderboardsResponse,
    Leaderboards,
    PunishmentStats
};
use crate::Error;

/// Stores the provided API key for later use. Makes things cleaner.
pub struct Client<'a> {
    key: &'a str
}

impl<'a> Client<'a> {
    /// Returns a Client struct with the provided API key.
    /// 
    /// # Arguments
    /// 
    /// * `key` - Your API key.
    pub fn login(key: &'a str) -> Self {
        Self { key: key }
    } 

    /// Returns a list of active boosters and their information.
    pub async fn boosters(&self) -> Result<Vec<Booster>, Error> {
        let res = http::fetch::<BoostersResponse> (
            &format!("boosters?key={}", &self.key)
        ).await?;

        Ok(res.boosters)
    }

    /// Returns the total number of players on Hypixel.
    pub async fn player_count(&self) -> Result<usize, Error> {
        let res = http::fetch::<PlayerCountResponse>(
            &format!("counts?key={}", &self.key)
        ).await?;

        Ok(res.player_count)
    }

    /// Returns the distribution of players on different Hypixel game modes.
    /// 
    /// # Example
    /// 
    /// ```no_run
    /// let player_dist = client.player_distribution().await?;
    /// 
    /// // Simple player count.
    /// let smp = player_dist.smp.players;
    /// // Modes.
    /// let solo_uhc = player_dist.uhc.modes["SOLO"].as_u16();
    /// ```
    pub async fn player_distribution(&self) -> Result<PlayerDistribution, Error> {
        let res = http::fetch::<PlayerCountResponse>(
            &format!("counts?key={}", &self.key)
        ).await?;

        Ok(res.games)
    }

    /// Returns all game modes and their list of leaderboards.
    pub async fn leaderboards(&self) -> Result<Leaderboards, Error> {
        let res = http::fetch::<LeaderboardsResponse>(
            &format!("leaderboards?key={}", &self.key)
        ).await?;

        Ok(res.leaderboards)
    }

    /// Returns punishment statistics for Hypixel.
    pub async fn punishment_stats(&self) -> Result<PunishmentStats, Error> {
        Ok(http::fetch::<PunishmentStats>(&format!("punishmentstats?key={}", &self.key)).await?)
    }
}