hi_jira2/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;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17/// struct for passing parameters to the method [`cancel_task`]
18#[derive(Clone, Debug, Default)]
19pub struct CancelTaskParams {
20    /// The ID of the task.
21    pub task_id: String
22}
23
24/// struct for passing parameters to the method [`get_task`]
25#[derive(Clone, Debug, Default)]
26pub struct GetTaskParams {
27    /// The ID of the task.
28    pub task_id: String
29}
30
31
32/// struct for typed errors of method [`cancel_task`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum CancelTaskError {
36    Status400(Vec<String>),
37    Status401(Vec<String>),
38    Status403(Vec<String>),
39    Status404(Vec<String>),
40    UnknownValue(serde_json::Value),
41}
42
43/// struct for typed errors of method [`get_task`]
44#[derive(Debug, Clone, Serialize, Deserialize)]
45#[serde(untagged)]
46pub enum GetTaskError {
47    Status401(),
48    Status403(),
49    Status404(),
50    UnknownValue(serde_json::Value),
51}
52
53
54/// Cancels a task.  **[Permissions](#permissions) required:** either of:   *  *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).  *  Creator of the task.
55pub async fn cancel_task(configuration: &configuration::Configuration, params: CancelTaskParams) -> Result<serde_json::Value, Error<CancelTaskError>> {
56    let local_var_configuration = configuration;
57
58    // unbox the parameters
59    let task_id = params.task_id;
60
61
62    let local_var_client = &local_var_configuration.client;
63
64    let local_var_uri_str = format!("{}/rest/api/2/task/{taskId}/cancel", local_var_configuration.base_path, taskId=crate::apis::urlencode(task_id));
65    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
66
67    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
68        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
69    }
70    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
71        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
72    };
73    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
74        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
75    };
76
77    let local_var_req = local_var_req_builder.build()?;
78    let local_var_resp = local_var_client.execute(local_var_req).await?;
79
80    let local_var_status = local_var_resp.status();
81    let local_var_content = local_var_resp.text().await?;
82
83    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
84        serde_json::from_str(&local_var_content).map_err(Error::from)
85    } else {
86        let local_var_entity: Option<CancelTaskError> = serde_json::from_str(&local_var_content).ok();
87        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
88        Err(Error::ResponseError(local_var_error))
89    }
90}
91
92/// 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.
93pub async fn get_task(configuration: &configuration::Configuration, params: GetTaskParams) -> Result<crate::models::TaskProgressBeanObject, Error<GetTaskError>> {
94    let local_var_configuration = configuration;
95
96    // unbox the parameters
97    let task_id = params.task_id;
98
99
100    let local_var_client = &local_var_configuration.client;
101
102    let local_var_uri_str = format!("{}/rest/api/2/task/{taskId}", local_var_configuration.base_path, taskId=crate::apis::urlencode(task_id));
103    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
104
105    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
106        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
107    }
108    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
109        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
110    };
111    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
112        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
113    };
114
115    let local_var_req = local_var_req_builder.build()?;
116    let local_var_resp = local_var_client.execute(local_var_req).await?;
117
118    let local_var_status = local_var_resp.status();
119    let local_var_content = local_var_resp.text().await?;
120
121    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
122        serde_json::from_str(&local_var_content).map_err(Error::from)
123    } else {
124        let local_var_entity: Option<GetTaskError> = serde_json::from_str(&local_var_content).ok();
125        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
126        Err(Error::ResponseError(local_var_error))
127    }
128}
129