1use 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 OrganizationConnectionsApi: Send + Sync {
29 async fn connections_enabled(&self) -> Result<bool, Error<ConnectionsEnabledError>>;
31
32 async fn create_connection<'a>(
34 &self,
35 organization_connection_request_model: Option<models::OrganizationConnectionRequestModel>,
36 ) -> Result<models::OrganizationConnectionResponseModel, Error<CreateConnectionError>>;
37
38 async fn delete_connection<'a>(
40 &self,
41 organization_connection_id: uuid::Uuid,
42 ) -> Result<(), Error<DeleteConnectionError>>;
43
44 async fn get_connection<'a>(
46 &self,
47 organization_id: uuid::Uuid,
48 r#type: models::OrganizationConnectionType,
49 ) -> Result<models::OrganizationConnectionResponseModel, Error<GetConnectionError>>;
50
51 async fn update_connection<'a>(
53 &self,
54 organization_connection_id: uuid::Uuid,
55 organization_connection_request_model: Option<models::OrganizationConnectionRequestModel>,
56 ) -> Result<models::OrganizationConnectionResponseModel, Error<UpdateConnectionError>>;
57}
58
59pub struct OrganizationConnectionsApiClient {
60 configuration: Arc<configuration::Configuration>,
61}
62
63impl OrganizationConnectionsApiClient {
64 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
65 Self { configuration }
66 }
67}
68
69#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
70#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
71impl OrganizationConnectionsApi for OrganizationConnectionsApiClient {
72 async fn connections_enabled(&self) -> Result<bool, Error<ConnectionsEnabledError>> {
73 let local_var_configuration = &self.configuration;
74
75 let local_var_client = &local_var_configuration.client;
76
77 let local_var_uri_str = format!(
78 "{}/organizations/connections/enabled",
79 local_var_configuration.base_path
80 );
81 let mut local_var_req_builder =
82 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
83
84 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
85
86 let local_var_resp = local_var_req_builder.send().await?;
87
88 let local_var_status = local_var_resp.status();
89 let local_var_content_type = local_var_resp
90 .headers()
91 .get("content-type")
92 .and_then(|v| v.to_str().ok())
93 .unwrap_or("application/octet-stream");
94 let local_var_content_type = super::ContentType::from(local_var_content_type);
95 let local_var_content = local_var_resp.text().await?;
96
97 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
98 match local_var_content_type {
99 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
100 ContentType::Text => {
101 return Err(Error::from(serde_json::Error::custom(
102 "Received `text/plain` content type response that cannot be converted to `bool`",
103 )));
104 }
105 ContentType::Unsupported(local_var_unknown_type) => {
106 return Err(Error::from(serde_json::Error::custom(format!(
107 "Received `{local_var_unknown_type}` content type response that cannot be converted to `bool`"
108 ))));
109 }
110 }
111 } else {
112 let local_var_entity: Option<ConnectionsEnabledError> =
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 async fn create_connection<'a>(
124 &self,
125 organization_connection_request_model: Option<models::OrganizationConnectionRequestModel>,
126 ) -> Result<models::OrganizationConnectionResponseModel, Error<CreateConnectionError>> {
127 let local_var_configuration = &self.configuration;
128
129 let local_var_client = &local_var_configuration.client;
130
131 let local_var_uri_str = format!(
132 "{}/organizations/connections",
133 local_var_configuration.base_path
134 );
135 let mut local_var_req_builder =
136 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
137
138 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
139 local_var_req_builder = local_var_req_builder.json(&organization_connection_request_model);
140
141 let local_var_resp = local_var_req_builder.send().await?;
142
143 let local_var_status = local_var_resp.status();
144 let local_var_content_type = local_var_resp
145 .headers()
146 .get("content-type")
147 .and_then(|v| v.to_str().ok())
148 .unwrap_or("application/octet-stream");
149 let local_var_content_type = super::ContentType::from(local_var_content_type);
150 let local_var_content = local_var_resp.text().await?;
151
152 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
153 match local_var_content_type {
154 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
155 ContentType::Text => {
156 return Err(Error::from(serde_json::Error::custom(
157 "Received `text/plain` content type response that cannot be converted to `models::OrganizationConnectionResponseModel`",
158 )));
159 }
160 ContentType::Unsupported(local_var_unknown_type) => {
161 return Err(Error::from(serde_json::Error::custom(format!(
162 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::OrganizationConnectionResponseModel`"
163 ))));
164 }
165 }
166 } else {
167 let local_var_entity: Option<CreateConnectionError> =
168 serde_json::from_str(&local_var_content).ok();
169 let local_var_error = ResponseContent {
170 status: local_var_status,
171 content: local_var_content,
172 entity: local_var_entity,
173 };
174 Err(Error::ResponseError(local_var_error))
175 }
176 }
177
178 async fn delete_connection<'a>(
179 &self,
180 organization_connection_id: uuid::Uuid,
181 ) -> Result<(), Error<DeleteConnectionError>> {
182 let local_var_configuration = &self.configuration;
183
184 let local_var_client = &local_var_configuration.client;
185
186 let local_var_uri_str = format!(
187 "{}/organizations/connections/{organizationConnectionId}",
188 local_var_configuration.base_path,
189 organizationConnectionId = organization_connection_id
190 );
191 let mut local_var_req_builder =
192 local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
193
194 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
195
196 let local_var_resp = local_var_req_builder.send().await?;
197
198 let local_var_status = local_var_resp.status();
199 let local_var_content = local_var_resp.text().await?;
200
201 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
202 Ok(())
203 } else {
204 let local_var_entity: Option<DeleteConnectionError> =
205 serde_json::from_str(&local_var_content).ok();
206 let local_var_error = ResponseContent {
207 status: local_var_status,
208 content: local_var_content,
209 entity: local_var_entity,
210 };
211 Err(Error::ResponseError(local_var_error))
212 }
213 }
214
215 async fn get_connection<'a>(
216 &self,
217 organization_id: uuid::Uuid,
218 r#type: models::OrganizationConnectionType,
219 ) -> Result<models::OrganizationConnectionResponseModel, Error<GetConnectionError>> {
220 let local_var_configuration = &self.configuration;
221
222 let local_var_client = &local_var_configuration.client;
223
224 let local_var_uri_str = format!("{}/organizations/connections/{organizationId}/{type}", local_var_configuration.base_path, organizationId=organization_id, type=r#type.to_string());
225 let mut local_var_req_builder =
226 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
227
228 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
229
230 let local_var_resp = local_var_req_builder.send().await?;
231
232 let local_var_status = local_var_resp.status();
233 let local_var_content_type = local_var_resp
234 .headers()
235 .get("content-type")
236 .and_then(|v| v.to_str().ok())
237 .unwrap_or("application/octet-stream");
238 let local_var_content_type = super::ContentType::from(local_var_content_type);
239 let local_var_content = local_var_resp.text().await?;
240
241 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
242 match local_var_content_type {
243 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
244 ContentType::Text => {
245 return Err(Error::from(serde_json::Error::custom(
246 "Received `text/plain` content type response that cannot be converted to `models::OrganizationConnectionResponseModel`",
247 )));
248 }
249 ContentType::Unsupported(local_var_unknown_type) => {
250 return Err(Error::from(serde_json::Error::custom(format!(
251 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::OrganizationConnectionResponseModel`"
252 ))));
253 }
254 }
255 } else {
256 let local_var_entity: Option<GetConnectionError> =
257 serde_json::from_str(&local_var_content).ok();
258 let local_var_error = ResponseContent {
259 status: local_var_status,
260 content: local_var_content,
261 entity: local_var_entity,
262 };
263 Err(Error::ResponseError(local_var_error))
264 }
265 }
266
267 async fn update_connection<'a>(
268 &self,
269 organization_connection_id: uuid::Uuid,
270 organization_connection_request_model: Option<models::OrganizationConnectionRequestModel>,
271 ) -> Result<models::OrganizationConnectionResponseModel, Error<UpdateConnectionError>> {
272 let local_var_configuration = &self.configuration;
273
274 let local_var_client = &local_var_configuration.client;
275
276 let local_var_uri_str = format!(
277 "{}/organizations/connections/{organizationConnectionId}",
278 local_var_configuration.base_path,
279 organizationConnectionId = organization_connection_id
280 );
281 let mut local_var_req_builder =
282 local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
283
284 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
285 local_var_req_builder = local_var_req_builder.json(&organization_connection_request_model);
286
287 let local_var_resp = local_var_req_builder.send().await?;
288
289 let local_var_status = local_var_resp.status();
290 let local_var_content_type = local_var_resp
291 .headers()
292 .get("content-type")
293 .and_then(|v| v.to_str().ok())
294 .unwrap_or("application/octet-stream");
295 let local_var_content_type = super::ContentType::from(local_var_content_type);
296 let local_var_content = local_var_resp.text().await?;
297
298 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
299 match local_var_content_type {
300 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
301 ContentType::Text => {
302 return Err(Error::from(serde_json::Error::custom(
303 "Received `text/plain` content type response that cannot be converted to `models::OrganizationConnectionResponseModel`",
304 )));
305 }
306 ContentType::Unsupported(local_var_unknown_type) => {
307 return Err(Error::from(serde_json::Error::custom(format!(
308 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::OrganizationConnectionResponseModel`"
309 ))));
310 }
311 }
312 } else {
313 let local_var_entity: Option<UpdateConnectionError> =
314 serde_json::from_str(&local_var_content).ok();
315 let local_var_error = ResponseContent {
316 status: local_var_status,
317 content: local_var_content,
318 entity: local_var_entity,
319 };
320 Err(Error::ResponseError(local_var_error))
321 }
322 }
323}
324
325#[derive(Debug, Clone, Serialize, Deserialize)]
327#[serde(untagged)]
328pub enum ConnectionsEnabledError {
329 UnknownValue(serde_json::Value),
330}
331#[derive(Debug, Clone, Serialize, Deserialize)]
333#[serde(untagged)]
334pub enum CreateConnectionError {
335 UnknownValue(serde_json::Value),
336}
337#[derive(Debug, Clone, Serialize, Deserialize)]
339#[serde(untagged)]
340pub enum DeleteConnectionError {
341 UnknownValue(serde_json::Value),
342}
343#[derive(Debug, Clone, Serialize, Deserialize)]
345#[serde(untagged)]
346pub enum GetConnectionError {
347 UnknownValue(serde_json::Value),
348}
349#[derive(Debug, Clone, Serialize, Deserialize)]
351#[serde(untagged)]
352pub enum UpdateConnectionError {
353 UnknownValue(serde_json::Value),
354}