warframe_client/apis/
profile_api.rs

1/*
2 * WarframeStat.us API
3 *
4 * Simple API for data from the game Warframe. [Parser Docs](https://wfcd.github.io/warframe-worldstate-parser/) [Items Types](https://github.com/WFCD/warframe-items/blob/master/index.d.ts) 
5 *
6 * The version of the OpenAPI document: 2.0.8
7 * Contact: tobiah@protonmail.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`get_profile_data`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetProfileDataError {
22    Status400(models::InlineObject),
23    Status500(models::InlineObject),
24    UnknownValue(serde_json::Value),
25}
26
27/// struct for typed errors of method [`get_profile_stats`]
28#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(untagged)]
30pub enum GetProfileStatsError {
31    Status400(models::InlineObject),
32    Status500(models::InlineObject),
33    UnknownValue(serde_json::Value),
34}
35
36
37/// Get the player profile from the available GDPR data.  DE now has the profile endpoint behind authentication, and all requests will timeout.
38pub async fn get_profile_data(configuration: &configuration::Configuration, username: &str) -> Result<models::Profile, Error<GetProfileDataError>> {
39    // add a prefix to parameters to efficiently prevent name collisions
40    let p_path_username = username;
41
42    let uri_str = format!("{}/profile/{username}", configuration.base_path, username=crate::apis::urlencode(p_path_username));
43    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
44
45    if let Some(ref user_agent) = configuration.user_agent {
46        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
47    }
48
49    let req = req_builder.build()?;
50    let resp = configuration.client.execute(req).await?;
51
52    let status = resp.status();
53    let content_type = resp
54        .headers()
55        .get("content-type")
56        .and_then(|v| v.to_str().ok())
57        .unwrap_or("application/octet-stream");
58    let content_type = super::ContentType::from(content_type);
59
60    if !status.is_client_error() && !status.is_server_error() {
61        let content = resp.text().await?;
62        match content_type {
63            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
64            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Profile`"))),
65            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Profile`")))),
66        }
67    } else {
68        let content = resp.text().await?;
69        let entity: Option<GetProfileDataError> = serde_json::from_str(&content).ok();
70        Err(Error::ResponseError(ResponseContent { status, content, entity }))
71    }
72}
73
74/// Get the player profile from the available GDPR data.  DE now has the profile endpoint behind authentication, and all requests will timeout.
75pub async fn get_profile_stats(configuration: &configuration::Configuration, username: &str) -> Result<models::Stats, Error<GetProfileStatsError>> {
76    // add a prefix to parameters to efficiently prevent name collisions
77    let p_path_username = username;
78
79    let uri_str = format!("{}/profile/{username}/stats", configuration.base_path, username=crate::apis::urlencode(p_path_username));
80    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
81
82    if let Some(ref user_agent) = configuration.user_agent {
83        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
84    }
85
86    let req = req_builder.build()?;
87    let resp = configuration.client.execute(req).await?;
88
89    let status = resp.status();
90    let content_type = resp
91        .headers()
92        .get("content-type")
93        .and_then(|v| v.to_str().ok())
94        .unwrap_or("application/octet-stream");
95    let content_type = super::ContentType::from(content_type);
96
97    if !status.is_client_error() && !status.is_server_error() {
98        let content = resp.text().await?;
99        match content_type {
100            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
101            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Stats`"))),
102            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Stats`")))),
103        }
104    } else {
105        let content = resp.text().await?;
106        let entity: Option<GetProfileStatsError> = serde_json::from_str(&content).ok();
107        Err(Error::ResponseError(ResponseContent { status, content, entity }))
108    }
109}
110