bitwarden_api_identity/apis/
info_api.rs

1/*
2 * Bitwarden Identity
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: v1
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use std::sync::Arc;
12
13use async_trait::async_trait;
14#[cfg(feature = "mockall")]
15use mockall::automock;
16use reqwest;
17use serde::{Deserialize, Serialize, de::Error as _};
18
19use super::{Error, configuration};
20use crate::{
21    apis::{AuthRequired, ContentType, ResponseContent},
22    models,
23};
24
25#[cfg_attr(feature = "mockall", automock)]
26#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
27#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
28pub trait InfoApi: Send + Sync {
29    /// GET /alive
30    async fn get_alive(&self) -> Result<String, Error<GetAliveError>>;
31
32    /// GET /version
33    async fn get_version(&self) -> Result<(), Error<GetVersionError>>;
34}
35
36pub struct InfoApiClient {
37    configuration: Arc<configuration::Configuration>,
38}
39
40impl InfoApiClient {
41    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
42        Self { configuration }
43    }
44}
45
46#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
47#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
48impl InfoApi for InfoApiClient {
49    async fn get_alive(&self) -> Result<String, Error<GetAliveError>> {
50        let local_var_configuration = &self.configuration;
51
52        let local_var_client = &local_var_configuration.client;
53
54        let local_var_uri_str = format!("{}/alive", local_var_configuration.base_path);
55        let mut local_var_req_builder =
56            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
57
58        let local_var_req = local_var_req_builder.build()?;
59        let local_var_resp = local_var_client.execute(local_var_req).await?;
60
61        let local_var_status = local_var_resp.status();
62        let local_var_content_type = local_var_resp
63            .headers()
64            .get("content-type")
65            .and_then(|v| v.to_str().ok())
66            .unwrap_or("application/octet-stream");
67        let local_var_content_type = super::ContentType::from(local_var_content_type);
68        let local_var_content = local_var_resp.text().await?;
69
70        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
71            match local_var_content_type {
72                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
73                ContentType::Text => return Ok(local_var_content),
74                ContentType::Unsupported(local_var_unknown_type) => {
75                    return Err(Error::from(serde_json::Error::custom(format!(
76                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `String`"
77                    ))));
78                }
79            }
80        } else {
81            let local_var_entity: Option<GetAliveError> =
82                serde_json::from_str(&local_var_content).ok();
83            let local_var_error = ResponseContent {
84                status: local_var_status,
85                content: local_var_content,
86                entity: local_var_entity,
87            };
88            Err(Error::ResponseError(local_var_error))
89        }
90    }
91
92    async fn get_version(&self) -> Result<(), Error<GetVersionError>> {
93        let local_var_configuration = &self.configuration;
94
95        let local_var_client = &local_var_configuration.client;
96
97        let local_var_uri_str = format!("{}/version", local_var_configuration.base_path);
98        let mut local_var_req_builder =
99            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
100
101        let local_var_req = local_var_req_builder.build()?;
102        let local_var_resp = local_var_client.execute(local_var_req).await?;
103
104        let local_var_status = local_var_resp.status();
105        let local_var_content = local_var_resp.text().await?;
106
107        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
108            Ok(())
109        } else {
110            let local_var_entity: Option<GetVersionError> =
111                serde_json::from_str(&local_var_content).ok();
112            let local_var_error = ResponseContent {
113                status: local_var_status,
114                content: local_var_content,
115                entity: local_var_entity,
116            };
117            Err(Error::ResponseError(local_var_error))
118        }
119    }
120}
121
122/// struct for typed errors of method [`InfoApi::get_alive`]
123#[derive(Debug, Clone, Serialize, Deserialize)]
124#[serde(untagged)]
125pub enum GetAliveError {
126    UnknownValue(serde_json::Value),
127}
128/// struct for typed errors of method [`InfoApi::get_version`]
129#[derive(Debug, Clone, Serialize, Deserialize)]
130#[serde(untagged)]
131pub enum GetVersionError {
132    UnknownValue(serde_json::Value),
133}