jira_api_v2/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;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`delete_avatar`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum DeleteAvatarError {
22    Status400(),
23    Status403(),
24    Status404(),
25    UnknownValue(serde_json::Value),
26}
27
28/// struct for typed errors of method [`get_all_system_avatars`]
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum GetAllSystemAvatarsError {
32    Status401(),
33    Status500(),
34    UnknownValue(serde_json::Value),
35}
36
37/// struct for typed errors of method [`get_avatars`]
38#[derive(Debug, Clone, Serialize, Deserialize)]
39#[serde(untagged)]
40pub enum GetAvatarsError {
41    Status401(),
42    Status404(),
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`store_avatar`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum StoreAvatarError {
50    Status400(),
51    Status401(),
52    Status403(),
53    Status404(),
54    UnknownValue(serde_json::Value),
55}
56
57
58/// Deletes an avatar from a project or issue type.  **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
59pub async fn delete_avatar(configuration: &configuration::Configuration, r#type: &str, owning_object_id: &str, id: i64) -> Result<(), Error<DeleteAvatarError>> {
60    // add a prefix to parameters to efficiently prevent name collisions
61    let p_type = r#type;
62    let p_owning_object_id = owning_object_id;
63    let p_id = id;
64
65    let uri_str = format!("{}/rest/api/2/universal_avatar/type/{type}/owner/{owningObjectId}/avatar/{id}", configuration.base_path, type=crate::apis::urlencode(p_type), owningObjectId=crate::apis::urlencode(p_owning_object_id), id=p_id);
66    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
67
68    if let Some(ref user_agent) = configuration.user_agent {
69        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
70    }
71    if let Some(ref token) = configuration.oauth_access_token {
72        req_builder = req_builder.bearer_auth(token.to_owned());
73    };
74    if let Some(ref auth_conf) = configuration.basic_auth {
75        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
76    };
77
78    let req = req_builder.build()?;
79    let resp = configuration.client.execute(req).await?;
80
81    let status = resp.status();
82
83    if !status.is_client_error() && !status.is_server_error() {
84        Ok(())
85    } else {
86        let content = resp.text().await?;
87        let entity: Option<DeleteAvatarError> = serde_json::from_str(&content).ok();
88        Err(Error::ResponseError(ResponseContent { status, content, entity }))
89    }
90}
91
92/// 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.
93pub async fn get_all_system_avatars(configuration: &configuration::Configuration, r#type: &str) -> Result<models::SystemAvatars, Error<GetAllSystemAvatarsError>> {
94    // add a prefix to parameters to efficiently prevent name collisions
95    let p_type = r#type;
96
97    let uri_str = format!("{}/rest/api/2/avatar/{type}/system", configuration.base_path, type=crate::apis::urlencode(p_type));
98    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
99
100    if let Some(ref user_agent) = configuration.user_agent {
101        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
102    }
103    if let Some(ref token) = configuration.oauth_access_token {
104        req_builder = req_builder.bearer_auth(token.to_owned());
105    };
106    if let Some(ref auth_conf) = configuration.basic_auth {
107        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
108    };
109
110    let req = req_builder.build()?;
111    let resp = configuration.client.execute(req).await?;
112
113    let status = resp.status();
114
115    if !status.is_client_error() && !status.is_server_error() {
116        let content = resp.text().await?;
117        serde_json::from_str(&content).map_err(Error::from)
118    } else {
119        let content = resp.text().await?;
120        let entity: Option<GetAllSystemAvatarsError> = serde_json::from_str(&content).ok();
121        Err(Error::ResponseError(ResponseContent { status, content, entity }))
122    }
123}
124
125/// 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.
126pub async fn get_avatars(configuration: &configuration::Configuration, r#type: &str, entity_id: &str) -> Result<models::Avatars, Error<GetAvatarsError>> {
127    // add a prefix to parameters to efficiently prevent name collisions
128    let p_type = r#type;
129    let p_entity_id = entity_id;
130
131    let uri_str = format!("{}/rest/api/2/universal_avatar/type/{type}/owner/{entityId}", configuration.base_path, type=crate::apis::urlencode(p_type), entityId=crate::apis::urlencode(p_entity_id));
132    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
133
134    if let Some(ref user_agent) = configuration.user_agent {
135        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
136    }
137    if let Some(ref token) = configuration.oauth_access_token {
138        req_builder = req_builder.bearer_auth(token.to_owned());
139    };
140    if let Some(ref auth_conf) = configuration.basic_auth {
141        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
142    };
143
144    let req = req_builder.build()?;
145    let resp = configuration.client.execute(req).await?;
146
147    let status = resp.status();
148
149    if !status.is_client_error() && !status.is_server_error() {
150        let content = resp.text().await?;
151        serde_json::from_str(&content).map_err(Error::from)
152    } else {
153        let content = resp.text().await?;
154        let entity: Option<GetAvatarsError> = serde_json::from_str(&content).ok();
155        Err(Error::ResponseError(ResponseContent { status, content, entity }))
156    }
157}
158
159/// 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).
160pub async fn store_avatar(configuration: &configuration::Configuration, r#type: &str, entity_id: &str, size: i32, body: Option<serde_json::Value>, x: Option<i32>, y: Option<i32>) -> Result<models::Avatar, Error<StoreAvatarError>> {
161    // add a prefix to parameters to efficiently prevent name collisions
162    let p_type = r#type;
163    let p_entity_id = entity_id;
164    let p_size = size;
165    let p_body = body;
166    let p_x = x;
167    let p_y = y;
168
169    let uri_str = format!("{}/rest/api/2/universal_avatar/type/{type}/owner/{entityId}", configuration.base_path, type=crate::apis::urlencode(p_type), entityId=crate::apis::urlencode(p_entity_id));
170    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
171
172    if let Some(ref param_value) = p_x {
173        req_builder = req_builder.query(&[("x", &param_value.to_string())]);
174    }
175    if let Some(ref param_value) = p_y {
176        req_builder = req_builder.query(&[("y", &param_value.to_string())]);
177    }
178    req_builder = req_builder.query(&[("size", &p_size.to_string())]);
179    if let Some(ref user_agent) = configuration.user_agent {
180        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
181    }
182    if let Some(ref token) = configuration.oauth_access_token {
183        req_builder = req_builder.bearer_auth(token.to_owned());
184    };
185    if let Some(ref auth_conf) = configuration.basic_auth {
186        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
187    };
188    req_builder = req_builder.json(&p_body);
189
190    let req = req_builder.build()?;
191    let resp = configuration.client.execute(req).await?;
192
193    let status = resp.status();
194
195    if !status.is_client_error() && !status.is_server_error() {
196        let content = resp.text().await?;
197        serde_json::from_str(&content).map_err(Error::from)
198    } else {
199        let content = resp.text().await?;
200        let entity: Option<StoreAvatarError> = serde_json::from_str(&content).ok();
201        Err(Error::ResponseError(ResponseContent { status, content, entity }))
202    }
203}
204