Skip to main content

hypixel/endpoints/
skyblock.rs

1use crate::client::HypixelClient;
2use crate::error::Result;
3use crate::models::skyblock::*;
4
5impl HypixelClient {
6    /// Fetch all SkyBlock profiles for a player by UUID. Requires an API key.
7    pub async fn skyblock_profiles(&self, uuid: &str) -> Result<Vec<SkyBlockProfile>> {
8        let resp: ProfilesResponse = self
9            .request("/v2/skyblock/profiles", &[("uuid", uuid)], true)
10            .await?;
11        Ok(resp.profiles.unwrap_or_default())
12    }
13
14    /// Fetch a single SkyBlock profile by its profile id. Requires an API key.
15    pub async fn skyblock_profile(&self, profile: &str) -> Result<Option<SkyBlockProfile>> {
16        let resp: ProfileResponse = self
17            .request("/v2/skyblock/profile", &[("profile", profile)], true)
18            .await?;
19        Ok(resp.profile)
20    }
21
22    /// Fetch a profile's museum data by profile id. Requires an API key.
23    pub async fn skyblock_museum(&self, profile: &str) -> Result<Option<Museum>> {
24        let resp: MuseumResponse = self
25            .request("/v2/skyblock/museum", &[("profile", profile)], true)
26            .await?;
27        Ok(resp.profile)
28    }
29
30    /// Fetch a profile's garden data by profile id. Requires an API key.
31    pub async fn skyblock_garden(&self, profile: &str) -> Result<Option<Garden>> {
32        let resp: GardenResponse = self
33            .request("/v2/skyblock/garden", &[("profile", profile)], true)
34            .await?;
35        Ok(resp.garden)
36    }
37
38    /// Fetch a player's bingo participation by UUID. Requires an API key.
39    pub async fn skyblock_bingo(&self, uuid: &str) -> Result<Vec<serde_json::Value>> {
40        let resp: BingoEventsResponse = self
41            .request("/v2/skyblock/bingo", &[("uuid", uuid)], true)
42            .await?;
43        Ok(resp.events)
44    }
45
46    /// Fetch the active auctions of a player, profile, or single auction.
47    /// Provide exactly one of `uuid`, `player`, or `profile`. Requires an API key.
48    pub async fn skyblock_auction(
49        &self,
50        uuid: Option<&str>,
51        player: Option<&str>,
52        profile: Option<&str>,
53    ) -> Result<Vec<SkyBlockAuction>> {
54        let mut query = Vec::new();
55        if let Some(v) = uuid {
56            query.push(("uuid", v));
57        }
58        if let Some(v) = player {
59            query.push(("player", v));
60        }
61        if let Some(v) = profile {
62            query.push(("profile", v));
63        }
64        let resp: AuctionResponse = self.request("/v2/skyblock/auction", &query, true).await?;
65        Ok(resp.auctions)
66    }
67
68    /// Fetch one page of the global active-auction listing. Keyless.
69    pub async fn skyblock_auctions(&self, page: u32) -> Result<AuctionsPage> {
70        let page = page.to_string();
71        self.request("/v2/skyblock/auctions", &[("page", &page)], false)
72            .await
73    }
74
75    /// Fetch every page of the global active-auction listing, concurrently.
76    /// Keyless.
77    ///
78    /// The listing spans 100+ pages; pages after the first are fetched in
79    /// waves of eight. Ordering across pages is not guaranteed. The full
80    /// listing is tens of megabytes, so expect this to take a few seconds.
81    pub async fn skyblock_auctions_all(&self) -> Result<Vec<SkyBlockAuction>> {
82        let first = self.skyblock_auctions(0).await?;
83        let total_pages = first.total_pages.clamp(1, u32::MAX as i64) as u32;
84        let mut auctions = first.auctions;
85
86        let remaining: Vec<u32> = (1..total_pages).collect();
87        for wave in remaining.chunks(8) {
88            let pages = futures_util::future::try_join_all(
89                wave.iter().map(|&page| self.skyblock_auctions(page)),
90            )
91            .await?;
92            for page in pages {
93                auctions.extend(page.auctions);
94            }
95        }
96        Ok(auctions)
97    }
98
99    /// Fetch the most recently ended auctions. Keyless.
100    pub async fn skyblock_auctions_ended(&self) -> Result<Vec<EndedAuction>> {
101        let resp: EndedAuctionsResponse = self
102            .request("/v2/skyblock/auctions_ended", &[], false)
103            .await?;
104        Ok(resp.auctions)
105    }
106
107    /// Fetch the current bazaar order books for every product. Keyless.
108    pub async fn skyblock_bazaar(&self) -> Result<Bazaar> {
109        self.request("/v2/skyblock/bazaar", &[], false).await
110    }
111
112    /// Fetch the currently scheduled fire sales. Keyless.
113    pub async fn skyblock_firesales(&self) -> Result<Vec<FireSale>> {
114        let resp: FireSalesResponse = self.request("/v2/skyblock/firesales", &[], false).await?;
115        Ok(resp.sales)
116    }
117
118    /// Fetch the latest SkyBlock news posts. Keyless.
119    pub async fn skyblock_news(&self) -> Result<Vec<NewsItem>> {
120        let resp: NewsResponse = self.request("/v2/skyblock/news", &[], false).await?;
121        Ok(resp.items)
122    }
123}