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