hypixel/endpoints/
general.rs1use crate::client::HypixelClient;
2use crate::error::Result;
3use crate::models::*;
4
5impl HypixelClient {
6 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 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 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 pub async fn guild_by_id(&self, id: &str) -> Result<Option<Guild>> {
28 self.guild(&[("id", id)]).await
29 }
30
31 pub async fn guild_by_player(&self, uuid: &str) -> Result<Option<Guild>> {
33 self.guild(&[("player", uuid)]).await
34 }
35
36 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 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 pub async fn counts(&self) -> Result<Counts> {
54 self.request("/v2/counts", &[], true).await
55 }
56
57 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 pub async fn punishment_stats(&self) -> Result<PunishmentStats> {
67 self.request("/v2/punishmentstats", &[], true).await
68 }
69
70 pub async fn housing_active(&self) -> Result<Vec<HousingHouse>> {
72 self.request("/v2/housing/active", &[], true).await
73 }
74
75 pub async fn housing_house(&self, house: &str) -> Result<HousingHouse> {
77 self.request("/v2/housing/house", &[("house", house)], true)
78 .await
79 }
80
81 pub async fn housing_houses(&self, player: &str) -> Result<Vec<HousingHouse>> {
83 self.request("/v2/housing/houses", &[("player", player)], true)
84 .await
85 }
86}