jira_api_v2/apis/
project_email_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 [`get_project_email`]
19#[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/// struct for typed errors of method [`update_project_email`]
29#[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
40/// Returns the [project's sender email address](https://confluence.atlassian.com/x/dolKLg).  **[Permissions](#permissions) required:** *Browse projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project.
41pub async fn get_project_email(configuration: &configuration::Configuration, project_id: i64) -> Result<models::ProjectEmailAddress, Error<GetProjectEmailError>> {
42    // add a prefix to parameters to efficiently prevent name collisions
43    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
73/// Sets the [project's sender email address](https://confluence.atlassian.com/x/dolKLg).  If `emailAddress` is an empty string, the default email address is restored.  **[Permissions](#permissions) required:** *Browse projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project.
74pub async fn update_project_email(configuration: &configuration::Configuration, project_id: i64, project_email_address: models::ProjectEmailAddress) -> Result<serde_json::Value, Error<UpdateProjectEmailError>> {
75    // add a prefix to parameters to efficiently prevent name collisions
76    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