1use reqwest;
12use serde::{de::Error as _, Deserialize, Serialize};
13
14use super::{configuration, ContentType, Error};
15use crate::{apis::ResponseContent, models};
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum PostLoginError {
21 Status400(models::JsonErrorResponseNull),
22 Status401(models::JsonErrorResponseNull),
23 Status403(models::JsonErrorResponseNull),
24 Status404(models::JsonErrorResponseNull),
25 Status409(models::JsonErrorResponseNull),
26 Status429(models::JsonErrorResponseNull),
27 Status500(models::JsonErrorResponseNull),
28 UnknownValue(serde_json::Value),
29}
30
31#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(untagged)]
34pub enum PostLogoutError {
35 Status400(models::JsonErrorResponseNull),
36 Status401(models::JsonErrorResponseNull),
37 Status403(models::JsonErrorResponseNull),
38 Status404(models::JsonErrorResponseNull),
39 Status409(models::JsonErrorResponseNull),
40 Status429(models::JsonErrorResponseNull),
41 Status500(models::JsonErrorResponseNull),
42 UnknownValue(serde_json::Value),
43}
44
45#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum PostRegisterError {
49 Status400(models::JsonErrorResponseNull),
50 Status401(models::JsonErrorResponseNull),
51 Status403(models::JsonErrorResponseNull),
52 Status404(models::JsonErrorResponseNull),
53 Status409(models::JsonErrorResponseNull),
54 Status429(models::JsonErrorResponseNull),
55 Status500(models::JsonErrorResponseNull),
56 UnknownValue(serde_json::Value),
57}
58
59#[derive(Debug, Clone, Serialize, Deserialize)]
61#[serde(untagged)]
62pub enum PostTwoFactorPasscodeError {
63 Status400(models::JsonErrorResponseNull),
64 Status401(models::JsonErrorResponseNull),
65 Status403(models::JsonErrorResponseNull),
66 Status404(models::JsonErrorResponseNull),
67 Status409(models::JsonErrorResponseNull),
68 Status429(models::JsonErrorResponseNull),
69 Status500(models::JsonErrorResponseNull),
70 UnknownValue(serde_json::Value),
71}
72
73#[derive(Debug, Clone, Serialize, Deserialize)]
75#[serde(untagged)]
76pub enum PostTwoFactorScratchTokenError {
77 Status400(models::JsonErrorResponseNull),
78 Status401(models::JsonErrorResponseNull),
79 Status403(models::JsonErrorResponseNull),
80 Status404(models::JsonErrorResponseNull),
81 Status409(models::JsonErrorResponseNull),
82 Status429(models::JsonErrorResponseNull),
83 Status500(models::JsonErrorResponseNull),
84 UnknownValue(serde_json::Value),
85}
86
87pub async fn post_login(
88 configuration: &configuration::Configuration,
89 login_input: models::LoginInput,
90) -> Result<models::LoginOutput, Error<PostLoginError>> {
91 let p_body_login_input = login_input;
93
94 let uri_str = format!("{}/account/login", configuration.base_path);
95 let mut req_builder = configuration
96 .client
97 .request(reqwest::Method::POST, &uri_str);
98
99 if let Some(ref user_agent) = configuration.user_agent {
100 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
101 }
102 req_builder = req_builder.json(&p_body_login_input);
103
104 let req = req_builder.build()?;
105 let resp = configuration.client.execute(req).await?;
106
107 let status = resp.status();
108 let content_type = resp
109 .headers()
110 .get("content-type")
111 .and_then(|v| v.to_str().ok())
112 .unwrap_or("application/octet-stream");
113 let content_type = super::ContentType::from(content_type);
114
115 if !status.is_client_error() && !status.is_server_error() {
116 let content = resp.text().await?;
117 match content_type {
118 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
119 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::LoginOutput`"))),
120 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::LoginOutput`")))),
121 }
122 } else {
123 let content = resp.text().await?;
124 let entity: Option<PostLoginError> = serde_json::from_str(&content).ok();
125 Err(Error::ResponseError(ResponseContent {
126 status,
127 content,
128 entity,
129 }))
130 }
131}
132
133pub async fn post_logout(
134 configuration: &configuration::Configuration,
135) -> Result<(), Error<PostLogoutError>> {
136 let uri_str = format!("{}/account/logout", configuration.base_path);
137 let mut req_builder = configuration
138 .client
139 .request(reqwest::Method::POST, &uri_str);
140
141 if let Some(ref apikey) = configuration.api_key {
142 let key = apikey.key.clone();
143 let value = match apikey.prefix {
144 Some(ref prefix) => format!("{} {}", prefix, key),
145 None => key,
146 };
147 req_builder = req_builder.query(&[("access_token", value)]);
148 }
149 if let Some(ref user_agent) = configuration.user_agent {
150 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
151 }
152 if let Some(ref auth_conf) = configuration.basic_auth {
153 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
154 };
155 if let Some(ref token) = configuration.bearer_access_token {
156 req_builder = req_builder.bearer_auth(token.to_owned());
157 };
158
159 let req = req_builder.build()?;
160 let resp = configuration.client.execute(req).await?;
161
162 let status = resp.status();
163
164 if !status.is_client_error() && !status.is_server_error() {
165 Ok(())
166 } else {
167 let content = resp.text().await?;
168 let entity: Option<PostLogoutError> = serde_json::from_str(&content).ok();
169 Err(Error::ResponseError(ResponseContent {
170 status,
171 content,
172 entity,
173 }))
174 }
175}
176
177pub async fn post_register(
178 configuration: &configuration::Configuration,
179 register_input: models::RegisterInput,
180) -> Result<models::UserModel, Error<PostRegisterError>> {
181 let p_body_register_input = register_input;
183
184 let uri_str = format!("{}/account/register", configuration.base_path);
185 let mut req_builder = configuration
186 .client
187 .request(reqwest::Method::POST, &uri_str);
188
189 if let Some(ref user_agent) = configuration.user_agent {
190 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
191 }
192 req_builder = req_builder.json(&p_body_register_input);
193
194 let req = req_builder.build()?;
195 let resp = configuration.client.execute(req).await?;
196
197 let status = resp.status();
198 let content_type = resp
199 .headers()
200 .get("content-type")
201 .and_then(|v| v.to_str().ok())
202 .unwrap_or("application/octet-stream");
203 let content_type = super::ContentType::from(content_type);
204
205 if !status.is_client_error() && !status.is_server_error() {
206 let content = resp.text().await?;
207 match content_type {
208 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
209 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UserModel`"))),
210 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::UserModel`")))),
211 }
212 } else {
213 let content = resp.text().await?;
214 let entity: Option<PostRegisterError> = serde_json::from_str(&content).ok();
215 Err(Error::ResponseError(ResponseContent {
216 status,
217 content,
218 entity,
219 }))
220 }
221}
222
223pub async fn post_two_factor_passcode(
224 configuration: &configuration::Configuration,
225 two_factor_passcode_input: models::TwoFactorPasscodeInput,
226) -> Result<models::LoginOutput, Error<PostTwoFactorPasscodeError>> {
227 let p_body_two_factor_passcode_input = two_factor_passcode_input;
229
230 let uri_str = format!("{}/account/two_factor", configuration.base_path);
231 let mut req_builder = configuration
232 .client
233 .request(reqwest::Method::POST, &uri_str);
234
235 if let Some(ref apikey) = configuration.api_key {
236 let key = apikey.key.clone();
237 let value = match apikey.prefix {
238 Some(ref prefix) => format!("{} {}", prefix, key),
239 None => key,
240 };
241 req_builder = req_builder.query(&[("access_token", value)]);
242 }
243 if let Some(ref user_agent) = configuration.user_agent {
244 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
245 }
246 if let Some(ref auth_conf) = configuration.basic_auth {
247 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
248 };
249 if let Some(ref token) = configuration.bearer_access_token {
250 req_builder = req_builder.bearer_auth(token.to_owned());
251 };
252 req_builder = req_builder.json(&p_body_two_factor_passcode_input);
253
254 let req = req_builder.build()?;
255 let resp = configuration.client.execute(req).await?;
256
257 let status = resp.status();
258 let content_type = resp
259 .headers()
260 .get("content-type")
261 .and_then(|v| v.to_str().ok())
262 .unwrap_or("application/octet-stream");
263 let content_type = super::ContentType::from(content_type);
264
265 if !status.is_client_error() && !status.is_server_error() {
266 let content = resp.text().await?;
267 match content_type {
268 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
269 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::LoginOutput`"))),
270 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::LoginOutput`")))),
271 }
272 } else {
273 let content = resp.text().await?;
274 let entity: Option<PostTwoFactorPasscodeError> = serde_json::from_str(&content).ok();
275 Err(Error::ResponseError(ResponseContent {
276 status,
277 content,
278 entity,
279 }))
280 }
281}
282
283pub async fn post_two_factor_scratch_token(
284 configuration: &configuration::Configuration,
285 two_factor_scratch_token_input: models::TwoFactorScratchTokenInput,
286) -> Result<models::LoginOutput, Error<PostTwoFactorScratchTokenError>> {
287 let p_body_two_factor_scratch_token_input = two_factor_scratch_token_input;
289
290 let uri_str = format!("{}/account/two_factor/scratch", configuration.base_path);
291 let mut req_builder = configuration
292 .client
293 .request(reqwest::Method::POST, &uri_str);
294
295 if let Some(ref apikey) = configuration.api_key {
296 let key = apikey.key.clone();
297 let value = match apikey.prefix {
298 Some(ref prefix) => format!("{} {}", prefix, key),
299 None => key,
300 };
301 req_builder = req_builder.query(&[("access_token", value)]);
302 }
303 if let Some(ref user_agent) = configuration.user_agent {
304 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
305 }
306 if let Some(ref auth_conf) = configuration.basic_auth {
307 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
308 };
309 if let Some(ref token) = configuration.bearer_access_token {
310 req_builder = req_builder.bearer_auth(token.to_owned());
311 };
312 req_builder = req_builder.json(&p_body_two_factor_scratch_token_input);
313
314 let req = req_builder.build()?;
315 let resp = configuration.client.execute(req).await?;
316
317 let status = resp.status();
318 let content_type = resp
319 .headers()
320 .get("content-type")
321 .and_then(|v| v.to_str().ok())
322 .unwrap_or("application/octet-stream");
323 let content_type = super::ContentType::from(content_type);
324
325 if !status.is_client_error() && !status.is_server_error() {
326 let content = resp.text().await?;
327 match content_type {
328 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
329 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::LoginOutput`"))),
330 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::LoginOutput`")))),
331 }
332 } else {
333 let content = resp.text().await?;
334 let entity: Option<PostTwoFactorScratchTokenError> = serde_json::from_str(&content).ok();
335 Err(Error::ResponseError(ResponseContent {
336 status,
337 content,
338 entity,
339 }))
340 }
341}