added territory war report selection and marked non-exhaustive enums
This commit is contained in:
parent
68986cc780
commit
281bd3de15
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "torn-api"
|
||||
version = "0.5.21"
|
||||
version = "0.5.22"
|
||||
edition = "2021"
|
||||
authors = ["Pyrit [2111649]"]
|
||||
license = "MIT"
|
||||
|
|
|
@ -11,7 +11,8 @@ pub use crate::common::{Attack, AttackFull, LastAction, Status, Territory};
|
|||
|
||||
#[derive(Debug, Clone, Copy, ApiCategory)]
|
||||
#[api(category = "faction")]
|
||||
pub enum Selection {
|
||||
#[non_exhaustive]
|
||||
pub enum FactionSelection {
|
||||
#[api(type = "Basic", flatten)]
|
||||
Basic,
|
||||
|
||||
|
@ -29,6 +30,8 @@ pub enum Selection {
|
|||
Territory,
|
||||
}
|
||||
|
||||
pub type Selection = FactionSelection;
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct Member<'a> {
|
||||
pub name: &'a str,
|
||||
|
|
|
@ -5,12 +5,14 @@ use torn_api_macros::ApiCategory;
|
|||
|
||||
#[derive(Debug, Clone, Copy, ApiCategory)]
|
||||
#[api(category = "key")]
|
||||
#[non_exhaustive]
|
||||
pub enum Selection {
|
||||
#[api(type = "Info", flatten)]
|
||||
Info,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[non_exhaustive]
|
||||
pub enum AccessType {
|
||||
#[serde(rename = "Custom")]
|
||||
Custom,
|
||||
|
@ -30,12 +32,14 @@ pub enum AccessType {
|
|||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
#[non_exhaustive]
|
||||
pub enum KeySelection {
|
||||
Info,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
#[non_exhaustive]
|
||||
pub enum UserSelection {
|
||||
Ammo,
|
||||
Attacks,
|
||||
|
@ -83,10 +87,13 @@ pub enum UserSelection {
|
|||
WorkStats,
|
||||
Lookup,
|
||||
PublicStatus,
|
||||
#[serde(other)]
|
||||
Unknown,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
#[non_exhaustive]
|
||||
pub enum FactionSelection {
|
||||
Applications,
|
||||
Armor,
|
||||
|
@ -124,10 +131,13 @@ pub enum FactionSelection {
|
|||
Lookup,
|
||||
Caches,
|
||||
CrimeExp,
|
||||
#[serde(other)]
|
||||
Unknown,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
#[non_exhaustive]
|
||||
pub enum CompanySelection {
|
||||
Applications,
|
||||
Companies,
|
||||
|
@ -139,10 +149,13 @@ pub enum CompanySelection {
|
|||
Stock,
|
||||
Timestamp,
|
||||
Lookup,
|
||||
#[serde(other)]
|
||||
Unknown,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
#[non_exhaustive]
|
||||
pub enum TornSelection {
|
||||
Bank,
|
||||
Cards,
|
||||
|
@ -177,24 +190,32 @@ pub enum TornSelection {
|
|||
TerritoryNames,
|
||||
TerritoryWarReport,
|
||||
RaidReport,
|
||||
#[serde(other)]
|
||||
Unknown,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
#[non_exhaustive]
|
||||
pub enum MarketSelection {
|
||||
Bazaar,
|
||||
ItemMarket,
|
||||
PointsMarket,
|
||||
Timestamp,
|
||||
Lookup,
|
||||
#[serde(other)]
|
||||
Unknown,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
#[non_exhaustive]
|
||||
pub enum PropertySelection {
|
||||
Property,
|
||||
Timestamp,
|
||||
Lookup,
|
||||
#[serde(other)]
|
||||
Unknown,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::collections::HashMap;
|
|||
use chrono::{DateTime, Utc};
|
||||
use serde::{
|
||||
de::{self, MapAccess, Visitor},
|
||||
Deserialize,
|
||||
Deserialize, Deserializer,
|
||||
};
|
||||
|
||||
use torn_api_macros::ApiCategory;
|
||||
|
@ -12,7 +12,8 @@ use crate::user;
|
|||
|
||||
#[derive(Debug, Clone, Copy, ApiCategory)]
|
||||
#[api(category = "torn")]
|
||||
pub enum Selection {
|
||||
#[non_exhaustive]
|
||||
pub enum TornSelection {
|
||||
#[api(
|
||||
field = "competition",
|
||||
with = "decode_competition",
|
||||
|
@ -26,11 +27,20 @@ pub enum Selection {
|
|||
#[api(type = "HashMap<String, Racket>", field = "rackets")]
|
||||
Rackets,
|
||||
|
||||
#[api(type = "HashMap<String, Territory>", field = "territory")]
|
||||
#[api(
|
||||
type = "HashMap<String, Territory>",
|
||||
with = "decode_territory",
|
||||
field = "territory"
|
||||
)]
|
||||
Territory,
|
||||
|
||||
#[api(type = "TerritoryWarReport", field = "territorywarreport")]
|
||||
TerritoryWarReport,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub type Selection = TornSelection;
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct EliminationLeaderboard {
|
||||
pub position: i16,
|
||||
pub team: user::EliminationTeam,
|
||||
|
@ -41,6 +51,7 @@ pub struct EliminationLeaderboard {
|
|||
pub losses: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Competition {
|
||||
Elimination { teams: Vec<EliminationLeaderboard> },
|
||||
Unkown(String),
|
||||
|
@ -109,6 +120,7 @@ where
|
|||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct TerritoryWar {
|
||||
pub territory_war_id: i32,
|
||||
pub assaulting_faction: i32,
|
||||
pub defending_faction: i32,
|
||||
|
||||
|
@ -143,6 +155,58 @@ pub struct Territory {
|
|||
pub racket: Option<Racket>,
|
||||
}
|
||||
|
||||
fn decode_territory<'de, D>(deserializer: D) -> Result<HashMap<String, Territory>, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
Ok(Option::deserialize(deserializer)?.unwrap_or_default())
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
pub struct TerritoryWarReportTerritory {
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum TerritoryWarOutcome {
|
||||
EndWithPeaceTreaty,
|
||||
FailAssault,
|
||||
SuccessAssault,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
pub struct TerritoryWarReportWar {
|
||||
#[serde(with = "chrono::serde::ts_seconds")]
|
||||
pub start: DateTime<Utc>,
|
||||
#[serde(with = "chrono::serde::ts_seconds")]
|
||||
pub end: DateTime<Utc>,
|
||||
|
||||
pub result: TerritoryWarOutcome,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum TerritoryWarReportRole {
|
||||
Aggressor,
|
||||
Defender,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct TerritoryWarReportFaction {
|
||||
pub name: String,
|
||||
pub score: i32,
|
||||
pub joins: i32,
|
||||
pub clears: i32,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
pub struct TerritoryWarReport {
|
||||
pub territory: TerritoryWarReportTerritory,
|
||||
pub war: TerritoryWarReportWar,
|
||||
pub factions: HashMap<i32, TerritoryWarReportFaction>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
@ -156,9 +220,9 @@ mod tests {
|
|||
.torn_api(key)
|
||||
.torn(|b| {
|
||||
b.selections(&[
|
||||
Selection::Competition,
|
||||
Selection::TerritoryWars,
|
||||
Selection::Rackets,
|
||||
TornSelection::Competition,
|
||||
TornSelection::TerritoryWars,
|
||||
TornSelection::Rackets,
|
||||
])
|
||||
})
|
||||
.await
|
||||
|
@ -182,4 +246,55 @@ mod tests {
|
|||
let territory = response.territory().unwrap();
|
||||
assert!(territory.contains_key("NSC"));
|
||||
}
|
||||
|
||||
#[async_test]
|
||||
async fn invalid_territory() {
|
||||
let key = setup();
|
||||
|
||||
let response = Client::default()
|
||||
.torn_api(key)
|
||||
.torn(|b| b.selections(&[Selection::Territory]).id("AAA"))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert!(response.territory().unwrap().is_empty());
|
||||
}
|
||||
|
||||
#[async_test]
|
||||
async fn territory_war_report() {
|
||||
let key = setup();
|
||||
|
||||
let response = Client::default()
|
||||
.torn_api(&key)
|
||||
.torn(|b| b.selections(&[Selection::TerritoryWarReport]).id(37403))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
response.territory_war_report().unwrap().war.result,
|
||||
TerritoryWarOutcome::SuccessAssault
|
||||
);
|
||||
|
||||
let response = Client::default()
|
||||
.torn_api(&key)
|
||||
.torn(|b| b.selections(&[Selection::TerritoryWarReport]).id(37502))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
response.territory_war_report().unwrap().war.result,
|
||||
TerritoryWarOutcome::FailAssault
|
||||
);
|
||||
|
||||
let response = Client::default()
|
||||
.torn_api(&key)
|
||||
.torn(|b| b.selections(&[Selection::TerritoryWarReport]).id(37860))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
response.territory_war_report().unwrap().war.result,
|
||||
TerritoryWarOutcome::EndWithPeaceTreaty
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,8 @@ pub use crate::common::{Attack, AttackFull, LastAction, Status};
|
|||
|
||||
#[derive(Debug, Clone, Copy, ApiCategory)]
|
||||
#[api(category = "user")]
|
||||
pub enum Selection {
|
||||
#[non_exhaustive]
|
||||
pub enum UserSelection {
|
||||
#[api(type = "Basic", flatten)]
|
||||
Basic,
|
||||
#[api(type = "Profile", flatten)]
|
||||
|
@ -29,6 +30,8 @@ pub enum Selection {
|
|||
Attacks,
|
||||
}
|
||||
|
||||
pub type Selection = UserSelection;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
|
||||
pub enum Gender {
|
||||
Male,
|
||||
|
|
Loading…
Reference in a new issue