jira/gen/apis/
workflows_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
11use super::{configuration, Error};
12use crate::gen::apis::ResponseContent;
13use crate::gen::models;
14
15/// struct for passing parameters to the method `get_all_workflows`
16#[derive(Clone, Debug)]
17pub struct GetAllWorkflowsParams {
18    /// The name of the workflow to be returned. Only one workflow can be specified.
19    pub workflow_name: Option<String>,
20}
21
22/// struct for passing parameters to the method `get_workflows_paginated`
23#[derive(Clone, Debug)]
24pub struct GetWorkflowsPaginatedParams {
25    /// The index of the first item to return in a page of results (page offset).
26    pub start_at: Option<i64>,
27    /// The maximum number of items to return per page.
28    pub max_results: Option<i32>,
29    /// The name of a workflow to return.
30    pub workflow_name: Option<Vec<String>>,
31    /// Use [expand](#expansion) to include additional information in the response. This parameter accepts a comma-separated list. Expand options include:   *  `transitions` For each workflow, returns information about the transitions inside the workflow.  *  `transitions.rules` For each workflow transition, returns information about its rules. Transitions are included automatically if this expand is requested.  *  `statuses` For each workflow, returns information about the statuses inside the workflow.  *  `statuses.properties` For each workflow status, returns information about its properties. Statuses are included automatically if this expand is requested.
32    pub expand: Option<String>,
33}
34
35/// struct for typed errors of method `get_all_workflows`
36#[derive(Debug, Clone, Serialize, Deserialize)]
37#[serde(untagged)]
38pub enum GetAllWorkflowsError {
39    Status401(),
40    UnknownValue(serde_json::Value),
41}
42
43/// struct for typed errors of method `get_workflows_paginated`
44#[derive(Debug, Clone, Serialize, Deserialize)]
45#[serde(untagged)]
46pub enum GetWorkflowsPaginatedError {
47    Status401(),
48    Status403(models::ErrorCollection),
49    UnknownValue(serde_json::Value),
50}
51
52/// Returns all workflows in Jira or a workflow. Deprecated, use [Get workflows paginated](#api-rest-api-3-workflow-search-get).  If the `workflowName` parameter is specified, the workflow is returned as an object (not in an array). Otherwise, an array of workflow objects is returned.  **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
53pub async fn get_all_workflows(
54    configuration: &configuration::Configuration,
55    params: GetAllWorkflowsParams,
56) -> Result<Vec<models::DeprecatedWorkflow>, Error<GetAllWorkflowsError>> {
57    // unbox the parameters
58    let workflow_name = params.workflow_name;
59
60    let local_var_client = &configuration.client;
61
62    let local_var_uri_str = format!("{}/rest/api/3/workflow", configuration.base_path);
63    let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
64
65    if let Some(ref local_var_str) = workflow_name {
66        local_var_req_builder =
67            local_var_req_builder.query(&[("workflowName", &local_var_str.to_string())]);
68    }
69    if let Some(ref local_var_user_agent) = configuration.user_agent {
70        local_var_req_builder =
71            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
72    }
73    if let Some(ref local_var_token) = configuration.oauth_access_token {
74        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
75    };
76    if let Some(ref local_var_auth_conf) = configuration.basic_auth {
77        local_var_req_builder = local_var_req_builder.basic_auth(
78            local_var_auth_conf.0.to_owned(),
79            local_var_auth_conf.1.to_owned(),
80        );
81    };
82
83    let local_var_req = local_var_req_builder.build()?;
84    let local_var_resp = local_var_client.execute(local_var_req).await?;
85
86    let local_var_status = local_var_resp.status();
87    let local_var_content = local_var_resp.text().await?;
88
89    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
90        serde_json::from_str(&local_var_content).map_err(Error::from)
91    } else {
92        let local_var_entity: Option<GetAllWorkflowsError> =
93            serde_json::from_str(&local_var_content).ok();
94        let local_var_error = ResponseContent {
95            status: local_var_status,
96            content: local_var_content,
97            entity: local_var_entity,
98        };
99        Err(Error::ResponseError(local_var_error))
100    }
101}
102
103/// Returns a [paginated](#pagination) list of published classic workflows. When workflow names are specified, details of those workflows are returned. Otherwise, all published classic workflows are returned.  This operation does not return next-gen workflows.  **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
104pub async fn get_workflows_paginated(
105    configuration: &configuration::Configuration,
106    params: GetWorkflowsPaginatedParams,
107) -> Result<models::PageBeanWorkflow, Error<GetWorkflowsPaginatedError>> {
108    // unbox the parameters
109    let start_at = params.start_at;
110    let max_results = params.max_results;
111    let workflow_name = params.workflow_name;
112    let expand = params.expand;
113
114    let local_var_client = &configuration.client;
115
116    let local_var_uri_str = format!("{}/rest/api/3/workflow/search", configuration.base_path);
117    let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
118
119    if let Some(ref local_var_str) = start_at {
120        local_var_req_builder =
121            local_var_req_builder.query(&[("startAt", &local_var_str.to_string())]);
122    }
123    if let Some(ref local_var_str) = max_results {
124        local_var_req_builder =
125            local_var_req_builder.query(&[("maxResults", &local_var_str.to_string())]);
126    }
127    if let Some(ref local_var_str) = workflow_name {
128        local_var_req_builder = local_var_req_builder.query(&[(
129            "workflowName",
130            &local_var_str
131                .into_iter()
132                .map(|p| p.to_string())
133                .collect::<Vec<String>>()
134                .join(",")
135                .to_string(),
136        )]);
137    }
138    if let Some(ref local_var_str) = expand {
139        local_var_req_builder =
140            local_var_req_builder.query(&[("expand", &local_var_str.to_string())]);
141    }
142    if let Some(ref local_var_user_agent) = configuration.user_agent {
143        local_var_req_builder =
144            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
145    }
146    if let Some(ref local_var_token) = configuration.oauth_access_token {
147        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
148    };
149    if let Some(ref local_var_auth_conf) = configuration.basic_auth {
150        local_var_req_builder = local_var_req_builder.basic_auth(
151            local_var_auth_conf.0.to_owned(),
152            local_var_auth_conf.1.to_owned(),
153        );
154    };
155
156    let local_var_req = local_var_req_builder.build()?;
157    let local_var_resp = local_var_client.execute(local_var_req).await?;
158
159    let local_var_status = local_var_resp.status();
160    let local_var_content = local_var_resp.text().await?;
161
162    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
163        serde_json::from_str(&local_var_content).map_err(Error::from)
164    } else {
165        let local_var_entity: Option<GetWorkflowsPaginatedError> =
166            serde_json::from_str(&local_var_content).ok();
167        let local_var_error = ResponseContent {
168            status: local_var_status,
169            content: local_var_content,
170            entity: local_var_entity,
171        };
172        Err(Error::ResponseError(local_var_error))
173    }
174}