From 77ebfad29554720def6c9be713587d32ae0d5f50 Mon Sep 17 00:00:00 2001 From: TotallyNot <44345987+TotallyNot@users.noreply.github.com> Date: Fri, 30 Jun 2023 03:31:30 +0200 Subject: [PATCH] added torn->territory and torn->rackets --- torn-api/Cargo.toml | 2 +- torn-api/src/torn.rs | 54 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/torn-api/Cargo.toml b/torn-api/Cargo.toml index 59e280b..69cf58b 100644 --- a/torn-api/Cargo.toml +++ b/torn-api/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "torn-api" -version = "0.5.18" +version = "0.5.19" edition = "2021" authors = ["Pyrit [2111649]"] license = "MIT" diff --git a/torn-api/src/torn.rs b/torn-api/src/torn.rs index f118b63..20364ce 100644 --- a/torn-api/src/torn.rs +++ b/torn-api/src/torn.rs @@ -22,6 +22,12 @@ pub enum Selection { #[api(type = "HashMap", field = "territorywars")] TerritoryWars, + + #[api(type = "HashMap", field = "rackets")] + Rackets, + + #[api(type = "HashMap", field = "territory")] + Territory, } #[derive(Deserialize)] @@ -111,6 +117,31 @@ pub struct TerritoryWar { pub ends: DateTime, } +#[derive(Debug, Clone, Deserialize)] +pub struct Racket { + pub name: String, + pub level: i16, + pub reward: String, + + #[serde(with = "chrono::serde::ts_seconds")] + pub created: DateTime, + #[serde(with = "chrono::serde::ts_seconds")] + pub changed: DateTime, +} + +#[derive(Debug, Clone, Deserialize)] +pub struct Territory { + pub sector: i16, + pub size: i16, + pub slots: i16, + pub daily_respect: i16, + pub faction: i32, + + pub neighbors: Vec, + pub war: Option, + pub racket: Option, +} + #[cfg(test)] mod tests { use super::*; @@ -122,11 +153,32 @@ mod tests { let response = Client::default() .torn_api(key) - .torn(|b| b.selections(&[Selection::Competition, Selection::TerritoryWars])) + .torn(|b| { + b.selections(&[ + Selection::Competition, + Selection::TerritoryWars, + Selection::Rackets, + ]) + }) .await .unwrap(); response.competition().unwrap(); response.territory_wars().unwrap(); + response.rackets().unwrap(); + } + + #[async_test] + async fn territory() { + let key = setup(); + + let response = Client::default() + .torn_api(key) + .torn(|b| b.selections(&[Selection::Territory]).id("NSC")) + .await + .unwrap(); + + let territory = response.territory().unwrap(); + assert!(territory.contains_key("NSC")); } }