use crate::api::http;
use crate::objects::{
SkillsResponse,
Skills,
ItemsResponse,
Item,
ElectionResponse,
Mayor,
Election,
BingoResponse,
Bingo,
ActiveAuctionsResponse,
Auction,
EndedAuctionsResponse,
EndedAuction,
Bazaar
};
use crate::Error;
use serde_json::Value;
pub struct Client<'a> {
key: &'a str
}
impl<'a> Client<'a> {
pub fn login(key: &'a str) -> Self {
Self { key: key }
}
pub async fn auction_by_uuid(&self, auction_uuid: &str) -> Result<Vec<Auction>, Error> {
let res = http::fetch::<ActiveAuctionsResponse>(
&format!("skyblock/auction?uuid={auction_uuid}&key={}", &self.key)
).await?;
Ok(res.auctions)
}
pub async fn auction_by_player(&self, player_uuid: &str) -> Result<Vec<Auction>, Error> {
let res = http::fetch::<ActiveAuctionsResponse>(
&format!("skyblock/auction?player={player_uuid}&key={}", &self.key)
).await?;
Ok(res.auctions)
}
pub async fn auction_by_profile(&self, profile_id: &str) -> Result<Vec<Auction>, Error> {
let res = http::fetch::<ActiveAuctionsResponse>(
&format!("skyblock/auction?profile={profile_id}&key={}", &self.key)
).await?;
Ok(res.auctions)
}
}
pub async fn skills() -> Result<Skills, Error> {
let res = http::fetch::<SkillsResponse>("resources/skyblock/skills").await?;
Ok(res.skills)
}
pub async fn items() -> Result<Vec<Item>, Error> {
let res = http::fetch::<ItemsResponse>("resources/skyblock/items").await?;
Ok(res.items)
}
pub async fn current_mayor() -> Result<Mayor, Error> {
let res = http::fetch::<ElectionResponse>("resources/skyblock/election").await?;
Ok(res.mayor)
}
pub async fn current_election() -> Result<Election, Error> {
let res = http::fetch::<ElectionResponse>("resources/skyblock/election").await?;
Ok(res.current)
}
pub async fn active_bingo() -> Result<Vec<Bingo>, Error> {
let res = http::fetch::<BingoResponse>("resources/skyblock/bingo").await?;
Ok(res.goals)
}
pub async fn active_auctions(page: usize) -> Result<Vec<Auction>, Error> {
let res = http::fetch::<ActiveAuctionsResponse>(
&format!("skyblock/auctions?page={page}")
).await?;
Ok(res.auctions)
}
pub async fn recently_ended_auctions() -> Result<Vec<EndedAuction>, Error> {
let res = http::fetch::<EndedAuctionsResponse>("skyblock/auctions_ended").await?;
Ok(res.auctions)
}
pub async fn bazaar() -> Result<Value, Error> {
let res = http::fetch::<Bazaar>("skyblock/bazaar").await?;
Ok(res.products)
}