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