jira_api_v2/apis/
project_features_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_features_for_project`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetFeaturesForProjectError {
22    Status400(),
23    Status401(),
24    Status403(),
25    Status404(),
26    UnknownValue(serde_json::Value),
27}
28
29/// struct for typed errors of method [`toggle_feature_for_project`]
30#[derive(Debug, Clone, Serialize, Deserialize)]
31#[serde(untagged)]
32pub enum ToggleFeatureForProjectError {
33    Status400(),
34    Status401(),
35    Status403(),
36    Status404(),
37    UnknownValue(serde_json::Value),
38}
39
40
41/// Returns the list of features for a project. The project must be a [company-managed](https://support.atlassian.com/jira-service-management-cloud/docs/learn-the-differences-between-classic-and-next-gen-projects/) project.
42pub async fn get_features_for_project(configuration: &configuration::Configuration, project_id_or_key: &str) -> Result<models::ProjectFeaturesResponse, Error<GetFeaturesForProjectError>> {
43    // add a prefix to parameters to efficiently prevent name collisions
44    let p_project_id_or_key = project_id_or_key;
45
46    let uri_str = format!("{}/rest/api/2/project/{projectIdOrKey}/features", configuration.base_path, projectIdOrKey=crate::apis::urlencode(p_project_id_or_key));
47    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
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<GetFeaturesForProjectError> = serde_json::from_str(&content).ok();
70        Err(Error::ResponseError(ResponseContent { status, content, entity }))
71    }
72}
73
74/// Changes the state of a feature to ENABLED or DISABLED for the project. The project must be a [company-managed](https://support.atlassian.com/jira-service-management-cloud/docs/learn-the-differences-between-classic-and-next-gen-projects/) project.
75pub async fn toggle_feature_for_project(configuration: &configuration::Configuration, project_id_or_key: &str, feature_key: &str, project_feature_toggle_request: models::ProjectFeatureToggleRequest) -> Result<models::ProjectFeaturesResponse, Error<ToggleFeatureForProjectError>> {
76    // add a prefix to parameters to efficiently prevent name collisions
77    let p_project_id_or_key = project_id_or_key;
78    let p_feature_key = feature_key;
79    let p_project_feature_toggle_request = project_feature_toggle_request;
80
81    let uri_str = format!("{}/rest/api/2/project/{projectIdOrKey}/features/{featureKey}", configuration.base_path, projectIdOrKey=crate::apis::urlencode(p_project_id_or_key), featureKey=crate::apis::urlencode(p_feature_key));
82    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
83
84    if let Some(ref user_agent) = configuration.user_agent {
85        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
86    }
87    if let Some(ref token) = configuration.oauth_access_token {
88        req_builder = req_builder.bearer_auth(token.to_owned());
89    };
90    if let Some(ref auth_conf) = configuration.basic_auth {
91        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
92    };
93    req_builder = req_builder.json(&p_project_feature_toggle_request);
94
95    let req = req_builder.build()?;
96    let resp = configuration.client.execute(req).await?;
97
98    let status = resp.status();
99
100    if !status.is_client_error() && !status.is_server_error() {
101        let content = resp.text().await?;
102        serde_json::from_str(&content).map_err(Error::from)
103    } else {
104        let content = resp.text().await?;
105        let entity: Option<ToggleFeatureForProjectError> = serde_json::from_str(&content).ok();
106        Err(Error::ResponseError(ResponseContent { status, content, entity }))
107    }
108}
109