bitwarden_api_api/apis/
installations_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::{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 InstallationsApi: Send + Sync {
29    /// GET /installations/{id}
30    async fn get<'a>(
31        &self,
32        id: uuid::Uuid,
33    ) -> Result<models::InstallationResponseModel, Error<GetError>>;
34
35    /// POST /installations
36    async fn post<'a>(
37        &self,
38        installation_request_model: Option<models::InstallationRequestModel>,
39    ) -> Result<models::InstallationResponseModel, Error<PostError>>;
40}
41
42pub struct InstallationsApiClient {
43    configuration: Arc<configuration::Configuration>,
44}
45
46impl InstallationsApiClient {
47    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
48        Self { configuration }
49    }
50}
51
52#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
53#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
54impl InstallationsApi for InstallationsApiClient {
55    async fn get<'a>(
56        &self,
57        id: uuid::Uuid,
58    ) -> Result<models::InstallationResponseModel, Error<GetError>> {
59        let local_var_configuration = &self.configuration;
60
61        let local_var_client = &local_var_configuration.client;
62
63        let local_var_uri_str = format!(
64            "{}/installations/{id}",
65            local_var_configuration.base_path,
66            id = id
67        );
68        let mut local_var_req_builder =
69            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
70
71        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
72            local_var_req_builder = local_var_req_builder
73                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
74        }
75        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
76            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
77        };
78
79        let local_var_req = local_var_req_builder.build()?;
80        let local_var_resp = local_var_client.execute(local_var_req).await?;
81
82        let local_var_status = local_var_resp.status();
83        let local_var_content_type = local_var_resp
84            .headers()
85            .get("content-type")
86            .and_then(|v| v.to_str().ok())
87            .unwrap_or("application/octet-stream");
88        let local_var_content_type = super::ContentType::from(local_var_content_type);
89        let local_var_content = local_var_resp.text().await?;
90
91        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
92            match local_var_content_type {
93                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
94                ContentType::Text => {
95                    return Err(Error::from(serde_json::Error::custom(
96                        "Received `text/plain` content type response that cannot be converted to `models::InstallationResponseModel`",
97                    )));
98                }
99                ContentType::Unsupported(local_var_unknown_type) => {
100                    return Err(Error::from(serde_json::Error::custom(format!(
101                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::InstallationResponseModel`"
102                    ))));
103                }
104            }
105        } else {
106            let local_var_entity: Option<GetError> = serde_json::from_str(&local_var_content).ok();
107            let local_var_error = ResponseContent {
108                status: local_var_status,
109                content: local_var_content,
110                entity: local_var_entity,
111            };
112            Err(Error::ResponseError(local_var_error))
113        }
114    }
115
116    async fn post<'a>(
117        &self,
118        installation_request_model: Option<models::InstallationRequestModel>,
119    ) -> Result<models::InstallationResponseModel, Error<PostError>> {
120        let local_var_configuration = &self.configuration;
121
122        let local_var_client = &local_var_configuration.client;
123
124        let local_var_uri_str = format!("{}/installations", local_var_configuration.base_path);
125        let mut local_var_req_builder =
126            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
127
128        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
129            local_var_req_builder = local_var_req_builder
130                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
131        }
132        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
133            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
134        };
135        local_var_req_builder = local_var_req_builder.json(&installation_request_model);
136
137        let local_var_req = local_var_req_builder.build()?;
138        let local_var_resp = local_var_client.execute(local_var_req).await?;
139
140        let local_var_status = local_var_resp.status();
141        let local_var_content_type = local_var_resp
142            .headers()
143            .get("content-type")
144            .and_then(|v| v.to_str().ok())
145            .unwrap_or("application/octet-stream");
146        let local_var_content_type = super::ContentType::from(local_var_content_type);
147        let local_var_content = local_var_resp.text().await?;
148
149        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
150            match local_var_content_type {
151                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
152                ContentType::Text => {
153                    return Err(Error::from(serde_json::Error::custom(
154                        "Received `text/plain` content type response that cannot be converted to `models::InstallationResponseModel`",
155                    )));
156                }
157                ContentType::Unsupported(local_var_unknown_type) => {
158                    return Err(Error::from(serde_json::Error::custom(format!(
159                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::InstallationResponseModel`"
160                    ))));
161                }
162            }
163        } else {
164            let local_var_entity: Option<PostError> = serde_json::from_str(&local_var_content).ok();
165            let local_var_error = ResponseContent {
166                status: local_var_status,
167                content: local_var_content,
168                entity: local_var_entity,
169            };
170            Err(Error::ResponseError(local_var_error))
171        }
172    }
173}
174
175/// struct for typed errors of method [`InstallationsApi::get`]
176#[derive(Debug, Clone, Serialize, Deserialize)]
177#[serde(untagged)]
178pub enum GetError {
179    UnknownValue(serde_json::Value),
180}
181/// struct for typed errors of method [`InstallationsApi::post`]
182#[derive(Debug, Clone, Serialize, Deserialize)]
183#[serde(untagged)]
184pub enum PostError {
185    UnknownValue(serde_json::Value),
186}