1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use crate::{Result, SkyblockApi, Product};
use crate::client::ApiBody;
use std::collections::HashMap;
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
struct Products {
#[serde(rename = "productIds")]
pub product_ids: Vec<String>
}
#[derive(Serialize, Deserialize, Debug, PartialEq)]
struct ProductWrapper {
pub product_info: Product
}
#[derive(Serialize, Deserialize, Debug, PartialEq)]
struct UnifiedListing {
pub products: HashMap<String, Product>
}
impl<'a> SkyblockApi<'a> {
#[deprecated]
pub async fn get_bazaar_products(&mut self) -> Result<Vec<String>> {
let products: ApiBody<Products> = self.get("bazaar/products", vec![]).await?;
match products.into() {
Ok(prods) => Ok(prods.product_ids),
Err(cause) => Err(cause)
}
}
pub async fn get_bazaar_product_listing(&mut self) -> Result<HashMap<String, Product>> {
let products: ApiBody<UnifiedListing> = self.get("bazaar", vec![]).await?;
match products.into() {
Ok(prods) => Ok(prods.products),
Err(cause) => Err(cause)
}
}
#[deprecated]
pub async fn get_bazaar_product(&mut self, product: &str) -> Result<Product> {
let product: ApiBody<ProductWrapper> = self.get("bazaar/product", vec![("productId", product.to_owned())]).await?;
let res: Result<_> = product.into();
res.map(|wrapped| wrapped.product_info)
}
}