fixed faction->territory for sectored factions
This commit is contained in:
parent
2bd0998695
commit
171f9f2936
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
|||
/target
|
||||
/Cargo.lock
|
||||
.env
|
||||
.DS_Store
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "torn-api"
|
||||
version = "0.5.14"
|
||||
version = "0.5.15"
|
||||
edition = "2021"
|
||||
authors = ["Pyrit [2111649]"]
|
||||
license = "MIT"
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#![allow(unused)]
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
|
||||
use chrono::{DateTime, NaiveDateTime, Utc};
|
||||
use chrono::{serde::ts_nanoseconds::deserialize, DateTime, NaiveDateTime, Utc};
|
||||
use serde::de::{Deserialize, Deserializer, Error, Unexpected, Visitor};
|
||||
|
||||
pub(crate) fn empty_string_is_none<'de, D>(deserializer: D) -> Result<Option<&'de str>, D::Error>
|
||||
|
@ -182,6 +182,15 @@ where
|
|||
deserializer.deserialize_any(ArrayVisitor(std::marker::PhantomData))
|
||||
}
|
||||
|
||||
pub(crate) fn null_is_empty_dict<'de, D, K, V>(deserializer: D) -> Result<HashMap<K, V>, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
K: std::hash::Hash + std::cmp::Eq + Deserialize<'de>,
|
||||
V: Deserialize<'de>,
|
||||
{
|
||||
Ok(Option::deserialize(deserializer)?.unwrap_or_default())
|
||||
}
|
||||
|
||||
#[cfg(feature = "decimal")]
|
||||
pub(crate) fn string_or_decimal<'de, D>(deserializer: D) -> Result<rust_decimal::Decimal, D::Error>
|
||||
where
|
||||
|
|
|
@ -5,7 +5,7 @@ use serde::Deserialize;
|
|||
|
||||
use torn_api_macros::ApiCategory;
|
||||
|
||||
use crate::de_util;
|
||||
use crate::de_util::{self, null_is_empty_dict};
|
||||
|
||||
pub use crate::common::{LastAction, Status, Territory};
|
||||
|
||||
|
@ -21,7 +21,11 @@ pub enum Selection {
|
|||
#[api(type = "BTreeMap<i32, AttackFull>", field = "attacks")]
|
||||
Attacks,
|
||||
|
||||
#[api(type = "HashMap<String, Territory>", field = "territory")]
|
||||
#[api(
|
||||
type = "HashMap<String, Territory>",
|
||||
field = "territory",
|
||||
with = "null_is_empty_dict"
|
||||
)]
|
||||
Territory,
|
||||
}
|
||||
|
||||
|
@ -199,4 +203,21 @@ mod tests {
|
|||
response.attacks_full().unwrap();
|
||||
response.territory().unwrap();
|
||||
}
|
||||
|
||||
#[async_test]
|
||||
async fn destroyed_faction() {
|
||||
let key = setup();
|
||||
|
||||
let response = Client::default()
|
||||
.torn_api(key)
|
||||
.faction(|b| {
|
||||
b.id(8981)
|
||||
.selections(&[Selection::Basic, Selection::Territory])
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
response.basic().unwrap();
|
||||
response.territory().unwrap();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue