bitwarden_api_api/apis/
installations_api.rs1use 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 InstallationsApi: Send + Sync {
29 async fn get<'a>(
31 &self,
32 id: uuid::Uuid,
33 ) -> Result<models::InstallationResponseModel, Error<GetError>>;
34
35 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 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
72
73 let local_var_resp = local_var_req_builder.send().await?;
74
75 let local_var_status = local_var_resp.status();
76 let local_var_content_type = local_var_resp
77 .headers()
78 .get("content-type")
79 .and_then(|v| v.to_str().ok())
80 .unwrap_or("application/octet-stream");
81 let local_var_content_type = super::ContentType::from(local_var_content_type);
82 let local_var_content = local_var_resp.text().await?;
83
84 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
85 match local_var_content_type {
86 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
87 ContentType::Text => {
88 return Err(Error::from(serde_json::Error::custom(
89 "Received `text/plain` content type response that cannot be converted to `models::InstallationResponseModel`",
90 )));
91 }
92 ContentType::Unsupported(local_var_unknown_type) => {
93 return Err(Error::from(serde_json::Error::custom(format!(
94 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::InstallationResponseModel`"
95 ))));
96 }
97 }
98 } else {
99 let local_var_entity: Option<GetError> = serde_json::from_str(&local_var_content).ok();
100 let local_var_error = ResponseContent {
101 status: local_var_status,
102 content: local_var_content,
103 entity: local_var_entity,
104 };
105 Err(Error::ResponseError(local_var_error))
106 }
107 }
108
109 async fn post<'a>(
110 &self,
111 installation_request_model: Option<models::InstallationRequestModel>,
112 ) -> Result<models::InstallationResponseModel, Error<PostError>> {
113 let local_var_configuration = &self.configuration;
114
115 let local_var_client = &local_var_configuration.client;
116
117 let local_var_uri_str = format!("{}/installations", local_var_configuration.base_path);
118 let mut local_var_req_builder =
119 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
120
121 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
122 local_var_req_builder = local_var_req_builder.json(&installation_request_model);
123
124 let local_var_resp = local_var_req_builder.send().await?;
125
126 let local_var_status = local_var_resp.status();
127 let local_var_content_type = local_var_resp
128 .headers()
129 .get("content-type")
130 .and_then(|v| v.to_str().ok())
131 .unwrap_or("application/octet-stream");
132 let local_var_content_type = super::ContentType::from(local_var_content_type);
133 let local_var_content = local_var_resp.text().await?;
134
135 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
136 match local_var_content_type {
137 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
138 ContentType::Text => {
139 return Err(Error::from(serde_json::Error::custom(
140 "Received `text/plain` content type response that cannot be converted to `models::InstallationResponseModel`",
141 )));
142 }
143 ContentType::Unsupported(local_var_unknown_type) => {
144 return Err(Error::from(serde_json::Error::custom(format!(
145 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::InstallationResponseModel`"
146 ))));
147 }
148 }
149 } else {
150 let local_var_entity: Option<PostError> = serde_json::from_str(&local_var_content).ok();
151 let local_var_error = ResponseContent {
152 status: local_var_status,
153 content: local_var_content,
154 entity: local_var_entity,
155 };
156 Err(Error::ResponseError(local_var_error))
157 }
158 }
159}
160
161#[derive(Debug, Clone, Serialize, Deserialize)]
163#[serde(untagged)]
164pub enum GetError {
165 UnknownValue(serde_json::Value),
166}
167#[derive(Debug, Clone, Serialize, Deserialize)]
169#[serde(untagged)]
170pub enum PostError {
171 UnknownValue(serde_json::Value),
172}