jira_api_v2/apis/
issue_priorities_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_priorities`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetPrioritiesError {
22    Status401(),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method [`get_priority`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum GetPriorityError {
30    Status401(),
31    Status404(),
32    UnknownValue(serde_json::Value),
33}
34
35
36/// Returns the list of all issue priorities.  **[Permissions](#permissions) required:** Permission to access Jira.
37pub async fn get_priorities(configuration: &configuration::Configuration, ) -> Result<Vec<models::Priority>, Error<GetPrioritiesError>> {
38
39    let uri_str = format!("{}/rest/api/2/priority", configuration.base_path);
40    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
41
42    if let Some(ref user_agent) = configuration.user_agent {
43        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
44    }
45    if let Some(ref token) = configuration.oauth_access_token {
46        req_builder = req_builder.bearer_auth(token.to_owned());
47    };
48    if let Some(ref auth_conf) = configuration.basic_auth {
49        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
50    };
51
52    let req = req_builder.build()?;
53    let resp = configuration.client.execute(req).await?;
54
55    let status = resp.status();
56
57    if !status.is_client_error() && !status.is_server_error() {
58        let content = resp.text().await?;
59        serde_json::from_str(&content).map_err(Error::from)
60    } else {
61        let content = resp.text().await?;
62        let entity: Option<GetPrioritiesError> = serde_json::from_str(&content).ok();
63        Err(Error::ResponseError(ResponseContent { status, content, entity }))
64    }
65}
66
67/// Returns an issue priority.  **[Permissions](#permissions) required:** Permission to access Jira.
68pub async fn get_priority(configuration: &configuration::Configuration, id: &str) -> Result<models::Priority, Error<GetPriorityError>> {
69    // add a prefix to parameters to efficiently prevent name collisions
70    let p_id = id;
71
72    let uri_str = format!("{}/rest/api/2/priority/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
73    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
74
75    if let Some(ref user_agent) = configuration.user_agent {
76        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
77    }
78    if let Some(ref token) = configuration.oauth_access_token {
79        req_builder = req_builder.bearer_auth(token.to_owned());
80    };
81    if let Some(ref auth_conf) = configuration.basic_auth {
82        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
83    };
84
85    let req = req_builder.build()?;
86    let resp = configuration.client.execute(req).await?;
87
88    let status = resp.status();
89
90    if !status.is_client_error() && !status.is_server_error() {
91        let content = resp.text().await?;
92        serde_json::from_str(&content).map_err(Error::from)
93    } else {
94        let content = resp.text().await?;
95        let entity: Option<GetPriorityError> = serde_json::from_str(&content).ok();
96        Err(Error::ResponseError(ResponseContent { status, content, entity }))
97    }
98}
99