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 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
85 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
86 };
87 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
88
89 let local_var_req = local_var_req_builder.build()?;
90 let local_var_resp = local_var_client.execute(local_var_req).await?;
91
92 let local_var_status = local_var_resp.status();
93 let local_var_content_type = local_var_resp
94 .headers()
95 .get("content-type")
96 .and_then(|v| v.to_str().ok())
97 .unwrap_or("application/octet-stream");
98 let local_var_content_type = super::ContentType::from(local_var_content_type);
99 let local_var_content = local_var_resp.text().await?;
100
101 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
102 match local_var_content_type {
103 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
104 ContentType::Text => {
105 return Err(Error::from(serde_json::Error::custom(
106 "Received `text/plain` content type response that cannot be converted to `bool`",
107 )));
108 }
109 ContentType::Unsupported(local_var_unknown_type) => {
110 return Err(Error::from(serde_json::Error::custom(format!(
111 "Received `{local_var_unknown_type}` content type response that cannot be converted to `bool`"
112 ))));
113 }
114 }
115 } else {
116 let local_var_entity: Option<ConnectionsEnabledError> =
117 serde_json::from_str(&local_var_content).ok();
118 let local_var_error = ResponseContent {
119 status: local_var_status,
120 content: local_var_content,
121 entity: local_var_entity,
122 };
123 Err(Error::ResponseError(local_var_error))
124 }
125 }
126
127 async fn create_connection<'a>(
128 &self,
129 organization_connection_request_model: Option<models::OrganizationConnectionRequestModel>,
130 ) -> Result<models::OrganizationConnectionResponseModel, Error<CreateConnectionError>> {
131 let local_var_configuration = &self.configuration;
132
133 let local_var_client = &local_var_configuration.client;
134
135 let local_var_uri_str = format!(
136 "{}/organizations/connections",
137 local_var_configuration.base_path
138 );
139 let mut local_var_req_builder =
140 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
141
142 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
143 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
144 };
145 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
146 local_var_req_builder = local_var_req_builder.json(&organization_connection_request_model);
147
148 let local_var_req = local_var_req_builder.build()?;
149 let local_var_resp = local_var_client.execute(local_var_req).await?;
150
151 let local_var_status = local_var_resp.status();
152 let local_var_content_type = local_var_resp
153 .headers()
154 .get("content-type")
155 .and_then(|v| v.to_str().ok())
156 .unwrap_or("application/octet-stream");
157 let local_var_content_type = super::ContentType::from(local_var_content_type);
158 let local_var_content = local_var_resp.text().await?;
159
160 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
161 match local_var_content_type {
162 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
163 ContentType::Text => {
164 return Err(Error::from(serde_json::Error::custom(
165 "Received `text/plain` content type response that cannot be converted to `models::OrganizationConnectionResponseModel`",
166 )));
167 }
168 ContentType::Unsupported(local_var_unknown_type) => {
169 return Err(Error::from(serde_json::Error::custom(format!(
170 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::OrganizationConnectionResponseModel`"
171 ))));
172 }
173 }
174 } else {
175 let local_var_entity: Option<CreateConnectionError> =
176 serde_json::from_str(&local_var_content).ok();
177 let local_var_error = ResponseContent {
178 status: local_var_status,
179 content: local_var_content,
180 entity: local_var_entity,
181 };
182 Err(Error::ResponseError(local_var_error))
183 }
184 }
185
186 async fn delete_connection<'a>(
187 &self,
188 organization_connection_id: uuid::Uuid,
189 ) -> Result<(), Error<DeleteConnectionError>> {
190 let local_var_configuration = &self.configuration;
191
192 let local_var_client = &local_var_configuration.client;
193
194 let local_var_uri_str = format!(
195 "{}/organizations/connections/{organizationConnectionId}",
196 local_var_configuration.base_path,
197 organizationConnectionId = organization_connection_id
198 );
199 let mut local_var_req_builder =
200 local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
201
202 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
203 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
204 };
205 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
206
207 let local_var_req = local_var_req_builder.build()?;
208 let local_var_resp = local_var_client.execute(local_var_req).await?;
209
210 let local_var_status = local_var_resp.status();
211 let local_var_content = local_var_resp.text().await?;
212
213 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
214 Ok(())
215 } else {
216 let local_var_entity: Option<DeleteConnectionError> =
217 serde_json::from_str(&local_var_content).ok();
218 let local_var_error = ResponseContent {
219 status: local_var_status,
220 content: local_var_content,
221 entity: local_var_entity,
222 };
223 Err(Error::ResponseError(local_var_error))
224 }
225 }
226
227 async fn get_connection<'a>(
228 &self,
229 organization_id: uuid::Uuid,
230 r#type: models::OrganizationConnectionType,
231 ) -> Result<models::OrganizationConnectionResponseModel, Error<GetConnectionError>> {
232 let local_var_configuration = &self.configuration;
233
234 let local_var_client = &local_var_configuration.client;
235
236 let local_var_uri_str = format!("{}/organizations/connections/{organizationId}/{type}", local_var_configuration.base_path, organizationId=organization_id, type=r#type.to_string());
237 let mut local_var_req_builder =
238 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
239
240 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
241 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
242 };
243 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
244
245 let local_var_req = local_var_req_builder.build()?;
246 let local_var_resp = local_var_client.execute(local_var_req).await?;
247
248 let local_var_status = local_var_resp.status();
249 let local_var_content_type = local_var_resp
250 .headers()
251 .get("content-type")
252 .and_then(|v| v.to_str().ok())
253 .unwrap_or("application/octet-stream");
254 let local_var_content_type = super::ContentType::from(local_var_content_type);
255 let local_var_content = local_var_resp.text().await?;
256
257 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
258 match local_var_content_type {
259 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
260 ContentType::Text => {
261 return Err(Error::from(serde_json::Error::custom(
262 "Received `text/plain` content type response that cannot be converted to `models::OrganizationConnectionResponseModel`",
263 )));
264 }
265 ContentType::Unsupported(local_var_unknown_type) => {
266 return Err(Error::from(serde_json::Error::custom(format!(
267 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::OrganizationConnectionResponseModel`"
268 ))));
269 }
270 }
271 } else {
272 let local_var_entity: Option<GetConnectionError> =
273 serde_json::from_str(&local_var_content).ok();
274 let local_var_error = ResponseContent {
275 status: local_var_status,
276 content: local_var_content,
277 entity: local_var_entity,
278 };
279 Err(Error::ResponseError(local_var_error))
280 }
281 }
282
283 async fn update_connection<'a>(
284 &self,
285 organization_connection_id: uuid::Uuid,
286 organization_connection_request_model: Option<models::OrganizationConnectionRequestModel>,
287 ) -> Result<models::OrganizationConnectionResponseModel, Error<UpdateConnectionError>> {
288 let local_var_configuration = &self.configuration;
289
290 let local_var_client = &local_var_configuration.client;
291
292 let local_var_uri_str = format!(
293 "{}/organizations/connections/{organizationConnectionId}",
294 local_var_configuration.base_path,
295 organizationConnectionId = organization_connection_id
296 );
297 let mut local_var_req_builder =
298 local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
299
300 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
301 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
302 };
303 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
304 local_var_req_builder = local_var_req_builder.json(&organization_connection_request_model);
305
306 let local_var_req = local_var_req_builder.build()?;
307 let local_var_resp = local_var_client.execute(local_var_req).await?;
308
309 let local_var_status = local_var_resp.status();
310 let local_var_content_type = local_var_resp
311 .headers()
312 .get("content-type")
313 .and_then(|v| v.to_str().ok())
314 .unwrap_or("application/octet-stream");
315 let local_var_content_type = super::ContentType::from(local_var_content_type);
316 let local_var_content = local_var_resp.text().await?;
317
318 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
319 match local_var_content_type {
320 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
321 ContentType::Text => {
322 return Err(Error::from(serde_json::Error::custom(
323 "Received `text/plain` content type response that cannot be converted to `models::OrganizationConnectionResponseModel`",
324 )));
325 }
326 ContentType::Unsupported(local_var_unknown_type) => {
327 return Err(Error::from(serde_json::Error::custom(format!(
328 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::OrganizationConnectionResponseModel`"
329 ))));
330 }
331 }
332 } else {
333 let local_var_entity: Option<UpdateConnectionError> =
334 serde_json::from_str(&local_var_content).ok();
335 let local_var_error = ResponseContent {
336 status: local_var_status,
337 content: local_var_content,
338 entity: local_var_entity,
339 };
340 Err(Error::ResponseError(local_var_error))
341 }
342 }
343}
344
345#[derive(Debug, Clone, Serialize, Deserialize)]
347#[serde(untagged)]
348pub enum ConnectionsEnabledError {
349 UnknownValue(serde_json::Value),
350}
351#[derive(Debug, Clone, Serialize, Deserialize)]
353#[serde(untagged)]
354pub enum CreateConnectionError {
355 UnknownValue(serde_json::Value),
356}
357#[derive(Debug, Clone, Serialize, Deserialize)]
359#[serde(untagged)]
360pub enum DeleteConnectionError {
361 UnknownValue(serde_json::Value),
362}
363#[derive(Debug, Clone, Serialize, Deserialize)]
365#[serde(untagged)]
366pub enum GetConnectionError {
367 UnknownValue(serde_json::Value),
368}
369#[derive(Debug, Clone, Serialize, Deserialize)]
371#[serde(untagged)]
372pub enum UpdateConnectionError {
373 UnknownValue(serde_json::Value),
374}