jira_api_v2/apis/
project_avatars_api.rs1use 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 CreateProjectAvatarError {
22 Status400(),
23 Status401(),
24 Status403(),
25 Status404(),
26 UnknownValue(serde_json::Value),
27}
28
29#[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#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum GetAllProjectAvatarsError {
43 Status401(),
44 Status404(),
45 UnknownValue(serde_json::Value),
46}
47
48#[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
59pub 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 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", ¶m_value.to_string())]);
73 }
74 if let Some(ref param_value) = p_y {
75 req_builder = req_builder.query(&[("y", ¶m_value.to_string())]);
76 }
77 if let Some(ref param_value) = p_size {
78 req_builder = req_builder.query(&[("size", ¶m_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
106pub async fn delete_project_avatar(configuration: &configuration::Configuration, project_id_or_key: &str, id: i64) -> Result<(), Error<DeleteProjectAvatarError>> {
108 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
139pub async fn get_all_project_avatars(configuration: &configuration::Configuration, project_id_or_key: &str) -> Result<models::ProjectAvatars, Error<GetAllProjectAvatarsError>> {
141 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
172pub async fn update_project_avatar(configuration: &configuration::Configuration, project_id_or_key: &str, avatar: models::Avatar) -> Result<serde_json::Value, Error<UpdateProjectAvatarError>> {
174 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