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 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 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
89 local_var_req_builder = local_var_req_builder.json(&organization_integration_request_model);
90
91 let local_var_resp = local_var_req_builder.send().await?;
92
93 let local_var_status = local_var_resp.status();
94 let local_var_content_type = local_var_resp
95 .headers()
96 .get("content-type")
97 .and_then(|v| v.to_str().ok())
98 .unwrap_or("application/octet-stream");
99 let local_var_content_type = super::ContentType::from(local_var_content_type);
100 let local_var_content = local_var_resp.text().await?;
101
102 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
103 match local_var_content_type {
104 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
105 ContentType::Text => {
106 return Err(Error::from(serde_json::Error::custom(
107 "Received `text/plain` content type response that cannot be converted to `models::OrganizationIntegrationResponseModel`",
108 )));
109 }
110 ContentType::Unsupported(local_var_unknown_type) => {
111 return Err(Error::from(serde_json::Error::custom(format!(
112 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::OrganizationIntegrationResponseModel`"
113 ))));
114 }
115 }
116 } else {
117 let local_var_entity: Option<CreateError> =
118 serde_json::from_str(&local_var_content).ok();
119 let local_var_error = ResponseContent {
120 status: local_var_status,
121 content: local_var_content,
122 entity: local_var_entity,
123 };
124 Err(Error::ResponseError(local_var_error))
125 }
126 }
127
128 async fn delete<'a>(
129 &self,
130 organization_id: uuid::Uuid,
131 integration_id: uuid::Uuid,
132 ) -> Result<(), Error<DeleteError>> {
133 let local_var_configuration = &self.configuration;
134
135 let local_var_client = &local_var_configuration.client;
136
137 let local_var_uri_str = format!(
138 "{}/organizations/{organizationId}/integrations/{integrationId}",
139 local_var_configuration.base_path,
140 organizationId = organization_id,
141 integrationId = integration_id
142 );
143 let mut local_var_req_builder =
144 local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
145
146 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
147
148 let local_var_resp = local_var_req_builder.send().await?;
149
150 let local_var_status = local_var_resp.status();
151 let local_var_content = local_var_resp.text().await?;
152
153 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
154 Ok(())
155 } else {
156 let local_var_entity: Option<DeleteError> =
157 serde_json::from_str(&local_var_content).ok();
158 let local_var_error = ResponseContent {
159 status: local_var_status,
160 content: local_var_content,
161 entity: local_var_entity,
162 };
163 Err(Error::ResponseError(local_var_error))
164 }
165 }
166
167 async fn get<'a>(
168 &self,
169 organization_id: uuid::Uuid,
170 ) -> Result<Vec<models::OrganizationIntegrationResponseModel>, Error<GetError>> {
171 let local_var_configuration = &self.configuration;
172
173 let local_var_client = &local_var_configuration.client;
174
175 let local_var_uri_str = format!(
176 "{}/organizations/{organizationId}/integrations",
177 local_var_configuration.base_path,
178 organizationId = organization_id
179 );
180 let mut local_var_req_builder =
181 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
182
183 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
184
185 let local_var_resp = local_var_req_builder.send().await?;
186
187 let local_var_status = local_var_resp.status();
188 let local_var_content_type = local_var_resp
189 .headers()
190 .get("content-type")
191 .and_then(|v| v.to_str().ok())
192 .unwrap_or("application/octet-stream");
193 let local_var_content_type = super::ContentType::from(local_var_content_type);
194 let local_var_content = local_var_resp.text().await?;
195
196 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
197 match local_var_content_type {
198 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
199 ContentType::Text => {
200 return Err(Error::from(serde_json::Error::custom(
201 "Received `text/plain` content type response that cannot be converted to `Vec<models::OrganizationIntegrationResponseModel>`",
202 )));
203 }
204 ContentType::Unsupported(local_var_unknown_type) => {
205 return Err(Error::from(serde_json::Error::custom(format!(
206 "Received `{local_var_unknown_type}` content type response that cannot be converted to `Vec<models::OrganizationIntegrationResponseModel>`"
207 ))));
208 }
209 }
210 } else {
211 let local_var_entity: Option<GetError> = serde_json::from_str(&local_var_content).ok();
212 let local_var_error = ResponseContent {
213 status: local_var_status,
214 content: local_var_content,
215 entity: local_var_entity,
216 };
217 Err(Error::ResponseError(local_var_error))
218 }
219 }
220
221 async fn update<'a>(
222 &self,
223 organization_id: uuid::Uuid,
224 integration_id: uuid::Uuid,
225 organization_integration_request_model: Option<models::OrganizationIntegrationRequestModel>,
226 ) -> Result<models::OrganizationIntegrationResponseModel, Error<UpdateError>> {
227 let local_var_configuration = &self.configuration;
228
229 let local_var_client = &local_var_configuration.client;
230
231 let local_var_uri_str = format!(
232 "{}/organizations/{organizationId}/integrations/{integrationId}",
233 local_var_configuration.base_path,
234 organizationId = organization_id,
235 integrationId = integration_id
236 );
237 let mut local_var_req_builder =
238 local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
239
240 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
241 local_var_req_builder = local_var_req_builder.json(&organization_integration_request_model);
242
243 let local_var_resp = local_var_req_builder.send().await?;
244
245 let local_var_status = local_var_resp.status();
246 let local_var_content_type = local_var_resp
247 .headers()
248 .get("content-type")
249 .and_then(|v| v.to_str().ok())
250 .unwrap_or("application/octet-stream");
251 let local_var_content_type = super::ContentType::from(local_var_content_type);
252 let local_var_content = local_var_resp.text().await?;
253
254 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
255 match local_var_content_type {
256 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
257 ContentType::Text => {
258 return Err(Error::from(serde_json::Error::custom(
259 "Received `text/plain` content type response that cannot be converted to `models::OrganizationIntegrationResponseModel`",
260 )));
261 }
262 ContentType::Unsupported(local_var_unknown_type) => {
263 return Err(Error::from(serde_json::Error::custom(format!(
264 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::OrganizationIntegrationResponseModel`"
265 ))));
266 }
267 }
268 } else {
269 let local_var_entity: Option<UpdateError> =
270 serde_json::from_str(&local_var_content).ok();
271 let local_var_error = ResponseContent {
272 status: local_var_status,
273 content: local_var_content,
274 entity: local_var_entity,
275 };
276 Err(Error::ResponseError(local_var_error))
277 }
278 }
279}
280
281#[derive(Debug, Clone, Serialize, Deserialize)]
283#[serde(untagged)]
284pub enum CreateError {
285 UnknownValue(serde_json::Value),
286}
287#[derive(Debug, Clone, Serialize, Deserialize)]
289#[serde(untagged)]
290pub enum DeleteError {
291 UnknownValue(serde_json::Value),
292}
293#[derive(Debug, Clone, Serialize, Deserialize)]
295#[serde(untagged)]
296pub enum GetError {
297 UnknownValue(serde_json::Value),
298}
299#[derive(Debug, Clone, Serialize, Deserialize)]
301#[serde(untagged)]
302pub enum UpdateError {
303 UnknownValue(serde_json::Value),
304}