artifacts/apis/
accounts_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_account`]
7#[derive(Clone, Debug)]
8pub struct CreateAccountParams {
9    pub add_account_schema: models::AddAccountSchema,
10}
11
12impl CreateAccountParams {
13    pub fn new(add_account_schema: models::AddAccountSchema) -> Self {
14        Self { add_account_schema }
15    }
16}
17
18/// struct for passing parameters to the method [`forgot_password`]
19#[derive(Clone, Debug)]
20pub struct ForgotPasswordParams {
21    pub password_reset_request_schema: models::PasswordResetRequestSchema,
22}
23
24impl ForgotPasswordParams {
25    pub fn new(password_reset_request_schema: models::PasswordResetRequestSchema) -> Self {
26        Self {
27            password_reset_request_schema,
28        }
29    }
30}
31
32/// struct for passing parameters to the method [`get_account`]
33#[derive(Clone, Debug)]
34pub struct GetAccountParams {
35    /// The name of the account.
36    pub account: String,
37}
38
39impl GetAccountParams {
40    pub fn new(account: String) -> Self {
41        Self { account }
42    }
43}
44
45/// struct for passing parameters to the method [`get_account_achievements`]
46#[derive(Clone, Debug)]
47pub struct GetAccountAchievementsParams {
48    /// The name of the account.
49    pub account: String,
50    /// Type of achievements.
51    pub r#type: Option<String>,
52    /// Filter by completed achievements.
53    pub completed: Option<bool>,
54    /// Page number
55    pub page: Option<u32>,
56    /// Page size
57    pub size: Option<u32>,
58}
59
60impl GetAccountAchievementsParams {
61    pub fn new(
62        account: String,
63        r#type: Option<String>,
64        completed: Option<bool>,
65        page: Option<u32>,
66        size: Option<u32>,
67    ) -> Self {
68        Self {
69            account,
70            r#type,
71            completed,
72            page,
73            size,
74        }
75    }
76}
77
78/// struct for passing parameters to the method [`get_account_characters`]
79#[derive(Clone, Debug)]
80pub struct GetAccountCharactersParams {
81    /// The name of the account.
82    pub account: String,
83}
84
85impl GetAccountCharactersParams {
86    pub fn new(account: String) -> Self {
87        Self { account }
88    }
89}
90
91/// struct for passing parameters to the method [`reset_password`]
92#[derive(Clone, Debug)]
93pub struct ResetPasswordParams {
94    pub password_reset_confirm_schema: models::PasswordResetConfirmSchema,
95}
96
97impl ResetPasswordParams {
98    pub fn new(password_reset_confirm_schema: models::PasswordResetConfirmSchema) -> Self {
99        Self {
100            password_reset_confirm_schema,
101        }
102    }
103}
104
105/// struct for typed errors of method [`create_account`]
106#[derive(Debug, Clone, Serialize)]
107#[serde(untagged)]
108pub enum CreateAccountError {
109    /// This username is already taken.
110    Status456(models::ErrorResponseSchema),
111    /// This email is already in use.
112    Status457(models::ErrorResponseSchema),
113    /// Request could not be processed due to an invalid payload.
114    Status422(models::ErrorResponseSchema),
115}
116
117impl<'de> Deserialize<'de> for CreateAccountError {
118    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
119    where
120        D: Deserializer<'de>,
121    {
122        let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
123        match raw.error.code {
124            456 => Ok(Self::Status456(raw)),
125            457 => Ok(Self::Status457(raw)),
126            422 => Ok(Self::Status422(raw)),
127            _ => Err(de::Error::custom(format!(
128                "Unexpected error code: {}",
129                raw.error.code
130            ))),
131        }
132    }
133}
134
135/// struct for typed errors of method [`forgot_password`]
136#[derive(Debug, Clone, Serialize)]
137#[serde(untagged)]
138pub enum ForgotPasswordError {
139    /// Request could not be processed due to an invalid payload.
140    Status422(models::ErrorResponseSchema),
141}
142
143impl<'de> Deserialize<'de> for ForgotPasswordError {
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        match raw.error.code {
150            422 => Ok(Self::Status422(raw)),
151            _ => Err(de::Error::custom(format!(
152                "Unexpected error code: {}",
153                raw.error.code
154            ))),
155        }
156    }
157}
158
159/// struct for typed errors of method [`get_account`]
160#[derive(Debug, Clone, Serialize)]
161#[serde(untagged)]
162pub enum GetAccountError {
163    /// account not found.
164    Status404(models::ErrorResponseSchema),
165}
166
167impl<'de> Deserialize<'de> for GetAccountError {
168    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
169    where
170        D: Deserializer<'de>,
171    {
172        let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
173        match raw.error.code {
174            404 => Ok(Self::Status404(raw)),
175            _ => Err(de::Error::custom(format!(
176                "Unexpected error code: {}",
177                raw.error.code
178            ))),
179        }
180    }
181}
182
183/// struct for typed errors of method [`get_account_achievements`]
184#[derive(Debug, Clone, Serialize)]
185#[serde(untagged)]
186pub enum GetAccountAchievementsError {
187    /// Account not found.
188    Status404(models::ErrorResponseSchema),
189}
190
191impl<'de> Deserialize<'de> for GetAccountAchievementsError {
192    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
193    where
194        D: Deserializer<'de>,
195    {
196        let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
197        match raw.error.code {
198            404 => Ok(Self::Status404(raw)),
199            _ => Err(de::Error::custom(format!(
200                "Unexpected error code: {}",
201                raw.error.code
202            ))),
203        }
204    }
205}
206
207/// struct for typed errors of method [`get_account_characters`]
208#[derive(Debug, Clone, Serialize)]
209#[serde(untagged)]
210pub enum GetAccountCharactersError {}
211
212impl<'de> Deserialize<'de> for GetAccountCharactersError {
213    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
214    where
215        D: Deserializer<'de>,
216    {
217        let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
218        Err(de::Error::custom(format!(
219            "Unexpected error code: {}",
220            raw.error.code
221        )))
222    }
223}
224
225/// struct for typed errors of method [`reset_password`]
226#[derive(Debug, Clone, Serialize)]
227#[serde(untagged)]
228pub enum ResetPasswordError {
229    /// The password reset token has expired.
230    Status561(models::ErrorResponseSchema),
231    /// This password reset token has already been used.
232    Status562(models::ErrorResponseSchema),
233    /// The password reset token is invalid.
234    Status560(models::ErrorResponseSchema),
235    /// Request could not be processed due to an invalid payload.
236    Status422(models::ErrorResponseSchema),
237}
238
239impl<'de> Deserialize<'de> for ResetPasswordError {
240    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
241    where
242        D: Deserializer<'de>,
243    {
244        let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
245        match raw.error.code {
246            561 => Ok(Self::Status561(raw)),
247            562 => Ok(Self::Status562(raw)),
248            560 => Ok(Self::Status560(raw)),
249            422 => Ok(Self::Status422(raw)),
250            _ => Err(de::Error::custom(format!(
251                "Unexpected error code: {}",
252                raw.error.code
253            ))),
254        }
255    }
256}
257
258pub async fn create_account(
259    configuration: &configuration::Configuration,
260    params: CreateAccountParams,
261) -> Result<models::ResponseSchema, Error<CreateAccountError>> {
262    let local_var_configuration = configuration;
263
264    // unbox the parameters
265    let add_account_schema = params.add_account_schema;
266
267    let local_var_client = &local_var_configuration.client;
268
269    let local_var_uri_str = format!("{}/accounts/create", local_var_configuration.base_path);
270    let mut local_var_req_builder =
271        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
272
273    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
274        local_var_req_builder =
275            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
276    }
277    local_var_req_builder = local_var_req_builder.json(&add_account_schema);
278
279    let local_var_req = local_var_req_builder.build()?;
280    let local_var_resp = local_var_client.execute(local_var_req).await?;
281
282    let local_var_status = local_var_resp.status();
283    let local_var_content = local_var_resp.text().await?;
284
285    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
286        serde_json::from_str(&local_var_content).map_err(Error::from)
287    } else {
288        let local_var_entity: Option<CreateAccountError> =
289            serde_json::from_str(&local_var_content).ok();
290        let local_var_error = ResponseContent {
291            status: local_var_status,
292            content: local_var_content,
293            entity: local_var_entity,
294        };
295        Err(Error::ResponseError(local_var_error))
296    }
297}
298
299/// Request a password reset.
300pub async fn forgot_password(
301    configuration: &configuration::Configuration,
302    params: ForgotPasswordParams,
303) -> Result<models::PasswordResetResponseSchema, Error<ForgotPasswordError>> {
304    let local_var_configuration = configuration;
305
306    // unbox the parameters
307    let password_reset_request_schema = params.password_reset_request_schema;
308
309    let local_var_client = &local_var_configuration.client;
310
311    let local_var_uri_str = format!(
312        "{}/accounts/forgot_password",
313        local_var_configuration.base_path
314    );
315    let mut local_var_req_builder =
316        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
317
318    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
319        local_var_req_builder =
320            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
321    }
322    local_var_req_builder = local_var_req_builder.json(&password_reset_request_schema);
323
324    let local_var_req = local_var_req_builder.build()?;
325    let local_var_resp = local_var_client.execute(local_var_req).await?;
326
327    let local_var_status = local_var_resp.status();
328    let local_var_content = local_var_resp.text().await?;
329
330    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
331        serde_json::from_str(&local_var_content).map_err(Error::from)
332    } else {
333        let local_var_entity: Option<ForgotPasswordError> =
334            serde_json::from_str(&local_var_content).ok();
335        let local_var_error = ResponseContent {
336            status: local_var_status,
337            content: local_var_content,
338            entity: local_var_entity,
339        };
340        Err(Error::ResponseError(local_var_error))
341    }
342}
343
344/// Retrieve the details of an account.
345pub async fn get_account(
346    configuration: &configuration::Configuration,
347    params: GetAccountParams,
348) -> Result<models::AccountDetailsSchema, Error<GetAccountError>> {
349    let local_var_configuration = configuration;
350
351    // unbox the parameters
352    let account = params.account;
353
354    let local_var_client = &local_var_configuration.client;
355
356    let local_var_uri_str = format!(
357        "{}/accounts/{account}",
358        local_var_configuration.base_path,
359        account = crate::apis::urlencode(account)
360    );
361    let mut local_var_req_builder =
362        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
363
364    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
365        local_var_req_builder =
366            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
367    }
368
369    let local_var_req = local_var_req_builder.build()?;
370    let local_var_resp = local_var_client.execute(local_var_req).await?;
371
372    let local_var_status = local_var_resp.status();
373    let local_var_content = local_var_resp.text().await?;
374
375    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
376        serde_json::from_str(&local_var_content).map_err(Error::from)
377    } else {
378        let local_var_entity: Option<GetAccountError> =
379            serde_json::from_str(&local_var_content).ok();
380        let local_var_error = ResponseContent {
381            status: local_var_status,
382            content: local_var_content,
383            entity: local_var_entity,
384        };
385        Err(Error::ResponseError(local_var_error))
386    }
387}
388
389/// Retrieve the achievements of a account.
390pub async fn get_account_achievements(
391    configuration: &configuration::Configuration,
392    params: GetAccountAchievementsParams,
393) -> Result<models::DataPageAccountAchievementSchema, Error<GetAccountAchievementsError>> {
394    let local_var_configuration = configuration;
395
396    // unbox the parameters
397    let account = params.account;
398    // unbox the parameters
399    let r#type = params.r#type;
400    // unbox the parameters
401    let completed = params.completed;
402    // unbox the parameters
403    let page = params.page;
404    // unbox the parameters
405    let size = params.size;
406
407    let local_var_client = &local_var_configuration.client;
408
409    let local_var_uri_str = format!(
410        "{}/accounts/{account}/achievements",
411        local_var_configuration.base_path,
412        account = crate::apis::urlencode(account)
413    );
414    let mut local_var_req_builder =
415        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
416
417    if let Some(ref local_var_str) = r#type {
418        local_var_req_builder =
419            local_var_req_builder.query(&[("type", &local_var_str.to_string())]);
420    }
421    if let Some(ref local_var_str) = completed {
422        local_var_req_builder =
423            local_var_req_builder.query(&[("completed", &local_var_str.to_string())]);
424    }
425    if let Some(ref local_var_str) = page {
426        local_var_req_builder =
427            local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
428    }
429    if let Some(ref local_var_str) = size {
430        local_var_req_builder =
431            local_var_req_builder.query(&[("size", &local_var_str.to_string())]);
432    }
433    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
434        local_var_req_builder =
435            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
436    }
437
438    let local_var_req = local_var_req_builder.build()?;
439    let local_var_resp = local_var_client.execute(local_var_req).await?;
440
441    let local_var_status = local_var_resp.status();
442    let local_var_content = local_var_resp.text().await?;
443
444    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
445        serde_json::from_str(&local_var_content).map_err(Error::from)
446    } else {
447        let local_var_entity: Option<GetAccountAchievementsError> =
448            serde_json::from_str(&local_var_content).ok();
449        let local_var_error = ResponseContent {
450            status: local_var_status,
451            content: local_var_content,
452            entity: local_var_entity,
453        };
454        Err(Error::ResponseError(local_var_error))
455    }
456}
457
458/// Account character lists.
459pub async fn get_account_characters(
460    configuration: &configuration::Configuration,
461    params: GetAccountCharactersParams,
462) -> Result<models::CharactersListSchema, Error<GetAccountCharactersError>> {
463    let local_var_configuration = configuration;
464
465    // unbox the parameters
466    let account = params.account;
467
468    let local_var_client = &local_var_configuration.client;
469
470    let local_var_uri_str = format!(
471        "{}/accounts/{account}/characters",
472        local_var_configuration.base_path,
473        account = crate::apis::urlencode(account)
474    );
475    let mut local_var_req_builder =
476        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
477
478    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
479        local_var_req_builder =
480            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
481    }
482
483    let local_var_req = local_var_req_builder.build()?;
484    let local_var_resp = local_var_client.execute(local_var_req).await?;
485
486    let local_var_status = local_var_resp.status();
487    let local_var_content = local_var_resp.text().await?;
488
489    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
490        serde_json::from_str(&local_var_content).map_err(Error::from)
491    } else {
492        let local_var_entity: Option<GetAccountCharactersError> =
493            serde_json::from_str(&local_var_content).ok();
494        let local_var_error = ResponseContent {
495            status: local_var_status,
496            content: local_var_content,
497            entity: local_var_entity,
498        };
499        Err(Error::ResponseError(local_var_error))
500    }
501}
502
503/// Reset password with a token. Use /forgot_password to get a token by email.
504pub async fn reset_password(
505    configuration: &configuration::Configuration,
506    params: ResetPasswordParams,
507) -> Result<models::PasswordResetResponseSchema, Error<ResetPasswordError>> {
508    let local_var_configuration = configuration;
509
510    // unbox the parameters
511    let password_reset_confirm_schema = params.password_reset_confirm_schema;
512
513    let local_var_client = &local_var_configuration.client;
514
515    let local_var_uri_str = format!(
516        "{}/accounts/reset_password",
517        local_var_configuration.base_path
518    );
519    let mut local_var_req_builder =
520        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
521
522    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
523        local_var_req_builder =
524            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
525    }
526    local_var_req_builder = local_var_req_builder.json(&password_reset_confirm_schema);
527
528    let local_var_req = local_var_req_builder.build()?;
529    let local_var_resp = local_var_client.execute(local_var_req).await?;
530
531    let local_var_status = local_var_resp.status();
532    let local_var_content = local_var_resp.text().await?;
533
534    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
535        serde_json::from_str(&local_var_content).map_err(Error::from)
536    } else {
537        let local_var_entity: Option<ResetPasswordError> =
538            serde_json::from_str(&local_var_content).ok();
539        let local_var_error = ResponseContent {
540            status: local_var_status,
541            content: local_var_content,
542            entity: local_var_entity,
543        };
544        Err(Error::ResponseError(local_var_error))
545    }
546}