jira_api_v2/apis/
project_email_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 GetProjectEmailError {
22 Status401(),
23 Status403(),
24 Status404(),
25 UnknownValue(serde_json::Value),
26}
27
28#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum UpdateProjectEmailError {
32 Status400(),
33 Status401(),
34 Status403(),
35 Status404(),
36 UnknownValue(serde_json::Value),
37}
38
39
40pub async fn get_project_email(configuration: &configuration::Configuration, project_id: i64) -> Result<models::ProjectEmailAddress, Error<GetProjectEmailError>> {
42 let p_project_id = project_id;
44
45 let uri_str = format!("{}/rest/api/2/project/{projectId}/email", configuration.base_path, projectId=p_project_id);
46 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
47
48 if let Some(ref user_agent) = configuration.user_agent {
49 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
50 }
51 if let Some(ref token) = configuration.oauth_access_token {
52 req_builder = req_builder.bearer_auth(token.to_owned());
53 };
54 if let Some(ref auth_conf) = configuration.basic_auth {
55 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
56 };
57
58 let req = req_builder.build()?;
59 let resp = configuration.client.execute(req).await?;
60
61 let status = resp.status();
62
63 if !status.is_client_error() && !status.is_server_error() {
64 let content = resp.text().await?;
65 serde_json::from_str(&content).map_err(Error::from)
66 } else {
67 let content = resp.text().await?;
68 let entity: Option<GetProjectEmailError> = serde_json::from_str(&content).ok();
69 Err(Error::ResponseError(ResponseContent { status, content, entity }))
70 }
71}
72
73pub async fn update_project_email(configuration: &configuration::Configuration, project_id: i64, project_email_address: models::ProjectEmailAddress) -> Result<serde_json::Value, Error<UpdateProjectEmailError>> {
75 let p_project_id = project_id;
77 let p_project_email_address = project_email_address;
78
79 let uri_str = format!("{}/rest/api/2/project/{projectId}/email", configuration.base_path, projectId=p_project_id);
80 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
81
82 if let Some(ref user_agent) = configuration.user_agent {
83 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
84 }
85 if let Some(ref token) = configuration.oauth_access_token {
86 req_builder = req_builder.bearer_auth(token.to_owned());
87 };
88 if let Some(ref auth_conf) = configuration.basic_auth {
89 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
90 };
91 req_builder = req_builder.json(&p_project_email_address);
92
93 let req = req_builder.build()?;
94 let resp = configuration.client.execute(req).await?;
95
96 let status = resp.status();
97
98 if !status.is_client_error() && !status.is_server_error() {
99 let content = resp.text().await?;
100 serde_json::from_str(&content).map_err(Error::from)
101 } else {
102 let content = resp.text().await?;
103 let entity: Option<UpdateProjectEmailError> = serde_json::from_str(&content).ok();
104 Err(Error::ResponseError(ResponseContent { status, content, entity }))
105 }
106}
107