Skip to content

Commit 1d1e995

Browse files
committed
feat: unstable profile impl, wont be included in release
1 parent 373dd8c commit 1d1e995

18 files changed

+1815
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
.vscode/settings.json
66
.vscode/launch.json
77
.idea/
8+
*.iml

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@
33
pub mod worldstate;
44

55
pub mod market;
6+
7+
// #[cfg(feature = "profile")]
8+
// pub mod profile;

src/profile/client.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//! Provides a client that acts as the baseline for interacting with the profile API
2+
3+
use super::{
4+
error::Error,
5+
models::platform::Platform,
6+
};
7+
use crate::profile::models::profile::Profile;
8+
9+
#[derive(Default, Debug, Clone)]
10+
pub struct Client {
11+
session: reqwest::Client,
12+
}
13+
14+
impl Client {
15+
/// Creates a new [Client].
16+
#[must_use]
17+
pub fn new() -> Self {
18+
Client::default()
19+
}
20+
}
21+
22+
impl Client {
23+
/// Fetches the profile of the user with the given username.
24+
#[allow(clippy::missing_errors_doc)]
25+
pub async fn fetch(&self, player_id: &str, platform: Platform) -> Result<Profile, Error> {
26+
let url = format!(
27+
"https://{}.warframe.com/dynamic/getProfileViewingData.php?playerId={player_id}",
28+
platform.to_sub_domain(),
29+
);
30+
let response = self.session.get(&url).send().await?;
31+
32+
if response.status().is_success() {
33+
let profile = response.json::<Profile>().await?;
34+
Ok(profile)
35+
} else if response.status() == reqwest::StatusCode::CONFLICT {
36+
let response = response.text().await?;
37+
let split = response.split(' ').collect::<Vec<&str>>();
38+
Err(Error::WrongPlatform(split[2].to_string()))
39+
} else {
40+
Err(Error::ApiError(response.status()))
41+
}
42+
}
43+
}

