added key->info selection
This commit is contained in:
parent
3e056ed63f
commit
cce7e2a4a5
|
@ -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 = []
|
||||
|
||||
|
|
229
torn-api/src/key.rs
Normal file
229
torn-api/src/key.rs
Normal file
|
@ -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<UserSelection>,
|
||||
pub faction: HashSet<FactionSelection>,
|
||||
pub company: HashSet<CompanySelection>,
|
||||
pub torn: HashSet<TornSelection>,
|
||||
pub market: HashSet<MarketSelection>,
|
||||
pub property: HashSet<PropertySelection>,
|
||||
pub key: HashSet<KeySelection>,
|
||||
}
|
||||
|
||||
#[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();
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -155,6 +155,21 @@ where
|
|||
.map(|(i, r)| (num_traits::AsPrimitive::as_(i), r))
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[cfg(feature = "key")]
|
||||
pub async fn key<F>(&self, build: F) -> Result<crate::key::Response, E::Error>
|
||||
where
|
||||
F: FnOnce(
|
||||
crate::ApiRequestBuilder<crate::key::Response>,
|
||||
) -> crate::ApiRequestBuilder<crate::key::Response>,
|
||||
{
|
||||
let mut builder = crate::ApiRequestBuilder::default();
|
||||
builder = build(builder);
|
||||
|
||||
self.executor
|
||||
.execute(self.client, builder.request, builder.id)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait(?Send)]
|
||||
|
|
|
@ -155,6 +155,21 @@ where
|
|||
.map(|(i, r)| (num_traits::AsPrimitive::as_(i), r))
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[cfg(feature = "key")]
|
||||
pub async fn key<F>(&self, build: F) -> Result<crate::key::Response, E::Error>
|
||||
where
|
||||
F: FnOnce(
|
||||
crate::ApiRequestBuilder<crate::key::Response>,
|
||||
) -> crate::ApiRequestBuilder<crate::key::Response>,
|
||||
{
|
||||
let mut builder = crate::ApiRequestBuilder::default();
|
||||
builder = build(builder);
|
||||
|
||||
self.executor
|
||||
.execute(self.client, builder.request, builder.id)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
|
|
Loading…
Reference in a new issue