jira2/apis/
project_features_api.rs1use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17#[derive(Clone, Debug, Default)]
19pub struct GetFeaturesForProjectParams {
20 pub project_id_or_key: String
22}
23
24#[derive(Clone, Debug, Default)]
26pub struct ToggleFeatureForProjectParams {
27 pub project_id_or_key: String,
29 pub feature_key: String,
31 pub project_feature_state: crate::models::ProjectFeatureState
33}
34
35
36#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(untagged)]
39pub enum GetFeaturesForProjectError {
40 Status400(),
41 Status401(),
42 Status403(),
43 Status404(),
44 UnknownValue(serde_json::Value),
45}
46
47#[derive(Debug, Clone, Serialize, Deserialize)]
49#[serde(untagged)]
50pub enum ToggleFeatureForProjectError {
51 Status400(),
52 Status401(),
53 Status403(),
54 Status404(),
55 UnknownValue(serde_json::Value),
56}
57
58
59pub async fn get_features_for_project(configuration: &configuration::Configuration, params: GetFeaturesForProjectParams) -> Result<crate::models::ContainerForProjectFeatures, Error<GetFeaturesForProjectError>> {
61 let local_var_configuration = configuration;
62
63 let project_id_or_key = params.project_id_or_key;
65
66
67 let local_var_client = &local_var_configuration.client;
68
69 let local_var_uri_str = format!("{}/rest/api/2/project/{projectIdOrKey}/features", local_var_configuration.base_path, projectIdOrKey=crate::apis::urlencode(project_id_or_key));
70 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
71
72 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
73 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
74 }
75 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
76 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
77 };
78 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
79 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
80 };
81
82 let local_var_req = local_var_req_builder.build()?;
83 let local_var_resp = local_var_client.execute(local_var_req).await?;
84
85 let local_var_status = local_var_resp.status();
86 let local_var_content = local_var_resp.text().await?;
87
88 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
89 serde_json::from_str(&local_var_content).map_err(Error::from)
90 } else {
91 let local_var_entity: Option<GetFeaturesForProjectError> = serde_json::from_str(&local_var_content).ok();
92 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
93 Err(Error::ResponseError(local_var_error))
94 }
95}
96
97pub async fn toggle_feature_for_project(configuration: &configuration::Configuration, params: ToggleFeatureForProjectParams) -> Result<crate::models::ContainerForProjectFeatures, Error<ToggleFeatureForProjectError>> {
99 let local_var_configuration = configuration;
100
101 let project_id_or_key = params.project_id_or_key;
103 let feature_key = params.feature_key;
104 let project_feature_state = params.project_feature_state;
105
106
107 let local_var_client = &local_var_configuration.client;
108
109 let local_var_uri_str = format!("{}/rest/api/2/project/{projectIdOrKey}/features/{featureKey}", local_var_configuration.base_path, projectIdOrKey=crate::apis::urlencode(project_id_or_key), featureKey=crate::apis::urlencode(feature_key));
110 let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
111
112 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
113 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
114 }
115 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
116 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
117 };
118 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
119 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
120 };
121 local_var_req_builder = local_var_req_builder.json(&project_feature_state);
122
123 let local_var_req = local_var_req_builder.build()?;
124 let local_var_resp = local_var_client.execute(local_var_req).await?;
125
126 let local_var_status = local_var_resp.status();
127 let local_var_content = local_var_resp.text().await?;
128
129 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
130 serde_json::from_str(&local_var_content).map_err(Error::from)
131 } else {
132 let local_var_entity: Option<ToggleFeatureForProjectError> = serde_json::from_str(&local_var_content).ok();
133 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
134 Err(Error::ResponseError(local_var_error))
135 }
136}
137