Skip to main content

bitwarden_api_api/apis/
info_api.rs

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