artifacts/apis/
characters_api.rs

1use super::{configuration, Error};
2use crate::{apis::ResponseContent, models};
3use reqwest::StatusCode;
4use serde::{Deserialize, 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_character`]
35#[derive(Clone, Debug)]
36pub struct GetCharacterParams {
37    /// The character name.
38    pub name: String,
39}
40
41impl GetCharacterParams {
42    pub fn new(name: String) -> Self {
43        Self { name }
44    }
45}
46
47/// struct for typed errors of method [`create_character`]
48#[derive(Debug, Clone, Serialize, Deserialize)]
49#[serde(untagged)]
50pub enum CreateCharacterError {
51    /// This name is already in use.
52    Status494,
53    /// You have reached the maximum number of characters on your account.
54    Status495,
55    /// You cannot choose this skin because you do not own it.
56    Status550,
57}
58
59impl TryFrom<StatusCode> for CreateCharacterError {
60    type Error = &'static str;
61    #[allow(clippy::match_single_binding)]
62    fn try_from(status: StatusCode) -> Result<Self, Self::Error> {
63        match status.as_u16() {
64            494 => Ok(Self::Status494),
65            495 => Ok(Self::Status495),
66            550 => Ok(Self::Status550),
67            _ => Err("status code not in spec"),
68        }
69    }
70}
71
72/// struct for typed errors of method [`delete_character`]
73#[derive(Debug, Clone, Serialize, Deserialize)]
74#[serde(untagged)]
75pub enum DeleteCharacterError {
76    /// Character not found.
77    Status498,
78}
79
80impl TryFrom<StatusCode> for DeleteCharacterError {
81    type Error = &'static str;
82    #[allow(clippy::match_single_binding)]
83    fn try_from(status: StatusCode) -> Result<Self, Self::Error> {
84        match status.as_u16() {
85            498 => Ok(Self::Status498),
86            _ => Err("status code not in spec"),
87        }
88    }
89}
90
91/// struct for typed errors of method [`get_character`]
92#[derive(Debug, Clone, Serialize, Deserialize)]
93#[serde(untagged)]
94pub enum GetCharacterError {
95    /// Character not found.
96    Status404,
97}
98
99impl TryFrom<StatusCode> for GetCharacterError {
100    type Error = &'static str;
101    #[allow(clippy::match_single_binding)]
102    fn try_from(status: StatusCode) -> Result<Self, Self::Error> {
103        match status.as_u16() {
104            404 => Ok(Self::Status404),
105            _ => Err("status code not in spec"),
106        }
107    }
108}
109
110/// Create new character on your account. You can create up to 5 characters.
111pub async fn create_character(
112    configuration: &configuration::Configuration,
113    params: CreateCharacterParams,
114) -> Result<models::CharacterResponseSchema, Error<CreateCharacterError>> {
115    let local_var_configuration = configuration;
116
117    // unbox the parameters
118    let add_character_schema = params.add_character_schema;
119
120    let local_var_client = &local_var_configuration.client;
121
122    let local_var_uri_str = format!("{}/characters/create", local_var_configuration.base_path);
123    let mut local_var_req_builder =
124        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
125
126    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
127        local_var_req_builder =
128            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
129    }
130    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
131        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
132    };
133    local_var_req_builder = local_var_req_builder.json(&add_character_schema);
134
135    let local_var_req = local_var_req_builder.build()?;
136    let local_var_resp = local_var_client.execute(local_var_req).await?;
137
138    let local_var_status = local_var_resp.status();
139    let local_var_content = local_var_resp.text().await?;
140
141    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
142        serde_json::from_str(&local_var_content).map_err(Error::from)
143    } else {
144        let local_var_entity: Option<CreateCharacterError> = local_var_status.try_into().ok();
145        let local_var_error = ResponseContent {
146            status: local_var_status,
147            content: local_var_content,
148            entity: local_var_entity,
149        };
150        Err(Error::ResponseError(local_var_error))
151    }
152}
153
154/// Delete character on your account.
155pub async fn delete_character(
156    configuration: &configuration::Configuration,
157    params: DeleteCharacterParams,
158) -> Result<models::CharacterResponseSchema, Error<DeleteCharacterError>> {
159    let local_var_configuration = configuration;
160
161    // unbox the parameters
162    let delete_character_schema = params.delete_character_schema;
163
164    let local_var_client = &local_var_configuration.client;
165
166    let local_var_uri_str = format!("{}/characters/delete", local_var_configuration.base_path);
167    let mut local_var_req_builder =
168        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
169
170    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
171        local_var_req_builder =
172            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
173    }
174    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
175        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
176    };
177    local_var_req_builder = local_var_req_builder.json(&delete_character_schema);
178
179    let local_var_req = local_var_req_builder.build()?;
180    let local_var_resp = local_var_client.execute(local_var_req).await?;
181
182    let local_var_status = local_var_resp.status();
183    let local_var_content = local_var_resp.text().await?;
184
185    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
186        serde_json::from_str(&local_var_content).map_err(Error::from)
187    } else {
188        let local_var_entity: Option<DeleteCharacterError> = local_var_status.try_into().ok();
189        let local_var_error = ResponseContent {
190            status: local_var_status,
191            content: local_var_content,
192            entity: local_var_entity,
193        };
194        Err(Error::ResponseError(local_var_error))
195    }
196}
197
198/// Retrieve the details of a character.
199pub async fn get_character(
200    configuration: &configuration::Configuration,
201    params: GetCharacterParams,
202) -> Result<models::CharacterResponseSchema, Error<GetCharacterError>> {
203    let local_var_configuration = configuration;
204
205    // unbox the parameters
206    let name = params.name;
207
208    let local_var_client = &local_var_configuration.client;
209
210    let local_var_uri_str = format!(
211        "{}/characters/{name}",
212        local_var_configuration.base_path,
213        name = crate::apis::urlencode(name)
214    );
215    let mut local_var_req_builder =
216        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
217
218    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
219        local_var_req_builder =
220            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
221    }
222
223    let local_var_req = local_var_req_builder.build()?;
224    let local_var_resp = local_var_client.execute(local_var_req).await?;
225
226    let local_var_status = local_var_resp.status();
227    let local_var_content = local_var_resp.text().await?;
228
229    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
230        serde_json::from_str(&local_var_content).map_err(Error::from)
231    } else {
232        let local_var_entity: Option<GetCharacterError> = local_var_status.try_into().ok();
233        let local_var_error = ResponseContent {
234            status: local_var_status,
235            content: local_var_content,
236            entity: local_var_entity,
237        };
238        Err(Error::ResponseError(local_var_error))
239    }
240}