Skip to main content

gitbundle_sdk/apis/
accounts_api.rs

1/*
2 * GitBundle API
3 *
4 * GitBundle API documentation.
5 *
6 * The version of the OpenAPI document: 3.4.1
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use reqwest;
12use serde::{de::Error as _, Deserialize, Serialize};
13
14use super::{configuration, ContentType, Error};
15use crate::{apis::ResponseContent, models};
16
17/// struct for typed errors of method [`post_login`]
18#[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/// struct for typed errors of method [`post_logout`]
32#[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/// struct for typed errors of method [`post_password_forgot`]
46#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum PostPasswordForgotError {
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/// struct for typed errors of method [`post_password_reset`]
60#[derive(Debug, Clone, Serialize, Deserialize)]
61#[serde(untagged)]
62pub enum PostPasswordResetError {
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/// struct for typed errors of method [`post_register`]
74#[derive(Debug, Clone, Serialize, Deserialize)]
75#[serde(untagged)]
76pub enum PostRegisterError {
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
87/// struct for typed errors of method [`post_two_factor_passcode`]
88#[derive(Debug, Clone, Serialize, Deserialize)]
89#[serde(untagged)]
90pub enum PostTwoFactorPasscodeError {
91    Status400(models::JsonErrorResponseNull),
92    Status401(models::JsonErrorResponseNull),
93    Status403(models::JsonErrorResponseNull),
94    Status404(models::JsonErrorResponseNull),
95    Status409(models::JsonErrorResponseNull),
96    Status429(models::JsonErrorResponseNull),
97    Status500(models::JsonErrorResponseNull),
98    UnknownValue(serde_json::Value),
99}
100
101/// struct for typed errors of method [`post_two_factor_scratch_token`]
102#[derive(Debug, Clone, Serialize, Deserialize)]
103#[serde(untagged)]
104pub enum PostTwoFactorScratchTokenError {
105    Status400(models::JsonErrorResponseNull),
106    Status401(models::JsonErrorResponseNull),
107    Status403(models::JsonErrorResponseNull),
108    Status404(models::JsonErrorResponseNull),
109    Status409(models::JsonErrorResponseNull),
110    Status429(models::JsonErrorResponseNull),
111    Status500(models::JsonErrorResponseNull),
112    UnknownValue(serde_json::Value),
113}
114
115/// struct for typed errors of method [`post_verify`]
116#[derive(Debug, Clone, Serialize, Deserialize)]
117#[serde(untagged)]
118pub enum PostVerifyError {
119    Status400(models::JsonErrorResponseNull),
120    Status401(models::JsonErrorResponseNull),
121    Status403(models::JsonErrorResponseNull),
122    Status404(models::JsonErrorResponseNull),
123    Status409(models::JsonErrorResponseNull),
124    Status429(models::JsonErrorResponseNull),
125    Status500(models::JsonErrorResponseNull),
126    UnknownValue(serde_json::Value),
127}
128
129/// struct for typed errors of method [`post_verify_query`]
130#[derive(Debug, Clone, Serialize, Deserialize)]
131#[serde(untagged)]
132pub enum PostVerifyQueryError {
133    Status400(models::JsonErrorResponseNull),
134    Status401(models::JsonErrorResponseNull),
135    Status403(models::JsonErrorResponseNull),
136    Status404(models::JsonErrorResponseNull),
137    Status409(models::JsonErrorResponseNull),
138    Status429(models::JsonErrorResponseNull),
139    Status500(models::JsonErrorResponseNull),
140    UnknownValue(serde_json::Value),
141}
142
143/// struct for typed errors of method [`post_verify_resend`]
144#[derive(Debug, Clone, Serialize, Deserialize)]
145#[serde(untagged)]
146pub enum PostVerifyResendError {
147    Status400(models::JsonErrorResponseNull),
148    Status401(models::JsonErrorResponseNull),
149    Status403(models::JsonErrorResponseNull),
150    Status404(models::JsonErrorResponseNull),
151    Status409(models::JsonErrorResponseNull),
152    Status429(models::JsonErrorResponseNull),
153    Status500(models::JsonErrorResponseNull),
154    UnknownValue(serde_json::Value),
155}
156
157pub async fn post_login(
158    configuration: &configuration::Configuration,
159    login_input: models::LoginInput,
160) -> Result<models::LoginOutput, Error<PostLoginError>> {
161    // add a prefix to parameters to efficiently prevent name collisions
162    let p_body_login_input = login_input;
163
164    let uri_str = format!("{}/account/login", configuration.base_path);
165    let mut req_builder = configuration
166        .client
167        .request(reqwest::Method::POST, &uri_str);
168
169    if let Some(ref user_agent) = configuration.user_agent {
170        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
171    }
172    req_builder = req_builder.json(&p_body_login_input);
173
174    let req = req_builder.build()?;
175    let resp = configuration.client.execute(req).await?;
176
177    let status = resp.status();
178    let content_type = resp
179        .headers()
180        .get("content-type")
181        .and_then(|v| v.to_str().ok())
182        .unwrap_or("application/octet-stream");
183    let content_type = super::ContentType::from(content_type);
184
185    if !status.is_client_error() && !status.is_server_error() {
186        let content = resp.text().await?;
187        match content_type {
188            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
189            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::LoginOutput`"))),
190            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`")))),
191        }
192    } else {
193        let content = resp.text().await?;
194        let entity: Option<PostLoginError> = serde_json::from_str(&content).ok();
195        Err(Error::ResponseError(ResponseContent {
196            status,
197            content,
198            entity,
199        }))
200    }
201}
202
203pub async fn post_logout(
204    configuration: &configuration::Configuration,
205) -> Result<(), Error<PostLogoutError>> {
206    let uri_str = format!("{}/account/logout", configuration.base_path);
207    let mut req_builder = configuration
208        .client
209        .request(reqwest::Method::POST, &uri_str);
210
211    if let Some(ref apikey) = configuration.api_key {
212        let key = apikey.key.clone();
213        let value = match apikey.prefix {
214            Some(ref prefix) => format!("{} {}", prefix, key),
215            None => key,
216        };
217        req_builder = req_builder.query(&[("access_token", value)]);
218    }
219    if let Some(ref user_agent) = configuration.user_agent {
220        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
221    }
222    if let Some(ref auth_conf) = configuration.basic_auth {
223        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
224    };
225    if let Some(ref token) = configuration.bearer_access_token {
226        req_builder = req_builder.bearer_auth(token.to_owned());
227    };
228
229    let req = req_builder.build()?;
230    let resp = configuration.client.execute(req).await?;
231
232    let status = resp.status();
233
234    if !status.is_client_error() && !status.is_server_error() {
235        Ok(())
236    } else {
237        let content = resp.text().await?;
238        let entity: Option<PostLogoutError> = serde_json::from_str(&content).ok();
239        Err(Error::ResponseError(ResponseContent {
240            status,
241            content,
242            entity,
243        }))
244    }
245}
246
247pub async fn post_password_forgot(
248    configuration: &configuration::Configuration,
249    password_forgot_input: models::PasswordForgotInput,
250) -> Result<(), Error<PostPasswordForgotError>> {
251    // add a prefix to parameters to efficiently prevent name collisions
252    let p_body_password_forgot_input = password_forgot_input;
253
254    let uri_str = format!("{}/account/password/forgot", configuration.base_path);
255    let mut req_builder = configuration
256        .client
257        .request(reqwest::Method::POST, &uri_str);
258
259    if let Some(ref user_agent) = configuration.user_agent {
260        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
261    }
262    req_builder = req_builder.json(&p_body_password_forgot_input);
263
264    let req = req_builder.build()?;
265    let resp = configuration.client.execute(req).await?;
266
267    let status = resp.status();
268
269    if !status.is_client_error() && !status.is_server_error() {
270        Ok(())
271    } else {
272        let content = resp.text().await?;
273        let entity: Option<PostPasswordForgotError> = serde_json::from_str(&content).ok();
274        Err(Error::ResponseError(ResponseContent {
275            status,
276            content,
277            entity,
278        }))
279    }
280}
281
282pub async fn post_password_reset(
283    configuration: &configuration::Configuration,
284    password_reset_input: models::PasswordResetInput,
285) -> Result<(), Error<PostPasswordResetError>> {
286    // add a prefix to parameters to efficiently prevent name collisions
287    let p_body_password_reset_input = password_reset_input;
288
289    let uri_str = format!("{}/account/password/reset", configuration.base_path);
290    let mut req_builder = configuration
291        .client
292        .request(reqwest::Method::POST, &uri_str);
293
294    if let Some(ref user_agent) = configuration.user_agent {
295        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
296    }
297    req_builder = req_builder.json(&p_body_password_reset_input);
298
299    let req = req_builder.build()?;
300    let resp = configuration.client.execute(req).await?;
301
302    let status = resp.status();
303
304    if !status.is_client_error() && !status.is_server_error() {
305        Ok(())
306    } else {
307        let content = resp.text().await?;
308        let entity: Option<PostPasswordResetError> = serde_json::from_str(&content).ok();
309        Err(Error::ResponseError(ResponseContent {
310            status,
311            content,
312            entity,
313        }))
314    }
315}
316
317pub async fn post_register(
318    configuration: &configuration::Configuration,
319    register_input: models::RegisterInput,
320) -> Result<models::UserModel, Error<PostRegisterError>> {
321    // add a prefix to parameters to efficiently prevent name collisions
322    let p_body_register_input = register_input;
323
324    let uri_str = format!("{}/account/register", configuration.base_path);
325    let mut req_builder = configuration
326        .client
327        .request(reqwest::Method::POST, &uri_str);
328
329    if let Some(ref user_agent) = configuration.user_agent {
330        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
331    }
332    req_builder = req_builder.json(&p_body_register_input);
333
334    let req = req_builder.build()?;
335    let resp = configuration.client.execute(req).await?;
336
337    let status = resp.status();
338    let content_type = resp
339        .headers()
340        .get("content-type")
341        .and_then(|v| v.to_str().ok())
342        .unwrap_or("application/octet-stream");
343    let content_type = super::ContentType::from(content_type);
344
345    if !status.is_client_error() && !status.is_server_error() {
346        let content = resp.text().await?;
347        match content_type {
348            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
349            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UserModel`"))),
350            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`")))),
351        }
352    } else {
353        let content = resp.text().await?;
354        let entity: Option<PostRegisterError> = serde_json::from_str(&content).ok();
355        Err(Error::ResponseError(ResponseContent {
356            status,
357            content,
358            entity,
359        }))
360    }
361}
362
363pub async fn post_two_factor_passcode(
364    configuration: &configuration::Configuration,
365    two_factor_passcode_input: models::TwoFactorPasscodeInput,
366) -> Result<models::LoginOutput, Error<PostTwoFactorPasscodeError>> {
367    // add a prefix to parameters to efficiently prevent name collisions
368    let p_body_two_factor_passcode_input = two_factor_passcode_input;
369
370    let uri_str = format!("{}/account/two_factor", configuration.base_path);
371    let mut req_builder = configuration
372        .client
373        .request(reqwest::Method::POST, &uri_str);
374
375    if let Some(ref apikey) = configuration.api_key {
376        let key = apikey.key.clone();
377        let value = match apikey.prefix {
378            Some(ref prefix) => format!("{} {}", prefix, key),
379            None => key,
380        };
381        req_builder = req_builder.query(&[("access_token", value)]);
382    }
383    if let Some(ref user_agent) = configuration.user_agent {
384        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
385    }
386    if let Some(ref auth_conf) = configuration.basic_auth {
387        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
388    };
389    if let Some(ref token) = configuration.bearer_access_token {
390        req_builder = req_builder.bearer_auth(token.to_owned());
391    };
392    req_builder = req_builder.json(&p_body_two_factor_passcode_input);
393
394    let req = req_builder.build()?;
395    let resp = configuration.client.execute(req).await?;
396
397    let status = resp.status();
398    let content_type = resp
399        .headers()
400        .get("content-type")
401        .and_then(|v| v.to_str().ok())
402        .unwrap_or("application/octet-stream");
403    let content_type = super::ContentType::from(content_type);
404
405    if !status.is_client_error() && !status.is_server_error() {
406        let content = resp.text().await?;
407        match content_type {
408            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
409            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::LoginOutput`"))),
410            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`")))),
411        }
412    } else {
413        let content = resp.text().await?;
414        let entity: Option<PostTwoFactorPasscodeError> = serde_json::from_str(&content).ok();
415        Err(Error::ResponseError(ResponseContent {
416            status,
417            content,
418            entity,
419        }))
420    }
421}
422
423pub async fn post_two_factor_scratch_token(
424    configuration: &configuration::Configuration,
425    two_factor_scratch_token_input: models::TwoFactorScratchTokenInput,
426) -> Result<models::LoginOutput, Error<PostTwoFactorScratchTokenError>> {
427    // add a prefix to parameters to efficiently prevent name collisions
428    let p_body_two_factor_scratch_token_input = two_factor_scratch_token_input;
429
430    let uri_str = format!("{}/account/two_factor/scratch", configuration.base_path);
431    let mut req_builder = configuration
432        .client
433        .request(reqwest::Method::POST, &uri_str);
434
435    if let Some(ref apikey) = configuration.api_key {
436        let key = apikey.key.clone();
437        let value = match apikey.prefix {
438            Some(ref prefix) => format!("{} {}", prefix, key),
439            None => key,
440        };
441        req_builder = req_builder.query(&[("access_token", value)]);
442    }
443    if let Some(ref user_agent) = configuration.user_agent {
444        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
445    }
446    if let Some(ref auth_conf) = configuration.basic_auth {
447        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
448    };
449    if let Some(ref token) = configuration.bearer_access_token {
450        req_builder = req_builder.bearer_auth(token.to_owned());
451    };
452    req_builder = req_builder.json(&p_body_two_factor_scratch_token_input);
453
454    let req = req_builder.build()?;
455    let resp = configuration.client.execute(req).await?;
456
457    let status = resp.status();
458    let content_type = resp
459        .headers()
460        .get("content-type")
461        .and_then(|v| v.to_str().ok())
462        .unwrap_or("application/octet-stream");
463    let content_type = super::ContentType::from(content_type);
464
465    if !status.is_client_error() && !status.is_server_error() {
466        let content = resp.text().await?;
467        match content_type {
468            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
469            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::LoginOutput`"))),
470            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`")))),
471        }
472    } else {
473        let content = resp.text().await?;
474        let entity: Option<PostTwoFactorScratchTokenError> = serde_json::from_str(&content).ok();
475        Err(Error::ResponseError(ResponseContent {
476            status,
477            content,
478            entity,
479        }))
480    }
481}
482
483pub async fn post_verify(
484    configuration: &configuration::Configuration,
485    verify_link_input: models::VerifyLinkInput,
486) -> Result<(), Error<PostVerifyError>> {
487    // add a prefix to parameters to efficiently prevent name collisions
488    let p_body_verify_link_input = verify_link_input;
489
490    let uri_str = format!("{}/account/verification/confirm", configuration.base_path);
491    let mut req_builder = configuration
492        .client
493        .request(reqwest::Method::POST, &uri_str);
494
495    if let Some(ref user_agent) = configuration.user_agent {
496        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
497    }
498    req_builder = req_builder.json(&p_body_verify_link_input);
499
500    let req = req_builder.build()?;
501    let resp = configuration.client.execute(req).await?;
502
503    let status = resp.status();
504
505    if !status.is_client_error() && !status.is_server_error() {
506        Ok(())
507    } else {
508        let content = resp.text().await?;
509        let entity: Option<PostVerifyError> = serde_json::from_str(&content).ok();
510        Err(Error::ResponseError(ResponseContent {
511            status,
512            content,
513            entity,
514        }))
515    }
516}
517
518pub async fn post_verify_query(
519    configuration: &configuration::Configuration,
520    verify_link_input: models::VerifyLinkInput,
521) -> Result<models::VerifyLinkStatus, Error<PostVerifyQueryError>> {
522    // add a prefix to parameters to efficiently prevent name collisions
523    let p_body_verify_link_input = verify_link_input;
524
525    let uri_str = format!("{}/account/verification/query", configuration.base_path);
526    let mut req_builder = configuration
527        .client
528        .request(reqwest::Method::POST, &uri_str);
529
530    if let Some(ref user_agent) = configuration.user_agent {
531        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
532    }
533    req_builder = req_builder.json(&p_body_verify_link_input);
534
535    let req = req_builder.build()?;
536    let resp = configuration.client.execute(req).await?;
537
538    let status = resp.status();
539    let content_type = resp
540        .headers()
541        .get("content-type")
542        .and_then(|v| v.to_str().ok())
543        .unwrap_or("application/octet-stream");
544    let content_type = super::ContentType::from(content_type);
545
546    if !status.is_client_error() && !status.is_server_error() {
547        let content = resp.text().await?;
548        match content_type {
549            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
550            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::VerifyLinkStatus`"))),
551            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::VerifyLinkStatus`")))),
552        }
553    } else {
554        let content = resp.text().await?;
555        let entity: Option<PostVerifyQueryError> = serde_json::from_str(&content).ok();
556        Err(Error::ResponseError(ResponseContent {
557            status,
558            content,
559            entity,
560        }))
561    }
562}
563
564pub async fn post_verify_resend(
565    configuration: &configuration::Configuration,
566    verify_link_input: models::VerifyLinkInput,
567) -> Result<(), Error<PostVerifyResendError>> {
568    // add a prefix to parameters to efficiently prevent name collisions
569    let p_body_verify_link_input = verify_link_input;
570
571    let uri_str = format!("{}/account/verification/resend", configuration.base_path);
572    let mut req_builder = configuration
573        .client
574        .request(reqwest::Method::POST, &uri_str);
575
576    if let Some(ref user_agent) = configuration.user_agent {
577        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
578    }
579    req_builder = req_builder.json(&p_body_verify_link_input);
580
581    let req = req_builder.build()?;
582    let resp = configuration.client.execute(req).await?;
583
584    let status = resp.status();
585
586    if !status.is_client_error() && !status.is_server_error() {
587        Ok(())
588    } else {
589        let content = resp.text().await?;
590        let entity: Option<PostVerifyResendError> = serde_json::from_str(&content).ok();
591        Err(Error::ResponseError(ResponseContent {
592            status,
593            content,
594            entity,
595        }))
596    }
597}