jira_api_v2/apis/
issue_notification_schemes_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_notification_scheme`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetNotificationSchemeError {
22    Status400(),
23    Status401(),
24    Status404(),
25    UnknownValue(serde_json::Value),
26}
27
28/// struct for typed errors of method [`get_notification_schemes`]
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum GetNotificationSchemesError {
32    Status401(),
33    UnknownValue(serde_json::Value),
34}
35
36
37/// Returns a [notification scheme](https://confluence.atlassian.com/x/8YdKLg), including the list of events and the recipients who will receive notifications for those events.  **[Permissions](#permissions) required:** Permission to access Jira, however the user must have permission to administer at least one project associated with the notification scheme.
38pub async fn get_notification_scheme(configuration: &configuration::Configuration, id: i64, expand: Option<&str>) -> Result<models::NotificationScheme, Error<GetNotificationSchemeError>> {
39    // add a prefix to parameters to efficiently prevent name collisions
40    let p_id = id;
41    let p_expand = expand;
42
43    let uri_str = format!("{}/rest/api/2/notificationscheme/{id}", configuration.base_path, id=p_id);
44    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
45
46    if let Some(ref param_value) = p_expand {
47        req_builder = req_builder.query(&[("expand", &param_value.to_string())]);
48    }
49    if let Some(ref user_agent) = configuration.user_agent {
50        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
51    }
52    if let Some(ref token) = configuration.oauth_access_token {
53        req_builder = req_builder.bearer_auth(token.to_owned());
54    };
55    if let Some(ref auth_conf) = configuration.basic_auth {
56        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
57    };
58
59    let req = req_builder.build()?;
60    let resp = configuration.client.execute(req).await?;
61
62    let status = resp.status();
63
64    if !status.is_client_error() && !status.is_server_error() {
65        let content = resp.text().await?;
66        serde_json::from_str(&content).map_err(Error::from)
67    } else {
68        let content = resp.text().await?;
69        let entity: Option<GetNotificationSchemeError> = serde_json::from_str(&content).ok();
70        Err(Error::ResponseError(ResponseContent { status, content, entity }))
71    }
72}
73
74/// Returns a [paginated](#pagination) list of [notification schemes](https://confluence.atlassian.com/x/8YdKLg) ordered by display name.  ### About notification schemes ###  A notification scheme is a list of events and recipients who will receive notifications for those events. The list is contained within the `notificationSchemeEvents` object and contains pairs of `events` and `notifications`:   *  `event` Identifies the type of event. The events can be [Jira system events](https://confluence.atlassian.com/x/8YdKLg#Creatinganotificationscheme-eventsEvents) or [custom events](https://confluence.atlassian.com/x/AIlKLg).  *  `notifications` Identifies the [recipients](https://confluence.atlassian.com/x/8YdKLg#Creatinganotificationscheme-recipientsRecipients) of notifications for each event. Recipients can be any of the following types:           *  `CurrentAssignee`      *  `Reporter`      *  `CurrentUser`      *  `ProjectLead`      *  `ComponentLead`      *  `User` (the `parameter` is the user key)      *  `Group` (the `parameter` is the group name)      *  `ProjectRole` (the `parameter` is the project role ID)      *  `EmailAddress`      *  `AllWatchers`      *  `UserCustomField` (the `parameter` is the ID of the custom field)      *  `GroupCustomField`(the `parameter` is the ID of the custom field)  *Note that you should allow for events without recipients to appear in responses.*  **[Permissions](#permissions) required:** Permission to access Jira, however the user must have permission to administer at least one project associated with a notification scheme for it to be returned.
75pub async fn get_notification_schemes(configuration: &configuration::Configuration, start_at: Option<i64>, max_results: Option<i32>, expand: Option<&str>) -> Result<models::PageBeanNotificationScheme, Error<GetNotificationSchemesError>> {
76    // add a prefix to parameters to efficiently prevent name collisions
77    let p_start_at = start_at;
78    let p_max_results = max_results;
79    let p_expand = expand;
80
81    let uri_str = format!("{}/rest/api/2/notificationscheme", configuration.base_path);
82    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
83
84    if let Some(ref param_value) = p_start_at {
85        req_builder = req_builder.query(&[("startAt", &param_value.to_string())]);
86    }
87    if let Some(ref param_value) = p_max_results {
88        req_builder = req_builder.query(&[("maxResults", &param_value.to_string())]);
89    }
90    if let Some(ref param_value) = p_expand {
91        req_builder = req_builder.query(&[("expand", &param_value.to_string())]);
92    }
93    if let Some(ref user_agent) = configuration.user_agent {
94        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
95    }
96    if let Some(ref token) = configuration.oauth_access_token {
97        req_builder = req_builder.bearer_auth(token.to_owned());
98    };
99    if let Some(ref auth_conf) = configuration.basic_auth {
100        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
101    };
102
103    let req = req_builder.build()?;
104    let resp = configuration.client.execute(req).await?;
105
106    let status = resp.status();
107
108    if !status.is_client_error() && !status.is_server_error() {
109        let content = resp.text().await?;
110        serde_json::from_str(&content).map_err(Error::from)
111    } else {
112        let content = resp.text().await?;
113        let entity: Option<GetNotificationSchemesError> = serde_json::from_str(&content).ok();
114        Err(Error::ResponseError(ResponseContent { status, content, entity }))
115    }
116}
117