1use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17#[derive(Clone, Debug, Default)]
19pub struct AddAttachmentParams {
20 pub issue_id_or_key: String
22}
23
24#[derive(Clone, Debug, Default)]
26pub struct ExpandAttachmentForHumansParams {
27 pub id: String
29}
30
31#[derive(Clone, Debug, Default)]
33pub struct ExpandAttachmentForMachinesParams {
34 pub id: String
36}
37
38#[derive(Clone, Debug, Default)]
40pub struct GetAttachmentParams {
41 pub id: String
43}
44
45#[derive(Clone, Debug, Default)]
47pub struct GetAttachmentContentParams {
48 pub id: String,
50 pub redirect: Option<bool>
52}
53
54#[derive(Clone, Debug, Default)]
56pub struct GetAttachmentThumbnailParams {
57 pub id: String,
59 pub redirect: Option<bool>,
61 pub fallback_to_default: Option<bool>,
63 pub width: Option<i32>,
65 pub height: Option<i32>
67}
68
69#[derive(Clone, Debug, Default)]
71pub struct RemoveAttachmentParams {
72 pub id: String
74}
75
76
77#[derive(Debug, Clone, Serialize, Deserialize)]
79#[serde(untagged)]
80pub enum AddAttachmentSuccess {
81 Status200(Vec<crate::models::Attachment>),
82 UnknownValue(serde_json::Value),
83}
84
85#[derive(Debug, Clone, Serialize, Deserialize)]
87#[serde(untagged)]
88pub enum ExpandAttachmentForHumansSuccess {
89 Status200(crate::models::AttachmentArchiveMetadataReadable),
90 UnknownValue(serde_json::Value),
91}
92
93#[derive(Debug, Clone, Serialize, Deserialize)]
95#[serde(untagged)]
96pub enum ExpandAttachmentForMachinesSuccess {
97 Status200(crate::models::AttachmentArchiveImpl),
98 UnknownValue(serde_json::Value),
99}
100
101#[derive(Debug, Clone, Serialize, Deserialize)]
103#[serde(untagged)]
104pub enum GetAttachmentSuccess {
105 Status200(crate::models::AttachmentMetadata),
106 UnknownValue(serde_json::Value),
107}
108
109#[derive(Debug, Clone, Serialize, Deserialize)]
111#[serde(untagged)]
112pub enum GetAttachmentContentSuccess {
113 Status200(serde_json::Value),
114 Status206(),
115 Status303(),
116 UnknownValue(serde_json::Value),
117}
118
119#[derive(Debug, Clone, Serialize, Deserialize)]
121#[serde(untagged)]
122pub enum GetAttachmentMetaSuccess {
123 Status200(crate::models::AttachmentSettings),
124 UnknownValue(serde_json::Value),
125}
126
127#[derive(Debug, Clone, Serialize, Deserialize)]
129#[serde(untagged)]
130pub enum GetAttachmentThumbnailSuccess {
131 Status200(serde_json::Value),
132 Status303(),
133 UnknownValue(serde_json::Value),
134}
135
136#[derive(Debug, Clone, Serialize, Deserialize)]
138#[serde(untagged)]
139pub enum RemoveAttachmentSuccess {
140 Status204(),
141 UnknownValue(serde_json::Value),
142}
143
144#[derive(Debug, Clone, Serialize, Deserialize)]
146#[serde(untagged)]
147pub enum AddAttachmentError {
148 Status403(),
149 Status404(),
150 Status413(),
151 UnknownValue(serde_json::Value),
152}
153
154#[derive(Debug, Clone, Serialize, Deserialize)]
156#[serde(untagged)]
157pub enum ExpandAttachmentForHumansError {
158 Status401(),
159 Status403(),
160 Status404(),
161 Status409(),
162 UnknownValue(serde_json::Value),
163}
164
165#[derive(Debug, Clone, Serialize, Deserialize)]
167#[serde(untagged)]
168pub enum ExpandAttachmentForMachinesError {
169 Status401(),
170 Status403(),
171 Status404(),
172 Status409(),
173 UnknownValue(serde_json::Value),
174}
175
176#[derive(Debug, Clone, Serialize, Deserialize)]
178#[serde(untagged)]
179pub enum GetAttachmentError {
180 Status401(),
181 Status403(),
182 Status404(),
183 UnknownValue(serde_json::Value),
184}
185
186#[derive(Debug, Clone, Serialize, Deserialize)]
188#[serde(untagged)]
189pub enum GetAttachmentContentError {
190 Status400(),
191 Status401(),
192 Status403(),
193 Status404(),
194 Status416(),
195 UnknownValue(serde_json::Value),
196}
197
198#[derive(Debug, Clone, Serialize, Deserialize)]
200#[serde(untagged)]
201pub enum GetAttachmentMetaError {
202 Status401(),
203 UnknownValue(serde_json::Value),
204}
205
206#[derive(Debug, Clone, Serialize, Deserialize)]
208#[serde(untagged)]
209pub enum GetAttachmentThumbnailError {
210 Status400(),
211 Status401(),
212 Status403(),
213 Status404(),
214 UnknownValue(serde_json::Value),
215}
216
217#[derive(Debug, Clone, Serialize, Deserialize)]
219#[serde(untagged)]
220pub enum RemoveAttachmentError {
221 Status403(),
222 Status404(),
223 UnknownValue(serde_json::Value),
224}
225
226
227pub async fn add_attachment(configuration: &configuration::Configuration, params: AddAttachmentParams) -> Result<ResponseContent<AddAttachmentSuccess>, Error<AddAttachmentError>> {
229 let local_var_configuration = configuration;
230
231 let issue_id_or_key = params.issue_id_or_key;
233
234
235 let local_var_client = &local_var_configuration.client;
236
237 let local_var_uri_str = format!("{}/rest/api/2/issue/{issueIdOrKey}/attachments", local_var_configuration.base_path, issueIdOrKey=crate::apis::urlencode(issue_id_or_key));
238 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
239
240 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
241 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
242 }
243 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
244 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
245 };
246 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
247 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
248 };
249
250 let local_var_req = local_var_req_builder.build()?;
251 let local_var_resp = local_var_client.execute(local_var_req).await?;
252
253 let local_var_status = local_var_resp.status();
254 let local_var_content = local_var_resp.text().await?;
255
256 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
257 let local_var_entity: Option<AddAttachmentSuccess> = serde_json::from_str(&local_var_content).ok();
258 let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
259 Ok(local_var_result)
260 } else {
261 let local_var_entity: Option<AddAttachmentError> = serde_json::from_str(&local_var_content).ok();
262 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
263 Err(Error::ResponseError(local_var_error))
264 }
265}
266
267pub async fn expand_attachment_for_humans(configuration: &configuration::Configuration, params: ExpandAttachmentForHumansParams) -> Result<ResponseContent<ExpandAttachmentForHumansSuccess>, Error<ExpandAttachmentForHumansError>> {
269 let local_var_configuration = configuration;
270
271 let id = params.id;
273
274
275 let local_var_client = &local_var_configuration.client;
276
277 let local_var_uri_str = format!("{}/rest/api/2/attachment/{id}/expand/human", local_var_configuration.base_path, id=crate::apis::urlencode(id));
278 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
279
280 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
281 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
282 }
283 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
284 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
285 };
286 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
287 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
288 };
289
290 let local_var_req = local_var_req_builder.build()?;
291 let local_var_resp = local_var_client.execute(local_var_req).await?;
292
293 let local_var_status = local_var_resp.status();
294 let local_var_content = local_var_resp.text().await?;
295
296 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
297 let local_var_entity: Option<ExpandAttachmentForHumansSuccess> = serde_json::from_str(&local_var_content).ok();
298 let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
299 Ok(local_var_result)
300 } else {
301 let local_var_entity: Option<ExpandAttachmentForHumansError> = serde_json::from_str(&local_var_content).ok();
302 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
303 Err(Error::ResponseError(local_var_error))
304 }
305}
306
307pub async fn expand_attachment_for_machines(configuration: &configuration::Configuration, params: ExpandAttachmentForMachinesParams) -> Result<ResponseContent<ExpandAttachmentForMachinesSuccess>, Error<ExpandAttachmentForMachinesError>> {
309 let local_var_configuration = configuration;
310
311 let id = params.id;
313
314
315 let local_var_client = &local_var_configuration.client;
316
317 let local_var_uri_str = format!("{}/rest/api/2/attachment/{id}/expand/raw", local_var_configuration.base_path, id=crate::apis::urlencode(id));
318 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
319
320 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
321 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
322 }
323 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
324 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
325 };
326 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
327 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
328 };
329
330 let local_var_req = local_var_req_builder.build()?;
331 let local_var_resp = local_var_client.execute(local_var_req).await?;
332
333 let local_var_status = local_var_resp.status();
334 let local_var_content = local_var_resp.text().await?;
335
336 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
337 let local_var_entity: Option<ExpandAttachmentForMachinesSuccess> = serde_json::from_str(&local_var_content).ok();
338 let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
339 Ok(local_var_result)
340 } else {
341 let local_var_entity: Option<ExpandAttachmentForMachinesError> = serde_json::from_str(&local_var_content).ok();
342 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
343 Err(Error::ResponseError(local_var_error))
344 }
345}
346
347pub async fn get_attachment(configuration: &configuration::Configuration, params: GetAttachmentParams) -> Result<ResponseContent<GetAttachmentSuccess>, Error<GetAttachmentError>> {
349 let local_var_configuration = configuration;
350
351 let id = params.id;
353
354
355 let local_var_client = &local_var_configuration.client;
356
357 let local_var_uri_str = format!("{}/rest/api/2/attachment/{id}", local_var_configuration.base_path, id=crate::apis::urlencode(id));
358 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
359
360 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
361 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
362 }
363 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
364 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
365 };
366 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
367 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
368 };
369
370 let local_var_req = local_var_req_builder.build()?;
371 let local_var_resp = local_var_client.execute(local_var_req).await?;
372
373 let local_var_status = local_var_resp.status();
374 let local_var_content = local_var_resp.text().await?;
375
376 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
377 let local_var_entity: Option<GetAttachmentSuccess> = serde_json::from_str(&local_var_content).ok();
378 let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
379 Ok(local_var_result)
380 } else {
381 let local_var_entity: Option<GetAttachmentError> = serde_json::from_str(&local_var_content).ok();
382 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
383 Err(Error::ResponseError(local_var_error))
384 }
385}
386
387pub async fn get_attachment_content(configuration: &configuration::Configuration, params: GetAttachmentContentParams) -> Result<ResponseContent<GetAttachmentContentSuccess>, Error<GetAttachmentContentError>> {
389 let local_var_configuration = configuration;
390
391 let id = params.id;
393 let redirect = params.redirect;
394
395
396 let local_var_client = &local_var_configuration.client;
397
398 let local_var_uri_str = format!("{}/rest/api/2/attachment/content/{id}", local_var_configuration.base_path, id=crate::apis::urlencode(id));
399 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
400
401 if let Some(ref local_var_str) = redirect {
402 local_var_req_builder = local_var_req_builder.query(&[("redirect", &local_var_str.to_string())]);
403 }
404 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
405 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
406 }
407 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
408 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
409 };
410 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
411 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
412 };
413
414 let local_var_req = local_var_req_builder.build()?;
415 let local_var_resp = local_var_client.execute(local_var_req).await?;
416
417 let local_var_status = local_var_resp.status();
418 let local_var_content = local_var_resp.text().await?;
419
420 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
421 let local_var_entity: Option<GetAttachmentContentSuccess> = serde_json::from_str(&local_var_content).ok();
422 let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
423 Ok(local_var_result)
424 } else {
425 let local_var_entity: Option<GetAttachmentContentError> = serde_json::from_str(&local_var_content).ok();
426 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
427 Err(Error::ResponseError(local_var_error))
428 }
429}
430
431pub async fn get_attachment_meta(configuration: &configuration::Configuration) -> Result<ResponseContent<GetAttachmentMetaSuccess>, Error<GetAttachmentMetaError>> {
433 let local_var_configuration = configuration;
434
435 let local_var_client = &local_var_configuration.client;
439
440 let local_var_uri_str = format!("{}/rest/api/2/attachment/meta", local_var_configuration.base_path);
441 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
442
443 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
444 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
445 }
446 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
447 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
448 };
449 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
450 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
451 };
452
453 let local_var_req = local_var_req_builder.build()?;
454 let local_var_resp = local_var_client.execute(local_var_req).await?;
455
456 let local_var_status = local_var_resp.status();
457 let local_var_content = local_var_resp.text().await?;
458
459 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
460 let local_var_entity: Option<GetAttachmentMetaSuccess> = serde_json::from_str(&local_var_content).ok();
461 let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
462 Ok(local_var_result)
463 } else {
464 let local_var_entity: Option<GetAttachmentMetaError> = serde_json::from_str(&local_var_content).ok();
465 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
466 Err(Error::ResponseError(local_var_error))
467 }
468}
469
470pub async fn get_attachment_thumbnail(configuration: &configuration::Configuration, params: GetAttachmentThumbnailParams) -> Result<ResponseContent<GetAttachmentThumbnailSuccess>, Error<GetAttachmentThumbnailError>> {
472 let local_var_configuration = configuration;
473
474 let id = params.id;
476 let redirect = params.redirect;
477 let fallback_to_default = params.fallback_to_default;
478 let width = params.width;
479 let height = params.height;
480
481
482 let local_var_client = &local_var_configuration.client;
483
484 let local_var_uri_str = format!("{}/rest/api/2/attachment/thumbnail/{id}", local_var_configuration.base_path, id=crate::apis::urlencode(id));
485 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
486
487 if let Some(ref local_var_str) = redirect {
488 local_var_req_builder = local_var_req_builder.query(&[("redirect", &local_var_str.to_string())]);
489 }
490 if let Some(ref local_var_str) = fallback_to_default {
491 local_var_req_builder = local_var_req_builder.query(&[("fallbackToDefault", &local_var_str.to_string())]);
492 }
493 if let Some(ref local_var_str) = width {
494 local_var_req_builder = local_var_req_builder.query(&[("width", &local_var_str.to_string())]);
495 }
496 if let Some(ref local_var_str) = height {
497 local_var_req_builder = local_var_req_builder.query(&[("height", &local_var_str.to_string())]);
498 }
499 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
500 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
501 }
502 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
503 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
504 };
505 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
506 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
507 };
508
509 let local_var_req = local_var_req_builder.build()?;
510 let local_var_resp = local_var_client.execute(local_var_req).await?;
511
512 let local_var_status = local_var_resp.status();
513 let local_var_content = local_var_resp.text().await?;
514
515 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
516 let local_var_entity: Option<GetAttachmentThumbnailSuccess> = serde_json::from_str(&local_var_content).ok();
517 let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
518 Ok(local_var_result)
519 } else {
520 let local_var_entity: Option<GetAttachmentThumbnailError> = serde_json::from_str(&local_var_content).ok();
521 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
522 Err(Error::ResponseError(local_var_error))
523 }
524}
525
526pub async fn remove_attachment(configuration: &configuration::Configuration, params: RemoveAttachmentParams) -> Result<ResponseContent<RemoveAttachmentSuccess>, Error<RemoveAttachmentError>> {
528 let local_var_configuration = configuration;
529
530 let id = params.id;
532
533
534 let local_var_client = &local_var_configuration.client;
535
536 let local_var_uri_str = format!("{}/rest/api/2/attachment/{id}", local_var_configuration.base_path, id=crate::apis::urlencode(id));
537 let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
538
539 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
540 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
541 }
542 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
543 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
544 };
545 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
546 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
547 };
548
549 let local_var_req = local_var_req_builder.build()?;
550 let local_var_resp = local_var_client.execute(local_var_req).await?;
551
552 let local_var_status = local_var_resp.status();
553 let local_var_content = local_var_resp.text().await?;
554
555 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
556 let local_var_entity: Option<RemoveAttachmentSuccess> = serde_json::from_str(&local_var_content).ok();
557 let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
558 Ok(local_var_result)
559 } else {
560 let local_var_entity: Option<RemoveAttachmentError> = serde_json::from_str(&local_var_content).ok();
561 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
562 Err(Error::ResponseError(local_var_error))
563 }
564}
565