diff --git a/torn-api/Cargo.toml b/torn-api/Cargo.toml index 74af14c..f9b816e 100644 --- a/torn-api/Cargo.toml +++ b/torn-api/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "torn-api" -version = "0.5.5" +version = "0.5.6" edition = "2021" authors = ["Pyrit [2111649]"] license = "MIT" @@ -13,7 +13,7 @@ name = "deserialisation_benchmark" harness = false [features] -default = [ "reqwest", "user", "faction", "torn" ] +default = [ "reqwest", "user", "faction", "torn", "key" ] reqwest = [ "dep:reqwest" ] awc = [ "dep:awc" ] decimal = [ "dep:rust_decimal" ] @@ -21,6 +21,7 @@ decimal = [ "dep:rust_decimal" ] user = [ "__common" ] faction = [ "__common" ] torn = [ "__common" ] +key = [] __common = [] diff --git a/torn-api/src/key.rs b/torn-api/src/key.rs new file mode 100644 index 0000000..0e970d2 --- /dev/null +++ b/torn-api/src/key.rs @@ -0,0 +1,229 @@ +use std::collections::HashSet; + +use serde::{Deserialize, Serialize}; +use torn_api_macros::ApiCategory; + +#[derive(Debug, Clone, Copy, ApiCategory)] +#[api(category = "key")] +pub enum Selection { + #[api(type = "Info", flatten)] + Info, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] +pub enum AccessType { + #[serde(rename = "Custom")] + Custom, + + #[serde(rename = "Public Only")] + Public, + + #[serde(rename = "Minimal Access")] + Minimal, + + #[serde(rename = "Limited Access")] + Limited, + + #[serde(rename = "Full Access")] + Full, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] +#[serde(rename_all = "lowercase")] +pub enum KeySelection { + Info, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] +#[serde(rename_all = "lowercase")] +pub enum UserSelection { + Ammo, + Attacks, + AttacksFull, + Bars, + Basic, + BattleStats, + Bazaar, + Cooldowns, + Crimes, + Discord, + Display, + Education, + Events, + Gym, + Hof, + Honors, + Icons, + Inventory, + JobPoints, + Log, + Medals, + Merits, + Messages, + Missions, + Money, + Networth, + NewEvents, + NewMessages, + Notifications, + Perks, + PersonalStats, + Profile, + Properties, + ReceivedEvents, + Refills, + Reports, + Revives, + RevivesFull, + Skills, + Stocks, + Timestamp, + Travel, + WeaponExp, + WorkStats, + Lookup, + PublicStatus, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] +#[serde(rename_all = "lowercase")] +pub enum FactionSelection { + Applications, + Armor, + ArmoryNews, + AttackNews, + Attacks, + AttacksFull, + Basic, + Boosters, + Cesium, + Chain, + ChainReport, + Chains, + Contributors, + Crimenews, + Crimes, + Currency, + Donations, + Drugs, + FundsNews, + MainNews, + Medical, + MembershipNews, + Positions, + Reports, + Revives, + RevivesFull, + Stats, + Temporary, + Territory, + TerritoryNews, + Timestamp, + Upgrades, + Weapons, + Lookup, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] +#[serde(rename_all = "lowercase")] +pub enum CompanySelection { + Applications, + Companies, + Detailed, + Employees, + News, + NewsFull, + Profile, + Stock, + Timestamp, + Lookup, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] +#[serde(rename_all = "lowercase")] +pub enum TornSelection { + Bank, + Cards, + ChainReport, + Companies, + Competition, + Education, + FactionTree, + Gyms, + Honors, + Items, + ItemStats, + LogCategories, + LogTypes, + Medals, + OrganisedCrimes, + PawnShop, + PokerTables, + Properties, + Rackets, + Raids, + RankedWars, + RankedWarReport, + Stats, + Stocks, + Territory, + TerritoryWars, + Timestamp, + Lookup, + CityShops, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] +#[serde(rename_all = "lowercase")] +pub enum MarketSelection { + Bazaar, + ItemMarket, + PointsMarket, + Timestamp, + Lookup, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] +#[serde(rename_all = "lowercase")] +pub enum PropertySelection { + Property, + Timestamp, + Lookup, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Selections { + pub user: HashSet, + pub faction: HashSet, + pub company: HashSet, + pub torn: HashSet, + pub market: HashSet, + pub property: HashSet, + pub key: HashSet, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Info { + pub access_level: i16, + pub access_type: AccessType, + pub selections: Selections, +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::tests::{async_test, setup, Client, ClientTrait}; + + #[async_test] + async fn key() { + let key = setup(); + + let response = Client::default() + .torn_api(key) + .key(|b| b.selections(&[Selection::Info])) + .await + .unwrap(); + + response.info().unwrap(); + } +} diff --git a/torn-api/src/lib.rs b/torn-api/src/lib.rs index 2b4f334..806cceb 100644 --- a/torn-api/src/lib.rs +++ b/torn-api/src/lib.rs @@ -12,6 +12,9 @@ pub mod faction; #[cfg(feature = "torn")] pub mod torn; +#[cfg(feature = "key")] +pub mod key; + #[cfg(feature = "awc")] pub mod awc; diff --git a/torn-api/src/local.rs b/torn-api/src/local.rs index 1b005c4..73a188e 100644 --- a/torn-api/src/local.rs +++ b/torn-api/src/local.rs @@ -155,6 +155,21 @@ where .map(|(i, r)| (num_traits::AsPrimitive::as_(i), r)) .collect() } + + #[cfg(feature = "key")] + pub async fn key(&self, build: F) -> Result + where + F: FnOnce( + crate::ApiRequestBuilder, + ) -> crate::ApiRequestBuilder, + { + let mut builder = crate::ApiRequestBuilder::default(); + builder = build(builder); + + self.executor + .execute(self.client, builder.request, builder.id) + .await + } } #[async_trait(?Send)] diff --git a/torn-api/src/send.rs b/torn-api/src/send.rs index 7258494..ddd9eac 100644 --- a/torn-api/src/send.rs +++ b/torn-api/src/send.rs @@ -155,6 +155,21 @@ where .map(|(i, r)| (num_traits::AsPrimitive::as_(i), r)) .collect() } + + #[cfg(feature = "key")] + pub async fn key(&self, build: F) -> Result + where + F: FnOnce( + crate::ApiRequestBuilder, + ) -> crate::ApiRequestBuilder, + { + let mut builder = crate::ApiRequestBuilder::default(); + builder = build(builder); + + self.executor + .execute(self.client, builder.request, builder.id) + .await + } } #[async_trait]