Skip to main content

artifacts/apis/
characters_api.rs

1use super::{configuration, Error};
2use crate::{apis::ResponseContent, models};
3use reqwest::StatusCode;
4use serde::{de, Deserialize, Deserializer, Serialize};
5
6/// struct for passing parameters to the method [`create_character`]
7#[derive(Clone, Debug)]
8pub struct CreateCharacterParams {
9    pub add_character_schema: models::AddCharacterSchema,
10}
11
12impl CreateCharacterParams {
13    pub fn new(add_character_schema: models::AddCharacterSchema) -> Self {
14        Self {
15            add_character_schema,
16        }
17    }
18}
19
20/// struct for passing parameters to the method [`delete_character`]
21#[derive(Clone, Debug)]
22pub struct DeleteCharacterParams {
23    pub delete_character_schema: models::DeleteCharacterSchema,
24}
25
26impl DeleteCharacterParams {
27    pub fn new(delete_character_schema: models::DeleteCharacterSchema) -> Self {
28        Self {
29            delete_character_schema,
30        }
31    }
32}
33
34/// struct for passing parameters to the method [`get_active_characters`]
35#[derive(Clone, Debug)]
36pub struct GetActiveCharactersParams {
37    /// Page number
38    pub page: Option<u32>,
39    /// Page size
40    pub size: Option<u32>,
41}
42
43impl GetActiveCharactersParams {
44    pub fn new(page: Option<u32>, size: Option<u32>) -> Self {
45        Self { page, size }
46    }
47}
48
49/// struct for passing parameters to the method [`get_character`]
50#[derive(Clone, Debug)]
51pub struct GetCharacterParams {
52    /// The name of the character.
53    pub name: String,
54}
55
56impl GetCharacterParams {
57    pub fn new(name: String) -> Self {
58        Self { name }
59    }
60}
61
62/// struct for passing parameters to the method [`get_character_stats`]
63#[derive(Clone, Debug)]
64pub struct GetCharacterStatsParams {
65    /// The name of the character.
66    pub name: String,
67}
68
69impl GetCharacterStatsParams {
70    pub fn new(name: String) -> Self {
71        Self { name }
72    }
73}
74
75/// struct for typed errors of method [`create_character`]
76#[derive(Debug, Clone, Serialize)]
77#[serde(untagged)]
78pub enum CreateCharacterError {
79    /// This name is already in use.
80    Status494(models::ErrorResponseSchema),
81    /// You have reached the maximum number of characters on your account.
82    Status495(models::ErrorResponseSchema),
83    /// You cannot choose this skin because you do not own it.
84    Status550(models::ErrorResponseSchema),
85    /// Skin not found.
86    Status404(models::ErrorResponseSchema),
87    /// Request could not be processed due to an invalid payload.
88    Status422(models::ErrorResponseSchema),
89}
90
91impl<'de> Deserialize<'de> for CreateCharacterError {
92    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
93    where
94        D: Deserializer<'de>,
95    {
96        let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
97        match raw.error.code {
98            494 => Ok(Self::Status494(raw)),
99            495 => Ok(Self::Status495(raw)),
100            550 => Ok(Self::Status550(raw)),
101            404 => Ok(Self::Status404(raw)),
102            422 => Ok(Self::Status422(raw)),
103            _ => Err(de::Error::custom(format!(
104                "Unexpected error code: {}",
105                raw.error.code
106            ))),
107        }
108    }
109}
110
111/// struct for typed errors of method [`delete_character`]
112#[derive(Debug, Clone, Serialize)]
113#[serde(untagged)]
114pub enum DeleteCharacterError {
115    /// Character not found.
116    Status498(models::ErrorResponseSchema),
117    /// Request could not be processed due to an invalid payload.
118    Status422(models::ErrorResponseSchema),
119}
120
121impl<'de> Deserialize<'de> for DeleteCharacterError {
122    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
123    where
124        D: Deserializer<'de>,
125    {
126        let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
127        match raw.error.code {
128            498 => Ok(Self::Status498(raw)),
129            422 => Ok(Self::Status422(raw)),
130            _ => Err(de::Error::custom(format!(
131                "Unexpected error code: {}",
132                raw.error.code
133            ))),
134        }
135    }
136}
137
138/// struct for typed errors of method [`get_active_characters`]
139#[derive(Debug, Clone, Serialize)]
140#[serde(untagged)]
141pub enum GetActiveCharactersError {}
142
143impl<'de> Deserialize<'de> for GetActiveCharactersError {
144    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
145    where
146        D: Deserializer<'de>,
147    {
148        let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
149        Err(de::Error::custom(format!(
150            "Unexpected error code: {}",
151            raw.error.code
152        )))
153    }
154}
155
156/// struct for typed errors of method [`get_character`]
157#[derive(Debug, Clone, Serialize)]
158#[serde(untagged)]
159pub enum GetCharacterError {
160    /// character not found.
161    Status404(models::ErrorResponseSchema),
162}
163
164impl<'de> Deserialize<'de> for GetCharacterError {
165    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
166    where
167        D: Deserializer<'de>,
168    {
169        let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
170        match raw.error.code {
171            404 => Ok(Self::Status404(raw)),
172            _ => Err(de::Error::custom(format!(
173                "Unexpected error code: {}",
174                raw.error.code
175            ))),
176        }
177    }
178}
179
180/// struct for typed errors of method [`get_character_stats`]
181#[derive(Debug, Clone, Serialize)]
182#[serde(untagged)]
183pub enum GetCharacterStatsError {
184    /// character stats not found.
185    Status404(models::ErrorResponseSchema),
186}
187
188impl<'de> Deserialize<'de> for GetCharacterStatsError {
189    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
190    where
191        D: Deserializer<'de>,
192    {
193        let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
194        match raw.error.code {
195            404 => Ok(Self::Status404(raw)),
196            _ => Err(de::Error::custom(format!(
197                "Unexpected error code: {}",
198                raw.error.code
199            ))),
200        }
201    }
202}
203
204/// Create new character on your account. You can create up to 5 characters.
205pub async fn create_character(
206    configuration: &configuration::Configuration,
207    params: CreateCharacterParams,
208) -> Result<models::CharacterResponseSchema, Error<CreateCharacterError>> {
209    let local_var_configuration = configuration;
210
211    // unbox the parameters
212    let add_character_schema = params.add_character_schema;
213
214    let local_var_client = &local_var_configuration.client;
215
216    let local_var_uri_str = format!("{}/characters/create", local_var_configuration.base_path);
217    let mut local_var_req_builder =
218        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
219
220    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
221        local_var_req_builder =
222            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
223    }
224    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
225        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
226    };
227    local_var_req_builder = local_var_req_builder.json(&add_character_schema);
228
229    let local_var_req = local_var_req_builder.build()?;
230    let local_var_resp = local_var_client.execute(local_var_req).await?;
231
232    let local_var_status = local_var_resp.status();
233    let local_var_content = local_var_resp.text().await?;
234
235    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
236        serde_json::from_str(&local_var_content).map_err(Error::from)
237    } else {
238        let local_var_entity: Option<CreateCharacterError> =
239            serde_json::from_str(&local_var_content).ok();
240        let local_var_error = ResponseContent {
241            status: local_var_status,
242            content: local_var_content,
243            entity: local_var_entity,
244        };
245        Err(Error::ResponseError(local_var_error))
246    }
247}
248
249/// Delete character on your account.
250pub async fn delete_character(
251    configuration: &configuration::Configuration,
252    params: DeleteCharacterParams,
253) -> Result<models::CharacterResponseSchema, Error<DeleteCharacterError>> {
254    let local_var_configuration = configuration;
255
256    // unbox the parameters
257    let delete_character_schema = params.delete_character_schema;
258
259    let local_var_client = &local_var_configuration.client;
260
261    let local_var_uri_str = format!("{}/characters/delete", local_var_configuration.base_path);
262    let mut local_var_req_builder =
263        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
264
265    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
266        local_var_req_builder =
267            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
268    }
269    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
270        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
271    };
272    local_var_req_builder = local_var_req_builder.json(&delete_character_schema);
273
274    let local_var_req = local_var_req_builder.build()?;
275    let local_var_resp = local_var_client.execute(local_var_req).await?;
276
277    let local_var_status = local_var_resp.status();
278    let local_var_content = local_var_resp.text().await?;
279
280    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
281        serde_json::from_str(&local_var_content).map_err(Error::from)
282    } else {
283        let local_var_entity: Option<DeleteCharacterError> =
284            serde_json::from_str(&local_var_content).ok();
285        let local_var_error = ResponseContent {
286            status: local_var_status,
287            content: local_var_content,
288            entity: local_var_entity,
289        };
290        Err(Error::ResponseError(local_var_error))
291    }
292}
293
294/// Fetch active characters details.
295pub async fn get_active_characters(
296    configuration: &configuration::Configuration,
297    params: GetActiveCharactersParams,
298) -> Result<models::DataPageActiveCharacterSchema, Error<GetActiveCharactersError>> {
299    let local_var_configuration = configuration;
300
301    // unbox the parameters
302    let page = params.page;
303    // unbox the parameters
304    let size = params.size;
305
306    let local_var_client = &local_var_configuration.client;
307
308    let local_var_uri_str = format!("{}/characters/active", local_var_configuration.base_path);
309    let mut local_var_req_builder =
310        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
311
312    if let Some(ref local_var_str) = page {
313        local_var_req_builder =
314            local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
315    }
316    if let Some(ref local_var_str) = size {
317        local_var_req_builder =
318            local_var_req_builder.query(&[("size", &local_var_str.to_string())]);
319    }
320    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
321        local_var_req_builder =
322            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
323    }
324
325    let local_var_req = local_var_req_builder.build()?;
326    let local_var_resp = local_var_client.execute(local_var_req).await?;
327
328    let local_var_status = local_var_resp.status();
329    let local_var_content = local_var_resp.text().await?;
330
331    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
332        serde_json::from_str(&local_var_content).map_err(Error::from)
333    } else {
334        let local_var_entity: Option<GetActiveCharactersError> =
335            serde_json::from_str(&local_var_content).ok();
336        let local_var_error = ResponseContent {
337            status: local_var_status,
338            content: local_var_content,
339            entity: local_var_entity,
340        };
341        Err(Error::ResponseError(local_var_error))
342    }
343}
344
345/// Retrieve the details of a character.
346pub async fn get_character(
347    configuration: &configuration::Configuration,
348    params: GetCharacterParams,
349) -> Result<models::CharacterResponseSchema, Error<GetCharacterError>> {
350    let local_var_configuration = configuration;
351
352    // unbox the parameters
353    let name = params.name;
354
355    let local_var_client = &local_var_configuration.client;
356
357    let local_var_uri_str = format!(
358        "{}/characters/{name}",
359        local_var_configuration.base_path,
360        name = crate::apis::urlencode(name)
361    );
362    let mut local_var_req_builder =
363        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
364
365    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
366        local_var_req_builder =
367            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
368    }
369
370    let local_var_req = local_var_req_builder.build()?;
371    let local_var_resp = local_var_client.execute(local_var_req).await?;
372
373    let local_var_status = local_var_resp.status();
374    let local_var_content = local_var_resp.text().await?;
375
376    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
377        serde_json::from_str(&local_var_content).map_err(Error::from)
378    } else {
379        let local_var_entity: Option<GetCharacterError> =
380            serde_json::from_str(&local_var_content).ok();
381        let local_var_error = ResponseContent {
382            status: local_var_status,
383            content: local_var_content,
384            entity: local_var_entity,
385        };
386        Err(Error::ResponseError(local_var_error))
387    }
388}
389
390/// Retrieve gameplay statistics for a character.  Stats are only visible if the character's account has an active subscription. Statistics are still collected for all accounts regardless of subscription status.
391pub async fn get_character_stats(
392    configuration: &configuration::Configuration,
393    params: GetCharacterStatsParams,
394) -> Result<models::CharacterStatsResponseSchema, Error<GetCharacterStatsError>> {
395    let local_var_configuration = configuration;
396
397    // unbox the parameters
398    let name = params.name;
399
400    let local_var_client = &local_var_configuration.client;
401
402    let local_var_uri_str = format!(
403        "{}/characters/{name}/stats",
404        local_var_configuration.base_path,
405        name = crate::apis::urlencode(name)
406    );
407    let mut local_var_req_builder =
408        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
409
410    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
411        local_var_req_builder =
412            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
413    }
414
415    let local_var_req = local_var_req_builder.build()?;
416    let local_var_resp = local_var_client.execute(local_var_req).await?;
417
418    let local_var_status = local_var_resp.status();
419    let local_var_content = local_var_resp.text().await?;
420
421    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
422        serde_json::from_str(&local_var_content).map_err(Error::from)
423    } else {
424        let local_var_entity: Option<GetCharacterStatsError> =
425            serde_json::from_str(&local_var_content).ok();
426        let local_var_error = ResponseContent {
427            status: local_var_status,
428            content: local_var_content,
429            entity: local_var_entity,
430        };
431        Err(Error::ResponseError(local_var_error))
432    }
433}