hypixel-sdk 0.1.0

Async client for the Hypixel Public API with typed models and SkyBlock helpers
Documentation
use crate::client::HypixelClient;
use crate::error::Result;
use crate::models::*;

impl HypixelClient {
    /// Fetch a player's network profile by UUID. Requires an API key.
    pub async fn player(&self, uuid: &str) -> Result<Option<Player>> {
        let resp: PlayerResponse = self.request("/v2/player", &[("uuid", uuid)], true).await?;
        Ok(resp.player)
    }

    /// Fetch a player's recently played games by UUID. Requires an API key.
    pub async fn recent_games(&self, uuid: &str) -> Result<Vec<RecentGame>> {
        let resp: RecentGamesResponse = self
            .request("/v2/recentgames", &[("uuid", uuid)], true)
            .await?;
        Ok(resp.games)
    }

    /// Fetch a player's current online session by UUID. Requires an API key.
    pub async fn status(&self, uuid: &str) -> Result<Session> {
        let resp: StatusResponse = self.request("/v2/status", &[("uuid", uuid)], true).await?;
        Ok(resp.session)
    }

    /// Fetch a guild by its id. Requires an API key.
    pub async fn guild_by_id(&self, id: &str) -> Result<Option<Guild>> {
        self.guild(&[("id", id)]).await
    }

    /// Fetch a guild by the UUID of one of its members. Requires an API key.
    pub async fn guild_by_player(&self, uuid: &str) -> Result<Option<Guild>> {
        self.guild(&[("player", uuid)]).await
    }

    /// Fetch a guild by name. Requires an API key.
    pub async fn guild_by_name(&self, name: &str) -> Result<Option<Guild>> {
        self.guild(&[("name", name)]).await
    }

    async fn guild(&self, query: &[(&str, &str)]) -> Result<Option<Guild>> {
        let resp: GuildResponse = self.request("/v2/guild", query, true).await?;
        Ok(resp.guild)
    }

    /// Fetch all currently active and queued boosters. Requires an API key.
    pub async fn boosters(&self) -> Result<Vec<Booster>> {
        let resp: BoostersResponse = self.request("/v2/boosters", &[], true).await?;
        Ok(resp.boosters)
    }

    /// Fetch live player counts across the network. Requires an API key.
    pub async fn counts(&self) -> Result<Counts> {
        self.request("/v2/counts", &[], true).await
    }

    /// Fetch the configured leaderboards for each game. Requires an API key.
    pub async fn leaderboards(
        &self,
    ) -> Result<std::collections::HashMap<String, Vec<Leaderboard>>> {
        let resp: LeaderboardsResponse = self.request("/v2/leaderboards", &[], true).await?;
        Ok(resp.leaderboards)
    }

    /// Fetch network-wide moderation statistics. Requires an API key.
    pub async fn punishment_stats(&self) -> Result<PunishmentStats> {
        self.request("/v2/punishmentstats", &[], true).await
    }

    /// Fetch the Housing houses the player is currently in. Requires an API key.
    pub async fn housing_active(&self) -> Result<Vec<HousingHouse>> {
        self.request("/v2/housing/active", &[], true).await
    }

    /// Fetch a single Housing house by its id. Requires an API key.
    pub async fn housing_house(&self, house: &str) -> Result<HousingHouse> {
        self.request("/v2/housing/house", &[("house", house)], true)
            .await
    }

    /// Fetch the Housing houses owned by a player. Requires an API key.
    pub async fn housing_houses(&self, player: &str) -> Result<Vec<HousingHouse>> {
        self.request("/v2/housing/houses", &[("player", player)], true)
            .await
    }
}