added market->bazaar
This commit is contained in:
parent
f594a6b241
commit
80b699d77f
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "torn-api"
|
name = "torn-api"
|
||||||
version = "0.6.2"
|
version = "0.6.3"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
authors = ["Pyrit [2111649]"]
|
authors = ["Pyrit [2111649]"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
@ -13,7 +13,7 @@ name = "deserialisation_benchmark"
|
||||||
harness = false
|
harness = false
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = [ "reqwest", "user", "faction", "torn", "key" ]
|
default = [ "reqwest", "user", "faction", "torn", "key", "market" ]
|
||||||
reqwest = [ "dep:reqwest" ]
|
reqwest = [ "dep:reqwest" ]
|
||||||
awc = [ "dep:awc" ]
|
awc = [ "dep:awc" ]
|
||||||
decimal = [ "dep:rust_decimal" ]
|
decimal = [ "dep:rust_decimal" ]
|
||||||
|
@ -21,6 +21,7 @@ decimal = [ "dep:rust_decimal" ]
|
||||||
user = [ "__common" ]
|
user = [ "__common" ]
|
||||||
faction = [ "__common" ]
|
faction = [ "__common" ]
|
||||||
torn = [ "__common" ]
|
torn = [ "__common" ]
|
||||||
|
market = [ "__common" ]
|
||||||
key = []
|
key = []
|
||||||
|
|
||||||
__common = []
|
__common = []
|
||||||
|
|
|
@ -10,6 +10,9 @@ pub mod user;
|
||||||
#[cfg(feature = "faction")]
|
#[cfg(feature = "faction")]
|
||||||
pub mod faction;
|
pub mod faction;
|
||||||
|
|
||||||
|
#[cfg(feature = "market")]
|
||||||
|
pub mod market;
|
||||||
|
|
||||||
#[cfg(feature = "torn")]
|
#[cfg(feature = "torn")]
|
||||||
pub mod torn;
|
pub mod torn;
|
||||||
|
|
||||||
|
|
|
@ -106,6 +106,46 @@ where
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "market")]
|
||||||
|
pub async fn market<F>(&self, build: F) -> Result<crate::market::Response, E::Error>
|
||||||
|
where
|
||||||
|
F: FnOnce(
|
||||||
|
crate::ApiRequestBuilder<crate::market::MarketSelection>,
|
||||||
|
) -> crate::ApiRequestBuilder<crate::market::MarketSelection>,
|
||||||
|
{
|
||||||
|
let mut builder = crate::ApiRequestBuilder::default();
|
||||||
|
builder = build(builder);
|
||||||
|
|
||||||
|
self.executor
|
||||||
|
.execute(self.client, builder.request, builder.id)
|
||||||
|
.await
|
||||||
|
.map(crate::market::Response::from_response)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "market")]
|
||||||
|
pub async fn markets<F, L, I>(
|
||||||
|
&self,
|
||||||
|
ids: L,
|
||||||
|
build: F,
|
||||||
|
) -> HashMap<I, Result<crate::market::Response, E::Error>>
|
||||||
|
where
|
||||||
|
F: FnOnce(
|
||||||
|
crate::ApiRequestBuilder<crate::market::MarketSelection>,
|
||||||
|
) -> crate::ApiRequestBuilder<crate::market::MarketSelection>,
|
||||||
|
I: ToString + std::hash::Hash + std::cmp::Eq,
|
||||||
|
L: IntoIterator<Item = I>,
|
||||||
|
{
|
||||||
|
let mut builder = crate::ApiRequestBuilder::default();
|
||||||
|
builder = build(builder);
|
||||||
|
|
||||||
|
self.executor
|
||||||
|
.execute_many(self.client, builder.request, Vec::from_iter(ids))
|
||||||
|
.await
|
||||||
|
.into_iter()
|
||||||
|
.map(|(k, v)| (k, v.map(crate::market::Response::from_response)))
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "torn")]
|
#[cfg(feature = "torn")]
|
||||||
pub async fn torn<F>(&self, build: F) -> Result<crate::torn::Response, E::Error>
|
pub async fn torn<F>(&self, build: F) -> Result<crate::torn::Response, E::Error>
|
||||||
where
|
where
|
||||||
|
|
36
torn-api/src/market.rs
Normal file
36
torn-api/src/market.rs
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
use serde::Deserialize;
|
||||||
|
use torn_api_macros::ApiCategory;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, ApiCategory)]
|
||||||
|
#[api(category = "market")]
|
||||||
|
pub enum MarketSelection {
|
||||||
|
#[api(type = "Vec<BazaarItem>", field = "bazaar")]
|
||||||
|
Bazaar,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Deserialize)]
|
||||||
|
pub struct BazaarItem {
|
||||||
|
#[serde(rename = "ID")]
|
||||||
|
pub id: u32,
|
||||||
|
pub cost: u64,
|
||||||
|
pub quantity: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use super::*;
|
||||||
|
use crate::tests::{async_test, setup, Client, ClientTrait};
|
||||||
|
|
||||||
|
#[async_test]
|
||||||
|
async fn market_bazaar() {
|
||||||
|
let key = setup();
|
||||||
|
|
||||||
|
let response = Client::default()
|
||||||
|
.torn_api(key)
|
||||||
|
.market(|b| b.id(1).selections([MarketSelection::Bazaar]))
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
_ = response.bazaar().unwrap();
|
||||||
|
}
|
||||||
|
}
|
|
@ -106,6 +106,46 @@ where
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "market")]
|
||||||
|
pub async fn market<F>(&self, build: F) -> Result<crate::market::Response, E::Error>
|
||||||
|
where
|
||||||
|
F: FnOnce(
|
||||||
|
crate::ApiRequestBuilder<crate::market::MarketSelection>,
|
||||||
|
) -> crate::ApiRequestBuilder<crate::market::MarketSelection>,
|
||||||
|
{
|
||||||
|
let mut builder = crate::ApiRequestBuilder::default();
|
||||||
|
builder = build(builder);
|
||||||
|
|
||||||
|
self.executor
|
||||||
|
.execute(self.client, builder.request, builder.id)
|
||||||
|
.await
|
||||||
|
.map(crate::market::Response::from_response)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "market")]
|
||||||
|
pub async fn markets<F, L, I>(
|
||||||
|
&self,
|
||||||
|
ids: L,
|
||||||
|
build: F,
|
||||||
|
) -> HashMap<I, Result<crate::market::Response, E::Error>>
|
||||||
|
where
|
||||||
|
F: FnOnce(
|
||||||
|
crate::ApiRequestBuilder<crate::market::MarketSelection>,
|
||||||
|
) -> crate::ApiRequestBuilder<crate::market::MarketSelection>,
|
||||||
|
I: ToString + std::hash::Hash + std::cmp::Eq + Send + Sync,
|
||||||
|
L: IntoIterator<Item = I>,
|
||||||
|
{
|
||||||
|
let mut builder = crate::ApiRequestBuilder::default();
|
||||||
|
builder = build(builder);
|
||||||
|
|
||||||
|
self.executor
|
||||||
|
.execute_many(self.client, builder.request, Vec::from_iter(ids))
|
||||||
|
.await
|
||||||
|
.into_iter()
|
||||||
|
.map(|(k, v)| (k, v.map(crate::market::Response::from_response)))
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "torn")]
|
#[cfg(feature = "torn")]
|
||||||
pub async fn torn<F>(&self, build: F) -> Result<crate::torn::Response, E::Error>
|
pub async fn torn<F>(&self, build: F) -> Result<crate::torn::Response, E::Error>
|
||||||
where
|
where
|
||||||
|
|
Loading…
Reference in a new issue