1use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AddAttachmentError {
22 Status403(),
23 Status404(),
24 Status413(),
25 UnknownValue(serde_json::Value),
26}
27
28#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum ExpandAttachmentForHumansError {
32 Status401(),
33 Status403(),
34 Status404(),
35 Status409(),
36 UnknownValue(serde_json::Value),
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum ExpandAttachmentForMachinesError {
43 Status401(),
44 Status403(),
45 Status404(),
46 Status409(),
47 UnknownValue(serde_json::Value),
48}
49
50#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum GetAttachmentError {
54 Status401(),
55 Status403(),
56 Status404(),
57 UnknownValue(serde_json::Value),
58}
59
60#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum GetAttachmentMetaError {
64 Status401(),
65 UnknownValue(serde_json::Value),
66}
67
68#[derive(Debug, Clone, Serialize, Deserialize)]
70#[serde(untagged)]
71pub enum RemoveAttachmentError {
72 Status403(),
73 Status404(),
74 UnknownValue(serde_json::Value),
75}
76
77
78pub async fn add_attachment(configuration: &configuration::Configuration, issue_id_or_key: &str) -> Result<Vec<models::Attachment>, Error<AddAttachmentError>> {
80 let p_issue_id_or_key = issue_id_or_key;
82
83 let uri_str = format!("{}/rest/api/2/issue/{issueIdOrKey}/attachments", configuration.base_path, issueIdOrKey=crate::apis::urlencode(p_issue_id_or_key));
84 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
85
86 if let Some(ref user_agent) = configuration.user_agent {
87 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
88 }
89 if let Some(ref token) = configuration.oauth_access_token {
90 req_builder = req_builder.bearer_auth(token.to_owned());
91 };
92 if let Some(ref auth_conf) = configuration.basic_auth {
93 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
94 };
95
96 let req = req_builder.build()?;
97 let resp = configuration.client.execute(req).await?;
98
99 let status = resp.status();
100
101 if !status.is_client_error() && !status.is_server_error() {
102 let content = resp.text().await?;
103 serde_json::from_str(&content).map_err(Error::from)
104 } else {
105 let content = resp.text().await?;
106 let entity: Option<AddAttachmentError> = serde_json::from_str(&content).ok();
107 Err(Error::ResponseError(ResponseContent { status, content, entity }))
108 }
109}
110
111pub async fn expand_attachment_for_humans(configuration: &configuration::Configuration, id: &str) -> Result<models::AttachmentArchiveMetadataReadable, Error<ExpandAttachmentForHumansError>> {
113 let p_id = id;
115
116 let uri_str = format!("{}/rest/api/2/attachment/{id}/expand/human", configuration.base_path, id=crate::apis::urlencode(p_id));
117 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
118
119 if let Some(ref user_agent) = configuration.user_agent {
120 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
121 }
122 if let Some(ref token) = configuration.oauth_access_token {
123 req_builder = req_builder.bearer_auth(token.to_owned());
124 };
125 if let Some(ref auth_conf) = configuration.basic_auth {
126 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
127 };
128
129 let req = req_builder.build()?;
130 let resp = configuration.client.execute(req).await?;
131
132 let status = resp.status();
133
134 if !status.is_client_error() && !status.is_server_error() {
135 let content = resp.text().await?;
136 serde_json::from_str(&content).map_err(Error::from)
137 } else {
138 let content = resp.text().await?;
139 let entity: Option<ExpandAttachmentForHumansError> = serde_json::from_str(&content).ok();
140 Err(Error::ResponseError(ResponseContent { status, content, entity }))
141 }
142}
143
144pub async fn expand_attachment_for_machines(configuration: &configuration::Configuration, id: &str) -> Result<models::AttachmentArchiveImpl, Error<ExpandAttachmentForMachinesError>> {
146 let p_id = id;
148
149 let uri_str = format!("{}/rest/api/2/attachment/{id}/expand/raw", configuration.base_path, id=crate::apis::urlencode(p_id));
150 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
151
152 if let Some(ref user_agent) = configuration.user_agent {
153 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
154 }
155 if let Some(ref token) = configuration.oauth_access_token {
156 req_builder = req_builder.bearer_auth(token.to_owned());
157 };
158 if let Some(ref auth_conf) = configuration.basic_auth {
159 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
160 };
161
162 let req = req_builder.build()?;
163 let resp = configuration.client.execute(req).await?;
164
165 let status = resp.status();
166
167 if !status.is_client_error() && !status.is_server_error() {
168 let content = resp.text().await?;
169 serde_json::from_str(&content).map_err(Error::from)
170 } else {
171 let content = resp.text().await?;
172 let entity: Option<ExpandAttachmentForMachinesError> = serde_json::from_str(&content).ok();
173 Err(Error::ResponseError(ResponseContent { status, content, entity }))
174 }
175}
176
177pub async fn get_attachment(configuration: &configuration::Configuration, id: &str) -> Result<models::AttachmentMetadata, Error<GetAttachmentError>> {
179 let p_id = id;
181
182 let uri_str = format!("{}/rest/api/2/attachment/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
183 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
184
185 if let Some(ref user_agent) = configuration.user_agent {
186 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
187 }
188 if let Some(ref token) = configuration.oauth_access_token {
189 req_builder = req_builder.bearer_auth(token.to_owned());
190 };
191 if let Some(ref auth_conf) = configuration.basic_auth {
192 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
193 };
194
195 let req = req_builder.build()?;
196 let resp = configuration.client.execute(req).await?;
197
198 let status = resp.status();
199
200 if !status.is_client_error() && !status.is_server_error() {
201 let content = resp.text().await?;
202 serde_json::from_str(&content).map_err(Error::from)
203 } else {
204 let content = resp.text().await?;
205 let entity: Option<GetAttachmentError> = serde_json::from_str(&content).ok();
206 Err(Error::ResponseError(ResponseContent { status, content, entity }))
207 }
208}
209
210pub async fn get_attachment_meta(configuration: &configuration::Configuration, ) -> Result<models::AttachmentSettings, Error<GetAttachmentMetaError>> {
212
213 let uri_str = format!("{}/rest/api/2/attachment/meta", configuration.base_path);
214 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
215
216 if let Some(ref user_agent) = configuration.user_agent {
217 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
218 }
219 if let Some(ref token) = configuration.oauth_access_token {
220 req_builder = req_builder.bearer_auth(token.to_owned());
221 };
222 if let Some(ref auth_conf) = configuration.basic_auth {
223 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
224 };
225
226 let req = req_builder.build()?;
227 let resp = configuration.client.execute(req).await?;
228
229 let status = resp.status();
230
231 if !status.is_client_error() && !status.is_server_error() {
232 let content = resp.text().await?;
233 serde_json::from_str(&content).map_err(Error::from)
234 } else {
235 let content = resp.text().await?;
236 let entity: Option<GetAttachmentMetaError> = serde_json::from_str(&content).ok();
237 Err(Error::ResponseError(ResponseContent { status, content, entity }))
238 }
239}
240
241pub async fn remove_attachment(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<RemoveAttachmentError>> {
243 let p_id = id;
245
246 let uri_str = format!("{}/rest/api/2/attachment/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
247 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
248
249 if let Some(ref user_agent) = configuration.user_agent {
250 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
251 }
252 if let Some(ref token) = configuration.oauth_access_token {
253 req_builder = req_builder.bearer_auth(token.to_owned());
254 };
255 if let Some(ref auth_conf) = configuration.basic_auth {
256 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
257 };
258
259 let req = req_builder.build()?;
260 let resp = configuration.client.execute(req).await?;
261
262 let status = resp.status();
263
264 if !status.is_client_error() && !status.is_server_error() {
265 Ok(())
266 } else {
267 let content = resp.text().await?;
268 let entity: Option<RemoveAttachmentError> = serde_json::from_str(&content).ok();
269 Err(Error::ResponseError(ResponseContent { status, content, entity }))
270 }
271}
272