src/profile/error.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//! This module defines error types
2+
3+
/// The profile error type
4+
#[derive(Debug, thiserror::Error)]
5+
pub enum Error {
6+
/// An error from the sent request
7+
#[error("Couldn't send request: {0}")]
8+
FaultyRequest(#[from] reqwest::Error),
9+
10+
/// An error that occurs when the deserialization of `serde_json` fails
11+
#[error("Couldn't deserialize json body: {0}")]
12+
FailedDeserialization(#[from] serde_json::Error),
13+
14+
/// Error when the profile directs you to a different platform
15+
#[error("Retry using platform: {0}")]
16+
WrongPlatform(String),
17+
18+
/// Any error directly from the API (status code only)
19+
#[error("Error response from the API: {0}")]
20+
ApiError(reqwest::StatusCode),
21+
}
22+
23+
impl From<reqwest::StatusCode> for Error {
24+
fn from(value: reqwest::StatusCode) -> Self {
25+
Error::ApiError(value)
26+
}
27+
}

src/profile/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//! Implementation for the profile module, used to interact with the warframe profile API
2+
3+
pub mod client;
4+
pub mod models;
5+
pub mod error;

src/profile/models/affiliation.rs

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
use serde::Deserialize;
2+
3+
#[derive(Deserialize, Debug, Clone)]
4+
#[serde(rename_all = "PascalCase")]
5+
pub struct Affiliation {
6+
/// tag
7+
pub tag: AffiliationTag,
8+
9+
/// standing
10+
pub standing: i32,
11+
12+
/// title
13+
pub title: i32,
14+
}
15+
16+
#[derive(Deserialize, Debug, Clone, PartialEq)]
17+
pub enum AffiliationTag {
18+
#[serde(rename = "ArbitersSyndicate")]
19+
ArbitersOfHexis,
20+
#[serde(rename = "CephalonSudaSyndicate")]
21+
CephalonSuda,
22+
#[serde(rename = "NewLokaSyndicate")]
23+
NewLoka,
24+
#[serde(rename = "PerrinSyndicate")]
25+
PerrinSequence,
26+
#[serde(rename = "RedVeilSyndicate")]
27+
RedVeil,
28+
#[serde(rename = "SteelMeridianSyndicate")]
29+
SteelMeridian,
30+
#[serde(rename = "LibrarySyndicate")]
31+
CephalonSimaris,
32+
#[serde(rename = "ConclaveSyndicate")]
33+
Conclave,
34+
#[serde(rename = "CetusSyndicate")]
35+
Ostrons,
36+
#[serde(rename = "EventSyndicate")]
37+
PlagueStar,
38+
#[serde(rename = "QuillsSyndicate")]
39+
Quills,
40+
#[serde(rename = "VentKidsSyndicate")]
41+
VentKids,
42+
#[serde(rename = "SolarisSyndicate")]
43+
SolarisUnited,
44+
#[serde(rename = "VoxSyndicate")]
45+
VoxSolaris,
46+
#[serde(rename = "RadioLegionSyndicate")]
47+
NightwaveSaturnSix,
48+
#[serde(rename = "RadioLegionIntermissionSyndicate")]
49+
NightwaveIntermission1,
50+
#[serde(rename = "RadioLegion2Syndicate")]
51+
NightwaveEmissary,
52+
#[serde(rename = "RadioLegionIntermission2Syndicate")]
53+
NightwaveIntermission2,
54+
#[serde(rename = "RadioLegion3Syndicate")]
55+
NightwaveGlassmaker,
56+
#[serde(rename = "EntratiSyndicate")]
57+
Entrati,
58+
#[serde(rename = "NecraloidSyndicate")]
59+
Necarloid,
60+
#[serde(rename = "RadioLegionIntermission3Syndicate")]
61+
NightwaveIntermission3,
62+
#[serde(rename = "RadioLegionIntermission4Syndicate")]
63+
NightwaveNorasChoice,
64+
#[serde(rename = "RadioLegionIntermission5Syndicate")]
65+
NightwaveNorasMix1,
66+
#[serde(rename = "ZarimanSyndicate")]
67+
Zariman,
68+
#[serde(rename = "RadioLegionIntermission6Syndicate")]
69+
NightwaveNorasMix2,
70+
#[serde(rename = "KahlSyndicate")]
71+
KahlsGarrison,
72+
#[serde(rename = "RadioLegionIntermission7Syndicate")]
73+
NightwaveNorasMix3,
74+
#[serde(rename = "RadioLegionIntermission8Syndicate")]
75+
NightwaveNorasMix4,
76+
#[serde(rename = "RadioLegionIntermission9Syndicate")]
77+
NightwaveNorasMix5,
78+
#[serde(rename = "EntratiLabSyndicate")]
79+
Cavia,
80+
#[serde(rename = "RadioLegionIntermission10Syndicate")]
81+
NightwaveNorasMix6,
82+
#[serde(rename = "RadioLegionIntermission11Syndicate")]
83+
NightwaveNorasMix7,
84+
#[serde(rename = "HexSyndicate")]
85+
Hex,
86+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use serde::{
2+
Deserialize,
3+
Serialize,
4+
};
5+
6+
#[derive(Serialize, Deserialize, Debug, Clone)]
7+
/// base10 i32 color loadout, [None] if color is not set
8+
pub struct ColorLoadOut {
9+
#[serde(rename = "t0")]
10+
pub t0: Option<i32>,
11+
12+
#[serde(rename = "t1")]
13+
pub t1: Option<i32>,
14+
15+
#[serde(rename = "t2")]
16+
pub t2: Option<i32>,
17+
18+
#[serde(rename = "t3")]
19+
pub t3: Option<i32>,
20+
21+
#[serde(rename = "m0")]
22+
pub m0: Option<i32>,
23+
24+
#[serde(rename = "m1")]
25+
pub m1: Option<i32>,
26+
27+
#[serde(rename = "en")]
28+
pub en: Option<i32>,
29+
30+
#[serde(rename = "e1")]
31+
pub e1: Option<i32>,
32+
}

0 commit comments

Comments
 (0)