jira_api_v2/apis/
tasks_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 [`cancel_task`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CancelTaskError {
22    Status400(Vec<String>),
23    Status401(Vec<String>),
24    Status403(Vec<String>),
25    Status404(Vec<String>),
26    UnknownValue(serde_json::Value),
27}
28
29/// struct for typed errors of method [`get_task`]
30#[derive(Debug, Clone, Serialize, Deserialize)]
31#[serde(untagged)]
32pub enum GetTaskError {
33    Status401(),
34    Status403(),
35    Status404(),
36    UnknownValue(serde_json::Value),
37}
38
39
40/// Cancels a task.  **[Permissions](#permissions) required:** either of:   *  *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).  *  Creator of the task.
41pub async fn cancel_task(configuration: &configuration::Configuration, task_id: &str) -> Result<serde_json::Value, Error<CancelTaskError>> {
42    // add a prefix to parameters to efficiently prevent name collisions
43    let p_task_id = task_id;
44
45    let uri_str = format!("{}/rest/api/2/task/{taskId}/cancel", configuration.base_path, taskId=crate::apis::urlencode(p_task_id));
46    let mut req_builder = configuration.client.request(reqwest::Method::POST, &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<CancelTaskError> = serde_json::from_str(&content).ok();
69        Err(Error::ResponseError(ResponseContent { status, content, entity }))
70    }
71}
72
73/// Returns the status of a [long-running asynchronous task](#async).  When a task has finished, this operation returns the JSON blob applicable to the task. See the documentation of the operation that created the task for details. Task details are not permanently retained. As of September 2019, details are retained for 14 days although this period may change without notice.  **[Permissions](#permissions) required:** either of:   *  *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).  *  Creator of the task.
74pub async fn get_task(configuration: &configuration::Configuration, task_id: &str) -> Result<models::TaskProgressBeanObject, Error<GetTaskError>> {
75    // add a prefix to parameters to efficiently prevent name collisions
76    let p_task_id = task_id;
77
78    let uri_str = format!("{}/rest/api/2/task/{taskId}", configuration.base_path, taskId=crate::apis::urlencode(p_task_id));
79    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
80
81    if let Some(ref user_agent) = configuration.user_agent {
82        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
83    }
84    if let Some(ref token) = configuration.oauth_access_token {
85        req_builder = req_builder.bearer_auth(token.to_owned());
86    };
87    if let Some(ref auth_conf) = configuration.basic_auth {
88        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
89    };
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<GetTaskError> = serde_json::from_str(&content).ok();
102        Err(Error::ResponseError(ResponseContent { status, content, entity }))
103    }
104}
105