1#![allow(unused_imports)]
12
13use reqwest;
14
15use super::{configuration, Error};
16use crate::apis::ResponseContent;
17use crate::models::{self, *};
18
19#[derive(Debug, Clone, Serialize, Deserialize)]
21#[serde(untagged)]
22pub enum DeleteAttachmentError {
23 Status401(models::UnauthenticatedResponse),
24 Status404(models::NotFoundResponse),
25 Status400(models::BadRequestResponse),
26 Status500(models::InternalExceptionResponse),
27 UnknownValue(serde_json::Value),
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize)]
32#[serde(untagged)]
33pub enum DownloadAttachmentError {
34 Status401(models::UnauthenticatedResponse),
35 Status404(models::NotFoundResponse),
36 Status400(models::BadRequestResponse),
37 Status500(models::InternalExceptionResponse),
38 UnknownValue(serde_json::Value),
39}
40
41#[derive(Debug, Clone, Serialize, Deserialize)]
43#[serde(untagged)]
44pub enum GetAttachmentError {
45 Status401(models::UnauthenticatedResponse),
46 Status404(models::NotFoundResponse),
47 Status400(models::BadRequestResponse),
48 Status500(models::InternalExceptionResponse),
49 UnknownValue(serde_json::Value),
50}
51
52#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum ListAttachmentError {
56 Status401(models::UnauthenticatedResponse),
57 Status404(models::NotFoundResponse),
58 Status400(models::BadRequestResponse),
59 Status500(models::InternalExceptionResponse),
60 UnknownValue(serde_json::Value),
61}
62
63#[derive(Debug, Clone, Serialize, Deserialize)]
65#[serde(untagged)]
66pub enum StoreAttachmentError {
67 Status401(models::UnauthenticatedResponse),
68 Status404(models::NotFoundResponse),
69 Status400(models::BadRequestResponse),
70 Status500(models::InternalExceptionResponse),
71 Status422(models::ValidationErrorResponse),
72 UnknownValue(serde_json::Value),
73}
74
75#[derive(Debug, Clone, Serialize, Deserialize)]
77#[serde(untagged)]
78pub enum UpdateAttachmentError {
79 Status401(models::UnauthenticatedResponse),
80 Status404(models::NotFoundResponse),
81 Status400(models::BadRequestResponse),
82 Status500(models::InternalExceptionResponse),
83 Status422(models::ValidationErrorResponse),
84 UnknownValue(serde_json::Value),
85}
86
87#[derive(Debug, Clone, Serialize, Deserialize)]
89#[serde(untagged)]
90pub enum UploadAttachmentError {
91 Status401(models::UnauthenticatedResponse),
92 Status404(models::NotFoundResponse),
93 Status400(models::BadRequestResponse),
94 Status500(models::InternalExceptionResponse),
95 Status422(models::ValidationErrorResponse),
96 UnknownValue(serde_json::Value),
97}
98
99pub async fn delete_attachment(
101 configuration: &configuration::Configuration,
102 id: &str,
103 x_trace_id: Option<&str>,
104) -> Result<(), Error<DeleteAttachmentError>> {
105 let local_var_configuration = configuration;
106
107 let local_var_client = &local_var_configuration.client;
108
109 let local_var_uri_str = format!(
110 "{}/v1/attachments/{id}",
111 local_var_configuration.base_path,
112 id = crate::apis::urlencode(id)
113 );
114 let mut local_var_req_builder =
115 local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
116
117 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
118 local_var_req_builder =
119 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
120 }
121 if let Some(local_var_param_value) = x_trace_id {
122 local_var_req_builder =
123 local_var_req_builder.header("X-Trace-Id", local_var_param_value.to_string());
124 }
125 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
126 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
127 };
128 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
129 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
130 };
131
132 let local_var_req = local_var_req_builder.build()?;
133 let local_var_resp = local_var_client.execute(local_var_req).await?;
134
135 let local_var_status = local_var_resp.status();
136 let local_var_content = local_var_resp.text().await?;
137
138 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
139 Ok(())
140 } else {
141 let local_var_entity: Option<DeleteAttachmentError> =
142 serde_json::from_str(&local_var_content).ok();
143 let local_var_error = ResponseContent {
144 status: local_var_status,
145 content: local_var_content,
146 entity: local_var_entity,
147 };
148 Err(Error::ResponseError(local_var_error))
149 }
150}
151
152pub async fn download_attachment(
154 configuration: &configuration::Configuration,
155 id: &str,
156 x_trace_id: Option<&str>,
157) -> Result<std::path::PathBuf, Error<DownloadAttachmentError>> {
158 let local_var_configuration = configuration;
159
160 let local_var_client = &local_var_configuration.client;
161
162 let local_var_uri_str = format!(
163 "{}/v1/attachments/{id}/download",
164 local_var_configuration.base_path,
165 id = crate::apis::urlencode(id)
166 );
167 let mut local_var_req_builder =
168 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
169
170 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
171 local_var_req_builder =
172 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
173 }
174 if let Some(local_var_param_value) = x_trace_id {
175 local_var_req_builder =
176 local_var_req_builder.header("X-Trace-Id", local_var_param_value.to_string());
177 }
178 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
179 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
180 };
181 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
182 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
183 };
184
185 let local_var_req = local_var_req_builder.build()?;
186 let local_var_resp = local_var_client.execute(local_var_req).await?;
187
188 let local_var_status = local_var_resp.status();
189 let local_var_content = local_var_resp.text().await?;
190
191 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
192 serde_json::from_str(&local_var_content).map_err(Error::from)
193 } else {
194 let local_var_entity: Option<DownloadAttachmentError> =
195 serde_json::from_str(&local_var_content).ok();
196 let local_var_error = ResponseContent {
197 status: local_var_status,
198 content: local_var_content,
199 entity: local_var_entity,
200 };
201 Err(Error::ResponseError(local_var_error))
202 }
203}
204
205pub async fn get_attachment(
207 configuration: &configuration::Configuration,
208 id: &str,
209 x_trace_id: Option<&str>,
210) -> Result<models::AttachmentSingle, Error<GetAttachmentError>> {
211 let local_var_configuration = configuration;
212
213 let local_var_client = &local_var_configuration.client;
214
215 let local_var_uri_str = format!(
216 "{}/v1/attachments/{id}",
217 local_var_configuration.base_path,
218 id = crate::apis::urlencode(id)
219 );
220 let mut local_var_req_builder =
221 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
222
223 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
224 local_var_req_builder =
225 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
226 }
227 if let Some(local_var_param_value) = x_trace_id {
228 local_var_req_builder =
229 local_var_req_builder.header("X-Trace-Id", local_var_param_value.to_string());
230 }
231 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
232 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
233 };
234 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
235 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
236 };
237
238 let local_var_req = local_var_req_builder.build()?;
239 let local_var_resp = local_var_client.execute(local_var_req).await?;
240
241 let local_var_status = local_var_resp.status();
242 let local_var_content = local_var_resp.text().await?;
243
244 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
245 serde_json::from_str(&local_var_content).map_err(Error::from)
246 } else {
247 let local_var_entity: Option<GetAttachmentError> =
248 serde_json::from_str(&local_var_content).ok();
249 let local_var_error = ResponseContent {
250 status: local_var_status,
251 content: local_var_content,
252 entity: local_var_entity,
253 };
254 Err(Error::ResponseError(local_var_error))
255 }
256}
257
258pub async fn list_attachment(
260 configuration: &configuration::Configuration,
261 x_trace_id: Option<&str>,
262 limit: Option<i32>,
263 page: Option<i32>,
264) -> Result<models::AttachmentArray, Error<ListAttachmentError>> {
265 let local_var_configuration = configuration;
266
267 let local_var_client = &local_var_configuration.client;
268
269 let local_var_uri_str = format!("{}/v1/attachments", local_var_configuration.base_path);
270 let mut local_var_req_builder =
271 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
272
273 if let Some(ref local_var_str) = limit {
274 local_var_req_builder =
275 local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
276 }
277 if let Some(ref local_var_str) = page {
278 local_var_req_builder =
279 local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
280 }
281 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
282 local_var_req_builder =
283 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
284 }
285 if let Some(local_var_param_value) = x_trace_id {
286 local_var_req_builder =
287 local_var_req_builder.header("X-Trace-Id", local_var_param_value.to_string());
288 }
289 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
290 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
291 };
292 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
293 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
294 };
295
296 let local_var_req = local_var_req_builder.build()?;
297 let local_var_resp = local_var_client.execute(local_var_req).await?;
298
299 let local_var_status = local_var_resp.status();
300 let local_var_content = local_var_resp.text().await?;
301
302 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
303 serde_json::from_str(&local_var_content).map_err(Error::from)
304 } else {
305 let local_var_entity: Option<ListAttachmentError> =
306 serde_json::from_str(&local_var_content).ok();
307 let local_var_error = ResponseContent {
308 status: local_var_status,
309 content: local_var_content,
310 entity: local_var_entity,
311 };
312 Err(Error::ResponseError(local_var_error))
313 }
314}
315
316pub async fn store_attachment(
318 configuration: &configuration::Configuration,
319 attachment_store: AttachmentStore,
320 x_trace_id: Option<&str>,
321) -> Result<models::AttachmentSingle, Error<StoreAttachmentError>> {
322 let local_var_configuration = configuration;
323
324 let local_var_client = &local_var_configuration.client;
325
326 let local_var_uri_str = format!("{}/v1/attachments", local_var_configuration.base_path);
327 let mut local_var_req_builder =
328 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
329
330 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
331 local_var_req_builder =
332 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
333 }
334 if let Some(local_var_param_value) = x_trace_id {
335 local_var_req_builder =
336 local_var_req_builder.header("X-Trace-Id", local_var_param_value.to_string());
337 }
338 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
339 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
340 };
341 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
342 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
343 };
344 local_var_req_builder = local_var_req_builder.json(&attachment_store);
345
346 let local_var_req = local_var_req_builder.build()?;
347 let local_var_resp = local_var_client.execute(local_var_req).await?;
348
349 let local_var_status = local_var_resp.status();
350 let local_var_content = local_var_resp.text().await?;
351
352 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
353 serde_json::from_str(&local_var_content).map_err(Error::from)
354 } else {
355 let local_var_entity: Option<StoreAttachmentError> =
356 serde_json::from_str(&local_var_content).ok();
357 let local_var_error = ResponseContent {
358 status: local_var_status,
359 content: local_var_content,
360 entity: local_var_entity,
361 };
362 Err(Error::ResponseError(local_var_error))
363 }
364}
365
366pub async fn update_attachment(
368 configuration: &configuration::Configuration,
369 id: &str,
370 attachment_update: AttachmentUpdate,
371 x_trace_id: Option<&str>,
372) -> Result<models::AttachmentSingle, Error<UpdateAttachmentError>> {
373 let local_var_configuration = configuration;
374
375 let local_var_client = &local_var_configuration.client;
376
377 let local_var_uri_str = format!(
378 "{}/v1/attachments/{id}",
379 local_var_configuration.base_path,
380 id = crate::apis::urlencode(id)
381 );
382 let mut local_var_req_builder =
383 local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
384
385 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
386 local_var_req_builder =
387 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
388 }
389 if let Some(local_var_param_value) = x_trace_id {
390 local_var_req_builder =
391 local_var_req_builder.header("X-Trace-Id", local_var_param_value.to_string());
392 }
393 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
394 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
395 };
396 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
397 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
398 };
399 local_var_req_builder = local_var_req_builder.json(&attachment_update);
400
401 let local_var_req = local_var_req_builder.build()?;
402 let local_var_resp = local_var_client.execute(local_var_req).await?;
403
404 let local_var_status = local_var_resp.status();
405 let local_var_content = local_var_resp.text().await?;
406
407 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
408 serde_json::from_str(&local_var_content).map_err(Error::from)
409 } else {
410 let local_var_entity: Option<UpdateAttachmentError> =
411 serde_json::from_str(&local_var_content).ok();
412 let local_var_error = ResponseContent {
413 status: local_var_status,
414 content: local_var_content,
415 entity: local_var_entity,
416 };
417 Err(Error::ResponseError(local_var_error))
418 }
419}
420
421pub async fn upload_attachment(
423 configuration: &configuration::Configuration,
424 id: &str,
425 x_trace_id: Option<&str>,
426 body: Option<std::path::PathBuf>,
427) -> Result<(), Error<UploadAttachmentError>> {
428 let local_var_configuration = configuration;
429
430 let local_var_client = &local_var_configuration.client;
431
432 let local_var_uri_str = format!(
433 "{}/v1/attachments/{id}/upload",
434 local_var_configuration.base_path,
435 id = crate::apis::urlencode(id)
436 );
437 let mut local_var_req_builder =
438 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
439
440 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
441 local_var_req_builder =
442 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
443 }
444 if let Some(local_var_param_value) = x_trace_id {
445 local_var_req_builder =
446 local_var_req_builder.header("X-Trace-Id", local_var_param_value.to_string());
447 }
448 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
449 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
450 };
451 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
452 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
453 };
454 local_var_req_builder = local_var_req_builder.json(&body);
455
456 let local_var_req = local_var_req_builder.build()?;
457 let local_var_resp = local_var_client.execute(local_var_req).await?;
458
459 let local_var_status = local_var_resp.status();
460 let local_var_content = local_var_resp.text().await?;
461
462 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
463 Ok(())
464 } else {
465 let local_var_entity: Option<UploadAttachmentError> =
466 serde_json::from_str(&local_var_content).ok();
467 let local_var_error = ResponseContent {
468 status: local_var_status,
469 content: local_var_content,
470 entity: local_var_entity,
471 };
472 Err(Error::ResponseError(local_var_error))
473 }
474}