Skip to main content

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_resp = local_var_req_builder.send().await?;
59
60        let local_var_status = local_var_resp.status();
61        let local_var_content_type = local_var_resp
62            .headers()
63            .get("content-type")
64            .and_then(|v| v.to_str().ok())
65            .unwrap_or("application/octet-stream");
66        let local_var_content_type = super::ContentType::from(local_var_content_type);
67        let local_var_content = local_var_resp.text().await?;
68
69        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
70            match local_var_content_type {
71                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
72                ContentType::Text => return Ok(local_var_content),
73                ContentType::Unsupported(local_var_unknown_type) => {
74                    return Err(Error::from(serde_json::Error::custom(format!(
75                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `String`"
76                    ))));
77                }
78            }
79        } else {
80            let local_var_entity: Option<GetAliveError> =
81                serde_json::from_str(&local_var_content).ok();
82            let local_var_error = ResponseContent {
83                status: local_var_status,
84                content: local_var_content,
85                entity: local_var_entity,
86            };
87            Err(Error::ResponseError(local_var_error))
88        }
89    }
90
91    async fn get_version(&self) -> Result<(), Error<GetVersionError>> {
92        let local_var_configuration = &self.configuration;
93
94        let local_var_client = &local_var_configuration.client;
95
96        let local_var_uri_str = format!("{}/version", local_var_configuration.base_path);
97        let mut local_var_req_builder =
98            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
99
100        let local_var_resp = local_var_req_builder.send().await?;
101
102        let local_var_status = local_var_resp.status();
103        let local_var_content = local_var_resp.text().await?;
104
105        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
106            Ok(())
107        } else {
108            let local_var_entity: Option<GetVersionError> =
109                serde_json::from_str(&local_var_content).ok();
110            let local_var_error = ResponseContent {
111                status: local_var_status,
112                content: local_var_content,
113                entity: local_var_entity,
114            };
115            Err(Error::ResponseError(local_var_error))
116        }
117    }
118}
119
120/// struct for typed errors of method [`InfoApi::get_alive`]
121#[derive(Debug, Clone, Serialize, Deserialize)]
122#[serde(untagged)]
123pub enum GetAliveError {
124    UnknownValue(serde_json::Value),
125}
126/// struct for typed errors of method [`InfoApi::get_version`]
127#[derive(Debug, Clone, Serialize, Deserialize)]
128#[serde(untagged)]
129pub enum GetVersionError {
130    UnknownValue(serde_json::Value),
131}