Skip to main content

hypixel/endpoints/
general.rs

1use crate::client::HypixelClient;
2use crate::error::Result;
3use crate::models::*;
4
5impl HypixelClient {
6    /// Fetch a player's network profile by UUID. Requires an API key.
7    pub async fn player(&self, uuid: &str) -> Result<Option<Player>> {
8        let resp: PlayerResponse = self.request("/v2/player", &[("uuid", uuid)], true).await?;
9        Ok(resp.player)
10    }
11
12    /// Fetch a player's recently played games by UUID. Requires an API key.
13    pub async fn recent_games(&self, uuid: &str) -> Result<Vec<RecentGame>> {
14        let resp: RecentGamesResponse = self
15            .request("/v2/recentgames", &[("uuid", uuid)], true)
16            .await?;
17        Ok(resp.games)
18    }
19
20    /// Fetch a player's current online session by UUID. Requires an API key.
21    pub async fn status(&self, uuid: &str) -> Result<Session> {
22        let resp: StatusResponse = self.request("/v2/status", &[("uuid", uuid)], true).await?;
23        Ok(resp.session)
24    }
25
26    /// Fetch a guild by its id. Requires an API key.
27    pub async fn guild_by_id(&self, id: &str) -> Result<Option<Guild>> {
28        self.guild(&[("id", id)]).await
29    }
30
31    /// Fetch a guild by the UUID of one of its members. Requires an API key.
32    pub async fn guild_by_player(&self, uuid: &str) -> Result<Option<Guild>> {
33        self.guild(&[("player", uuid)]).await
34    }
35
36    /// Fetch a guild by name. Requires an API key.
37    pub async fn guild_by_name(&self, name: &str) -> Result<Option<Guild>> {
38        self.guild(&[("name", name)]).await
39    }
40
41    async fn guild(&self, query: &[(&str, &str)]) -> Result<Option<Guild>> {
42        let resp: GuildResponse = self.request("/v2/guild", query, true).await?;
43        Ok(resp.guild)
44    }
45
46    /// Fetch all currently active and queued boosters. Requires an API key.
47    pub async fn boosters(&self) -> Result<Vec<Booster>> {
48        let resp: BoostersResponse = self.request("/v2/boosters", &[], true).await?;
49        Ok(resp.boosters)
50    }
51
52    /// Fetch live player counts across the network. Requires an API key.
53    pub async fn counts(&self) -> Result<Counts> {
54        self.request("/v2/counts", &[], true).await
55    }
56
57    /// Fetch the configured leaderboards for each game. Requires an API key.
58    pub async fn leaderboards(
59        &self,
60    ) -> Result<std::collections::HashMap<String, Vec<Leaderboard>>> {
61        let resp: LeaderboardsResponse = self.request("/v2/leaderboards", &[], true).await?;
62        Ok(resp.leaderboards)
63    }
64
65    /// Fetch network-wide moderation statistics. Requires an API key.
66    pub async fn punishment_stats(&self) -> Result<PunishmentStats> {
67        self.request("/v2/punishmentstats", &[], true).await
68    }
69
70    /// Fetch the Housing houses the player is currently in. Requires an API key.
71    pub async fn housing_active(&self) -> Result<Vec<HousingHouse>> {
72        self.request("/v2/housing/active", &[], true).await
73    }
74
75    /// Fetch a single Housing house by its id. Requires an API key.
76    pub async fn housing_house(&self, house: &str) -> Result<HousingHouse> {
77        self.request("/v2/housing/house", &[("house", house)], true)
78            .await
79    }
80
81    /// Fetch the Housing houses owned by a player. Requires an API key.
82    pub async fn housing_houses(&self, player: &str) -> Result<Vec<HousingHouse>> {
83        self.request("/v2/housing/houses", &[("player", player)], true)
84            .await
85    }
86}