jira2/apis/
avatars_api.rs

1/*
2 * The Jira Cloud platform REST API
3 *
4 * Jira Cloud platform REST API documentation
5 *
6 * The version of the OpenAPI document: 1001.0.0-SNAPSHOT
7 * Contact: ecosystem@atlassian.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17/// struct for passing parameters to the method [`delete_avatar`]
18#[derive(Clone, Debug, Default)]
19pub struct DeleteAvatarParams {
20    /// The avatar type.
21    pub _type: String,
22    /// The ID of the item the avatar is associated with.
23    pub owning_object_id: String,
24    /// The ID of the avatar.
25    pub id: i64
26}
27
28/// struct for passing parameters to the method [`get_all_system_avatars`]
29#[derive(Clone, Debug, Default)]
30pub struct GetAllSystemAvatarsParams {
31    /// The avatar type.
32    pub _type: String
33}
34
35/// struct for passing parameters to the method [`get_avatar_image_by_id`]
36#[derive(Clone, Debug, Default)]
37pub struct GetAvatarImageByIdParams {
38    /// The icon type of the avatar.
39    pub _type: String,
40    /// The ID of the avatar.
41    pub id: i64,
42    /// The size of the avatar image. If not provided the default size is returned.
43    pub size: Option<String>,
44    /// The format to return the avatar image in. If not provided the original content format is returned.
45    pub format: Option<String>
46}
47
48/// struct for passing parameters to the method [`get_avatar_image_by_owner`]
49#[derive(Clone, Debug, Default)]
50pub struct GetAvatarImageByOwnerParams {
51    /// The icon type of the avatar.
52    pub _type: String,
53    /// The ID of the project or issue type the avatar belongs to.
54    pub entity_id: String,
55    /// The size of the avatar image. If not provided the default size is returned.
56    pub size: Option<String>,
57    /// The format to return the avatar image in. If not provided the original content format is returned.
58    pub format: Option<String>
59}
60
61/// struct for passing parameters to the method [`get_avatar_image_by_type`]
62#[derive(Clone, Debug, Default)]
63pub struct GetAvatarImageByTypeParams {
64    /// The icon type of the avatar.
65    pub _type: String,
66    /// The size of the avatar image. If not provided the default size is returned.
67    pub size: Option<String>,
68    /// The format to return the avatar image in. If not provided the original content format is returned.
69    pub format: Option<String>
70}
71
72/// struct for passing parameters to the method [`get_avatars`]
73#[derive(Clone, Debug, Default)]
74pub struct GetAvatarsParams {
75    /// The avatar type.
76    pub _type: String,
77    /// The ID of the item the avatar is associated with.
78    pub entity_id: String
79}
80
81/// struct for passing parameters to the method [`store_avatar`]
82#[derive(Clone, Debug, Default)]
83pub struct StoreAvatarParams {
84    /// The avatar type.
85    pub _type: String,
86    /// The ID of the item the avatar is associated with.
87    pub entity_id: String,
88    /// The length of each side of the crop region.
89    pub size: i32,
90    pub body: Option<serde_json::Value>,
91    /// The X coordinate of the top-left corner of the crop region.
92    pub x: Option<i32>,
93    /// The Y coordinate of the top-left corner of the crop region.
94    pub y: Option<i32>
95}
96
97
98/// struct for typed errors of method [`delete_avatar`]
99#[derive(Debug, Clone, Serialize, Deserialize)]
100#[serde(untagged)]
101pub enum DeleteAvatarError {
102    Status400(),
103    Status403(),
104    Status404(),
105    UnknownValue(serde_json::Value),
106}
107
108/// struct for typed errors of method [`get_all_system_avatars`]
109#[derive(Debug, Clone, Serialize, Deserialize)]
110#[serde(untagged)]
111pub enum GetAllSystemAvatarsError {
112    Status401(),
113    Status500(),
114    UnknownValue(serde_json::Value),
115}
116
117/// struct for typed errors of method [`get_avatar_image_by_id`]
118#[derive(Debug, Clone, Serialize, Deserialize)]
119#[serde(untagged)]
120pub enum GetAvatarImageByIdError {
121    Status400(crate::models::ErrorCollection),
122    Status401(crate::models::ErrorCollection),
123    Status403(crate::models::ErrorCollection),
124    Status404(crate::models::ErrorCollection),
125    UnknownValue(serde_json::Value),
126}
127
128/// struct for typed errors of method [`get_avatar_image_by_owner`]
129#[derive(Debug, Clone, Serialize, Deserialize)]
130#[serde(untagged)]
131pub enum GetAvatarImageByOwnerError {
132    Status400(crate::models::ErrorCollection),
133    Status401(crate::models::ErrorCollection),
134    Status403(crate::models::ErrorCollection),
135    Status404(crate::models::ErrorCollection),
136    UnknownValue(serde_json::Value),
137}
138
139/// struct for typed errors of method [`get_avatar_image_by_type`]
140#[derive(Debug, Clone, Serialize, Deserialize)]
141#[serde(untagged)]
142pub enum GetAvatarImageByTypeError {
143    Status401(crate::models::ErrorCollection),
144    Status403(crate::models::ErrorCollection),
145    Status404(crate::models::ErrorCollection),
146    UnknownValue(serde_json::Value),
147}
148
149/// struct for typed errors of method [`get_avatars`]
150#[derive(Debug, Clone, Serialize, Deserialize)]
151#[serde(untagged)]
152pub enum GetAvatarsError {
153    Status401(),
154    Status404(),
155    UnknownValue(serde_json::Value),
156}
157
158/// struct for typed errors of method [`store_avatar`]
159#[derive(Debug, Clone, Serialize, Deserialize)]
160#[serde(untagged)]
161pub enum StoreAvatarError {
162    Status400(),
163    Status401(),
164    Status403(),
165    Status404(),
166    UnknownValue(serde_json::Value),
167}
168
169
170/// Deletes an avatar from a project or issue type.  **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
171pub async fn delete_avatar(configuration: &configuration::Configuration, params: DeleteAvatarParams) -> Result<(), Error<DeleteAvatarError>> {
172    let local_var_configuration = configuration;
173
174    // unbox the parameters
175    let _type = params._type;
176    let owning_object_id = params.owning_object_id;
177    let id = params.id;
178
179
180    let local_var_client = &local_var_configuration.client;
181
182    let local_var_uri_str = format!("{}/rest/api/2/universal_avatar/type/{type}/owner/{owningObjectId}/avatar/{id}", local_var_configuration.base_path, type=crate::apis::urlencode(_type), owningObjectId=crate::apis::urlencode(owning_object_id), id=id);
183    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
184
185    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
186        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
187    }
188    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
189        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
190    };
191    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
192        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
193    };
194
195    let local_var_req = local_var_req_builder.build()?;
196    let local_var_resp = local_var_client.execute(local_var_req).await?;
197
198    let local_var_status = local_var_resp.status();
199    let local_var_content = local_var_resp.text().await?;
200
201    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
202        Ok(())
203    } else {
204        let local_var_entity: Option<DeleteAvatarError> = serde_json::from_str(&local_var_content).ok();
205        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
206        Err(Error::ResponseError(local_var_error))
207    }
208}
209
210/// Returns a list of system avatar details by owner type, where the owner types are issue type, project, or user.  This operation can be accessed anonymously.  **[Permissions](#permissions) required:** None.
211pub async fn get_all_system_avatars(configuration: &configuration::Configuration, params: GetAllSystemAvatarsParams) -> Result<crate::models::SystemAvatars, Error<GetAllSystemAvatarsError>> {
212    let local_var_configuration = configuration;
213
214    // unbox the parameters
215    let _type = params._type;
216
217
218    let local_var_client = &local_var_configuration.client;
219
220    let local_var_uri_str = format!("{}/rest/api/2/avatar/{type}/system", local_var_configuration.base_path, type=crate::apis::urlencode(_type));
221    let mut local_var_req_builder = 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 = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
225    }
226    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
227        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
228    };
229    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
230        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
231    };
232
233    let local_var_req = local_var_req_builder.build()?;
234    let local_var_resp = local_var_client.execute(local_var_req).await?;
235
236    let local_var_status = local_var_resp.status();
237    let local_var_content = local_var_resp.text().await?;
238
239    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
240        serde_json::from_str(&local_var_content).map_err(Error::from)
241    } else {
242        let local_var_entity: Option<GetAllSystemAvatarsError> = serde_json::from_str(&local_var_content).ok();
243        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
244        Err(Error::ResponseError(local_var_error))
245    }
246}
247
248/// Returns a project or issue type avatar image by ID.  This operation can be accessed anonymously.  **[Permissions](#permissions) required:**   *  For system avatars, none.  *  For custom project avatars, *Browse projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project the avatar belongs to.  *  For custom issue type avatars, *Browse projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for at least one project the issue type is used in.
249pub async fn get_avatar_image_by_id(configuration: &configuration::Configuration, params: GetAvatarImageByIdParams) -> Result<serde_json::Value, Error<GetAvatarImageByIdError>> {
250    let local_var_configuration = configuration;
251
252    // unbox the parameters
253    let _type = params._type;
254    let id = params.id;
255    let size = params.size;
256    let format = params.format;
257
258
259    let local_var_client = &local_var_configuration.client;
260
261    let local_var_uri_str = format!("{}/rest/api/2/universal_avatar/view/type/{type}/avatar/{id}", local_var_configuration.base_path, type=crate::apis::urlencode(_type), id=id);
262    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
263
264    if let Some(ref local_var_str) = size {
265        local_var_req_builder = local_var_req_builder.query(&[("size", &local_var_str.to_string())]);
266    }
267    if let Some(ref local_var_str) = format {
268        local_var_req_builder = local_var_req_builder.query(&[("format", &local_var_str.to_string())]);
269    }
270    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
271        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
272    }
273    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
274        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
275    };
276    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
277        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
278    };
279
280    let local_var_req = local_var_req_builder.build()?;
281    let local_var_resp = local_var_client.execute(local_var_req).await?;
282
283    let local_var_status = local_var_resp.status();
284    let local_var_content = local_var_resp.text().await?;
285
286    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
287        serde_json::from_str(&local_var_content).map_err(Error::from)
288    } else {
289        let local_var_entity: Option<GetAvatarImageByIdError> = serde_json::from_str(&local_var_content).ok();
290        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
291        Err(Error::ResponseError(local_var_error))
292    }
293}
294
295/// Returns the avatar image for a project or issue type.  This operation can be accessed anonymously.  **[Permissions](#permissions) required:**   *  For system avatars, none.  *  For custom project avatars, *Browse projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project the avatar belongs to.  *  For custom issue type avatars, *Browse projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for at least one project the issue type is used in.
296pub async fn get_avatar_image_by_owner(configuration: &configuration::Configuration, params: GetAvatarImageByOwnerParams) -> Result<serde_json::Value, Error<GetAvatarImageByOwnerError>> {
297    let local_var_configuration = configuration;
298
299    // unbox the parameters
300    let _type = params._type;
301    let entity_id = params.entity_id;
302    let size = params.size;
303    let format = params.format;
304
305
306    let local_var_client = &local_var_configuration.client;
307
308    let local_var_uri_str = format!("{}/rest/api/2/universal_avatar/view/type/{type}/owner/{entityId}", local_var_configuration.base_path, type=crate::apis::urlencode(_type), entityId=crate::apis::urlencode(entity_id));
309    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
310
311    if let Some(ref local_var_str) = size {
312        local_var_req_builder = local_var_req_builder.query(&[("size", &local_var_str.to_string())]);
313    }
314    if let Some(ref local_var_str) = format {
315        local_var_req_builder = local_var_req_builder.query(&[("format", &local_var_str.to_string())]);
316    }
317    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
318        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
319    }
320    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
321        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
322    };
323    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
324        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
325    };
326
327    let local_var_req = local_var_req_builder.build()?;
328    let local_var_resp = local_var_client.execute(local_var_req).await?;
329
330    let local_var_status = local_var_resp.status();
331    let local_var_content = local_var_resp.text().await?;
332
333    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
334        serde_json::from_str(&local_var_content).map_err(Error::from)
335    } else {
336        let local_var_entity: Option<GetAvatarImageByOwnerError> = serde_json::from_str(&local_var_content).ok();
337        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
338        Err(Error::ResponseError(local_var_error))
339    }
340}
341
342/// Returns the default project or issue type avatar image.  This operation can be accessed anonymously.  **[Permissions](#permissions) required:** None.
343pub async fn get_avatar_image_by_type(configuration: &configuration::Configuration, params: GetAvatarImageByTypeParams) -> Result<serde_json::Value, Error<GetAvatarImageByTypeError>> {
344    let local_var_configuration = configuration;
345
346    // unbox the parameters
347    let _type = params._type;
348    let size = params.size;
349    let format = params.format;
350
351
352    let local_var_client = &local_var_configuration.client;
353
354    let local_var_uri_str = format!("{}/rest/api/2/universal_avatar/view/type/{type}", local_var_configuration.base_path, type=crate::apis::urlencode(_type));
355    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
356
357    if let Some(ref local_var_str) = size {
358        local_var_req_builder = local_var_req_builder.query(&[("size", &local_var_str.to_string())]);
359    }
360    if let Some(ref local_var_str) = format {
361        local_var_req_builder = local_var_req_builder.query(&[("format", &local_var_str.to_string())]);
362    }
363    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
364        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
365    }
366    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
367        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
368    };
369    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
370        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
371    };
372
373    let local_var_req = local_var_req_builder.build()?;
374    let local_var_resp = local_var_client.execute(local_var_req).await?;
375
376    let local_var_status = local_var_resp.status();
377    let local_var_content = local_var_resp.text().await?;
378
379    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
380        serde_json::from_str(&local_var_content).map_err(Error::from)
381    } else {
382        let local_var_entity: Option<GetAvatarImageByTypeError> = serde_json::from_str(&local_var_content).ok();
383        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
384        Err(Error::ResponseError(local_var_error))
385    }
386}
387
388/// Returns the system and custom avatars for a project or issue type.  This operation can be accessed anonymously.  **[Permissions](#permissions) required:**   *  for custom project avatars, *Browse projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project the avatar belongs to.  *  for custom issue type avatars, *Browse projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for at least one project the issue type is used in.  *  for system avatars, none.
389pub async fn get_avatars(configuration: &configuration::Configuration, params: GetAvatarsParams) -> Result<crate::models::Avatars, Error<GetAvatarsError>> {
390    let local_var_configuration = configuration;
391
392    // unbox the parameters
393    let _type = params._type;
394    let entity_id = params.entity_id;
395
396
397    let local_var_client = &local_var_configuration.client;
398
399    let local_var_uri_str = format!("{}/rest/api/2/universal_avatar/type/{type}/owner/{entityId}", local_var_configuration.base_path, type=crate::apis::urlencode(_type), entityId=crate::apis::urlencode(entity_id));
400    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
401
402    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
403        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
404    }
405    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
406        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
407    };
408    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
409        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
410    };
411
412    let local_var_req = local_var_req_builder.build()?;
413    let local_var_resp = local_var_client.execute(local_var_req).await?;
414
415    let local_var_status = local_var_resp.status();
416    let local_var_content = local_var_resp.text().await?;
417
418    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
419        serde_json::from_str(&local_var_content).map_err(Error::from)
420    } else {
421        let local_var_entity: Option<GetAvatarsError> = serde_json::from_str(&local_var_content).ok();
422        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
423        Err(Error::ResponseError(local_var_error))
424    }
425}
426
427/// Loads a custom avatar for a project or issue type.  Specify the avatar's local file location in the body of the request. Also, include the following headers:   *  `X-Atlassian-Token: no-check` To prevent XSRF protection blocking the request, for more information see [Special Headers](#special-request-headers).  *  `Content-Type: image/image type` Valid image types are JPEG, GIF, or PNG.  For example:   `curl --request POST `  `--user email@example.com:<api_token> `  `--header 'X-Atlassian-Token: no-check' `  `--header 'Content-Type: image/< image_type>' `  `--data-binary \"<@/path/to/file/with/your/avatar>\" `  `--url 'https://your-domain.atlassian.net/rest/api/2/universal_avatar/type/{type}/owner/{entityId}'`  The avatar is cropped to a square. If no crop parameters are specified, the square originates at the top left of the image. The length of the square's sides is set to the smaller of the height or width of the image.  The cropped image is then used to create avatars of 16x16, 24x24, 32x32, and 48x48 in size.  After creating the avatar use:   *  [Update issue type](#api-rest-api-2-issuetype-id-put) to set it as the issue type's displayed avatar.  *  [Set project avatar](#api-rest-api-2-project-projectIdOrKey-avatar-put) to set it as the project's displayed avatar.  **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
428pub async fn store_avatar(configuration: &configuration::Configuration, params: StoreAvatarParams) -> Result<crate::models::Avatar, Error<StoreAvatarError>> {
429    let local_var_configuration = configuration;
430
431    // unbox the parameters
432    let _type = params._type;
433    let entity_id = params.entity_id;
434    let size = params.size;
435    let body = params.body;
436    let x = params.x;
437    let y = params.y;
438
439
440    let local_var_client = &local_var_configuration.client;
441
442    let local_var_uri_str = format!("{}/rest/api/2/universal_avatar/type/{type}/owner/{entityId}", local_var_configuration.base_path, type=crate::apis::urlencode(_type), entityId=crate::apis::urlencode(entity_id));
443    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
444
445    if let Some(ref local_var_str) = x {
446        local_var_req_builder = local_var_req_builder.query(&[("x", &local_var_str.to_string())]);
447    }
448    if let Some(ref local_var_str) = y {
449        local_var_req_builder = local_var_req_builder.query(&[("y", &local_var_str.to_string())]);
450    }
451    local_var_req_builder = local_var_req_builder.query(&[("size", &size.to_string())]);
452    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
453        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
454    }
455    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
456        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
457    };
458    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
459        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
460    };
461    local_var_req_builder = local_var_req_builder.json(&body);
462
463    let local_var_req = local_var_req_builder.build()?;
464    let local_var_resp = local_var_client.execute(local_var_req).await?;
465
466    let local_var_status = local_var_resp.status();
467    let local_var_content = local_var_resp.text().await?;
468
469    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
470        serde_json::from_str(&local_var_content).map_err(Error::from)
471    } else {
472        let local_var_entity: Option<StoreAvatarError> = serde_json::from_str(&local_var_content).ok();
473        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
474        Err(Error::ResponseError(local_var_error))
475    }
476}
477