jira_api_v2/apis/
project_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 [`create_project_avatar`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateProjectAvatarError {
22    Status400(),
23    Status401(),
24    Status403(),
25    Status404(),
26    UnknownValue(serde_json::Value),
27}
28
29/// struct for typed errors of method [`delete_project_avatar`]
30#[derive(Debug, Clone, Serialize, Deserialize)]
31#[serde(untagged)]
32pub enum DeleteProjectAvatarError {
33    Status401(),
34    Status403(),
35    Status404(),
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`get_all_project_avatars`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum GetAllProjectAvatarsError {
43    Status401(),
44    Status404(),
45    UnknownValue(serde_json::Value),
46}
47
48/// struct for typed errors of method [`update_project_avatar`]
49#[derive(Debug, Clone, Serialize, Deserialize)]
50#[serde(untagged)]
51pub enum UpdateProjectAvatarError {
52    Status401(),
53    Status403(),
54    Status404(),
55    UnknownValue(serde_json::Value),
56}
57
58
59/// Loads an avatar for a project.  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/project/{projectIdOrKey}/avatar2'`  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 [Set project avatar](#api-rest-api-2-project-projectIdOrKey-avatar-put) to set it as the project's displayed avatar.  **[Permissions](#permissions) required:** *Administer projects* [project permission](https://confluence.atlassian.com/x/yodKLg).
60pub async fn create_project_avatar(configuration: &configuration::Configuration, project_id_or_key: &str, body: Option<serde_json::Value>, x: Option<i32>, y: Option<i32>, size: Option<i32>) -> Result<models::Avatar, Error<CreateProjectAvatarError>> {
61    // add a prefix to parameters to efficiently prevent name collisions
62    let p_project_id_or_key = project_id_or_key;
63    let p_body = body;
64    let p_x = x;
65    let p_y = y;
66    let p_size = size;
67
68    let uri_str = format!("{}/rest/api/2/project/{projectIdOrKey}/avatar2", configuration.base_path, projectIdOrKey=crate::apis::urlencode(p_project_id_or_key));
69    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
70
71    if let Some(ref param_value) = p_x {
72        req_builder = req_builder.query(&[("x", &param_value.to_string())]);
73    }
74    if let Some(ref param_value) = p_y {
75        req_builder = req_builder.query(&[("y", &param_value.to_string())]);
76    }
77    if let Some(ref param_value) = p_size {
78        req_builder = req_builder.query(&[("size", &param_value.to_string())]);
79    }
80    if let Some(ref user_agent) = configuration.user_agent {
81        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
82    }
83    if let Some(ref token) = configuration.oauth_access_token {
84        req_builder = req_builder.bearer_auth(token.to_owned());
85    };
86    if let Some(ref auth_conf) = configuration.basic_auth {
87        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
88    };
89    req_builder = req_builder.json(&p_body);
90
91    let req = req_builder.build()?;
92    let resp = configuration.client.execute(req).await?;
93
94    let status = resp.status();
95
96    if !status.is_client_error() && !status.is_server_error() {
97        let content = resp.text().await?;
98        serde_json::from_str(&content).map_err(Error::from)
99    } else {
100        let content = resp.text().await?;
101        let entity: Option<CreateProjectAvatarError> = serde_json::from_str(&content).ok();
102        Err(Error::ResponseError(ResponseContent { status, content, entity }))
103    }
104}
105
106/// Deletes a custom avatar from a project. Note that system avatars cannot be deleted.  **[Permissions](#permissions) required:** *Administer projects* [project permission](https://confluence.atlassian.com/x/yodKLg).
107pub async fn delete_project_avatar(configuration: &configuration::Configuration, project_id_or_key: &str, id: i64) -> Result<(), Error<DeleteProjectAvatarError>> {
108    // add a prefix to parameters to efficiently prevent name collisions
109    let p_project_id_or_key = project_id_or_key;
110    let p_id = id;
111
112    let uri_str = format!("{}/rest/api/2/project/{projectIdOrKey}/avatar/{id}", configuration.base_path, projectIdOrKey=crate::apis::urlencode(p_project_id_or_key), id=p_id);
113    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
114
115    if let Some(ref user_agent) = configuration.user_agent {
116        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
117    }
118    if let Some(ref token) = configuration.oauth_access_token {
119        req_builder = req_builder.bearer_auth(token.to_owned());
120    };
121    if let Some(ref auth_conf) = configuration.basic_auth {
122        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
123    };
124
125    let req = req_builder.build()?;
126    let resp = configuration.client.execute(req).await?;
127
128    let status = resp.status();
129
130    if !status.is_client_error() && !status.is_server_error() {
131        Ok(())
132    } else {
133        let content = resp.text().await?;
134        let entity: Option<DeleteProjectAvatarError> = serde_json::from_str(&content).ok();
135        Err(Error::ResponseError(ResponseContent { status, content, entity }))
136    }
137}
138
139/// Returns all project avatars, grouped by system and custom avatars.  This operation can be accessed anonymously.  **[Permissions](#permissions) required:** *Browse projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project.
140pub async fn get_all_project_avatars(configuration: &configuration::Configuration, project_id_or_key: &str) -> Result<models::ProjectAvatars, Error<GetAllProjectAvatarsError>> {
141    // add a prefix to parameters to efficiently prevent name collisions
142    let p_project_id_or_key = project_id_or_key;
143
144    let uri_str = format!("{}/rest/api/2/project/{projectIdOrKey}/avatars", configuration.base_path, projectIdOrKey=crate::apis::urlencode(p_project_id_or_key));
145    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
146
147    if let Some(ref user_agent) = configuration.user_agent {
148        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
149    }
150    if let Some(ref token) = configuration.oauth_access_token {
151        req_builder = req_builder.bearer_auth(token.to_owned());
152    };
153    if let Some(ref auth_conf) = configuration.basic_auth {
154        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
155    };
156
157    let req = req_builder.build()?;
158    let resp = configuration.client.execute(req).await?;
159
160    let status = resp.status();
161
162    if !status.is_client_error() && !status.is_server_error() {
163        let content = resp.text().await?;
164        serde_json::from_str(&content).map_err(Error::from)
165    } else {
166        let content = resp.text().await?;
167        let entity: Option<GetAllProjectAvatarsError> = serde_json::from_str(&content).ok();
168        Err(Error::ResponseError(ResponseContent { status, content, entity }))
169    }
170}
171
172/// Sets the avatar displayed for a project.  Use [Load project avatar](#api-rest-api-2-project-projectIdOrKey-avatar2-post) to store avatars against the project, before using this operation to set the displayed avatar.  **[Permissions](#permissions) required:** *Administer projects* [project permission](https://confluence.atlassian.com/x/yodKLg).
173pub async fn update_project_avatar(configuration: &configuration::Configuration, project_id_or_key: &str, avatar: models::Avatar) -> Result<serde_json::Value, Error<UpdateProjectAvatarError>> {
174    // add a prefix to parameters to efficiently prevent name collisions
175    let p_project_id_or_key = project_id_or_key;
176    let p_avatar = avatar;
177
178    let uri_str = format!("{}/rest/api/2/project/{projectIdOrKey}/avatar", configuration.base_path, projectIdOrKey=crate::apis::urlencode(p_project_id_or_key));
179    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
180
181    if let Some(ref user_agent) = configuration.user_agent {
182        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
183    }
184    if let Some(ref token) = configuration.oauth_access_token {
185        req_builder = req_builder.bearer_auth(token.to_owned());
186    };
187    if let Some(ref auth_conf) = configuration.basic_auth {
188        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
189    };
190    req_builder = req_builder.json(&p_avatar);
191
192    let req = req_builder.build()?;
193    let resp = configuration.client.execute(req).await?;
194
195    let status = resp.status();
196
197    if !status.is_client_error() && !status.is_server_error() {
198        let content = resp.text().await?;
199        serde_json::from_str(&content).map_err(Error::from)
200    } else {
201        let content = resp.text().await?;
202        let entity: Option<UpdateProjectAvatarError> = serde_json::from_str(&content).ok();
203        Err(Error::ResponseError(ResponseContent { status, content, entity }))
204    }
205}
206