commit
fe708c2c97
|
@ -182,6 +182,22 @@ where
|
||||||
deserializer.deserialize_any(ArrayVisitor(std::marker::PhantomData))
|
deserializer.deserialize_any(ArrayVisitor(std::marker::PhantomData))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn zero_is_none<'de, D, I>(deserializer: D) -> Result<Option<I>, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
I: TryFrom<i64>,
|
||||||
|
{
|
||||||
|
let num = i64::deserialize(deserializer)?;
|
||||||
|
|
||||||
|
if num == 0 {
|
||||||
|
Ok(None)
|
||||||
|
} else {
|
||||||
|
Ok(Some(num.try_into().map_err(|_| {
|
||||||
|
D::Error::invalid_value(Unexpected::Signed(num), &std::any::type_name::<I>())
|
||||||
|
})?))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn null_is_empty_dict<'de, D, K, V>(deserializer: D) -> Result<HashMap<K, V>, D::Error>
|
pub(crate) fn null_is_empty_dict<'de, D, K, V>(deserializer: D) -> Result<HashMap<K, V>, D::Error>
|
||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::{BTreeMap, HashMap};
|
||||||
|
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use serde::{
|
use serde::{
|
||||||
|
@ -8,7 +8,7 @@ use serde::{
|
||||||
|
|
||||||
use torn_api_macros::ApiCategory;
|
use torn_api_macros::ApiCategory;
|
||||||
|
|
||||||
use crate::user;
|
use crate::{de_util, user};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, ApiCategory)]
|
#[derive(Debug, Clone, Copy, ApiCategory)]
|
||||||
#[api(category = "torn")]
|
#[api(category = "torn")]
|
||||||
|
@ -40,6 +40,9 @@ pub enum TornSelection {
|
||||||
|
|
||||||
#[api(type = "TerritoryWarReport", field = "territorywarreport")]
|
#[api(type = "TerritoryWarReport", field = "territorywarreport")]
|
||||||
TerritoryWarReport,
|
TerritoryWarReport,
|
||||||
|
|
||||||
|
#[api(type = "BTreeMap<i32, Item>", field = "items")]
|
||||||
|
Items,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type Selection = TornSelection;
|
pub type Selection = TornSelection;
|
||||||
|
@ -226,6 +229,76 @@ pub struct TerritoryWarReport {
|
||||||
pub factions: HashMap<i32, TerritoryWarReportFaction>,
|
pub factions: HashMap<i32, TerritoryWarReportFaction>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
|
||||||
|
#[non_exhaustive]
|
||||||
|
pub enum ItemType {
|
||||||
|
Primary,
|
||||||
|
Secondary,
|
||||||
|
Melee,
|
||||||
|
Temporary,
|
||||||
|
Defensive,
|
||||||
|
Collectible,
|
||||||
|
Medical,
|
||||||
|
Drug,
|
||||||
|
Booster,
|
||||||
|
#[serde(rename = "Energy Drink")]
|
||||||
|
EnergyDrink,
|
||||||
|
Alcohol,
|
||||||
|
Book,
|
||||||
|
Candy,
|
||||||
|
Car,
|
||||||
|
Clothing,
|
||||||
|
Electronic,
|
||||||
|
Enhancer,
|
||||||
|
Flower,
|
||||||
|
Jewelry,
|
||||||
|
Other,
|
||||||
|
Special,
|
||||||
|
#[serde(rename = "Supply Pack")]
|
||||||
|
SupplyPack,
|
||||||
|
Virus,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
|
||||||
|
#[non_exhaustive]
|
||||||
|
//Missing hand to hand because it is not possible as a weapon
|
||||||
|
pub enum WeaponType {
|
||||||
|
Slashing,
|
||||||
|
Rifle,
|
||||||
|
SMG,
|
||||||
|
Piercing,
|
||||||
|
Clubbing,
|
||||||
|
Pistol,
|
||||||
|
#[serde(rename = "Machine gun")]
|
||||||
|
MachineGun,
|
||||||
|
Mechanical,
|
||||||
|
Temporary,
|
||||||
|
Heavy,
|
||||||
|
Shotgun,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
|
pub struct Item<'a> {
|
||||||
|
pub name: String,
|
||||||
|
pub description: String,
|
||||||
|
#[serde(deserialize_with = "de_util::empty_string_is_none")]
|
||||||
|
pub effect: Option<&'a str>,
|
||||||
|
#[serde(deserialize_with = "de_util::empty_string_is_none")]
|
||||||
|
pub requirement: Option<&'a str>,
|
||||||
|
#[serde(rename = "type")]
|
||||||
|
pub item_type: ItemType,
|
||||||
|
pub weapon_type: Option<WeaponType>,
|
||||||
|
#[serde(deserialize_with = "de_util::zero_is_none")]
|
||||||
|
pub buy_price: Option<u64>,
|
||||||
|
#[serde(deserialize_with = "de_util::zero_is_none")]
|
||||||
|
pub sell_price: Option<u64>,
|
||||||
|
#[serde(deserialize_with = "de_util::zero_is_none")]
|
||||||
|
pub market_value: Option<u64>,
|
||||||
|
#[serde(deserialize_with = "de_util::zero_is_none")]
|
||||||
|
pub circulation: Option<u32>,
|
||||||
|
pub image: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -327,4 +400,18 @@ mod tests {
|
||||||
TerritoryWarOutcome::EndWithDestroyDefense
|
TerritoryWarOutcome::EndWithDestroyDefense
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[async_test]
|
||||||
|
async fn item() {
|
||||||
|
let key = setup();
|
||||||
|
|
||||||
|
let response = Client::default()
|
||||||
|
.torn_api(key)
|
||||||
|
.torn(|b| b.selections([Selection::Items]).id(837))
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let item_list = response.items().unwrap();
|
||||||
|
assert!(item_list.contains_key(&837));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue