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