jira2/apis/
issue_votes_api.rs1use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17#[derive(Clone, Debug, Default)]
19pub struct AddVoteParams {
20 pub issue_id_or_key: String
22}
23
24#[derive(Clone, Debug, Default)]
26pub struct GetVotesParams {
27 pub issue_id_or_key: String
29}
30
31#[derive(Clone, Debug, Default)]
33pub struct RemoveVoteParams {
34 pub issue_id_or_key: String
36}
37
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum AddVoteError {
43 Status401(),
44 Status404(),
45 UnknownValue(serde_json::Value),
46}
47
48#[derive(Debug, Clone, Serialize, Deserialize)]
50#[serde(untagged)]
51pub enum GetVotesError {
52 Status401(),
53 Status404(),
54 UnknownValue(serde_json::Value),
55}
56
57#[derive(Debug, Clone, Serialize, Deserialize)]
59#[serde(untagged)]
60pub enum RemoveVoteError {
61 Status401(),
62 Status404(),
63 UnknownValue(serde_json::Value),
64}
65
66
67pub async fn add_vote(configuration: &configuration::Configuration, params: AddVoteParams) -> Result<serde_json::Value, Error<AddVoteError>> {
69 let local_var_configuration = configuration;
70
71 let issue_id_or_key = params.issue_id_or_key;
73
74
75 let local_var_client = &local_var_configuration.client;
76
77 let local_var_uri_str = format!("{}/rest/api/2/issue/{issueIdOrKey}/votes", local_var_configuration.base_path, issueIdOrKey=crate::apis::urlencode(issue_id_or_key));
78 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
79
80 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
81 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
82 }
83 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
84 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
85 };
86 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
87 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
88 };
89
90 let local_var_req = local_var_req_builder.build()?;
91 let local_var_resp = local_var_client.execute(local_var_req).await?;
92
93 let local_var_status = local_var_resp.status();
94 let local_var_content = local_var_resp.text().await?;
95
96 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
97 serde_json::from_str(&local_var_content).map_err(Error::from)
98 } else {
99 let local_var_entity: Option<AddVoteError> = serde_json::from_str(&local_var_content).ok();
100 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
101 Err(Error::ResponseError(local_var_error))
102 }
103}
104
105pub async fn get_votes(configuration: &configuration::Configuration, params: GetVotesParams) -> Result<crate::models::Votes, Error<GetVotesError>> {
107 let local_var_configuration = configuration;
108
109 let issue_id_or_key = params.issue_id_or_key;
111
112
113 let local_var_client = &local_var_configuration.client;
114
115 let local_var_uri_str = format!("{}/rest/api/2/issue/{issueIdOrKey}/votes", local_var_configuration.base_path, issueIdOrKey=crate::apis::urlencode(issue_id_or_key));
116 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
117
118 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
119 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
120 }
121 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
122 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
123 };
124 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
125 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
126 };
127
128 let local_var_req = local_var_req_builder.build()?;
129 let local_var_resp = local_var_client.execute(local_var_req).await?;
130
131 let local_var_status = local_var_resp.status();
132 let local_var_content = local_var_resp.text().await?;
133
134 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
135 serde_json::from_str(&local_var_content).map_err(Error::from)
136 } else {
137 let local_var_entity: Option<GetVotesError> = serde_json::from_str(&local_var_content).ok();
138 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
139 Err(Error::ResponseError(local_var_error))
140 }
141}
142
143pub async fn remove_vote(configuration: &configuration::Configuration, params: RemoveVoteParams) -> Result<(), Error<RemoveVoteError>> {
145 let local_var_configuration = configuration;
146
147 let issue_id_or_key = params.issue_id_or_key;
149
150
151 let local_var_client = &local_var_configuration.client;
152
153 let local_var_uri_str = format!("{}/rest/api/2/issue/{issueIdOrKey}/votes", local_var_configuration.base_path, issueIdOrKey=crate::apis::urlencode(issue_id_or_key));
154 let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
155
156 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
157 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
158 }
159 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
160 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
161 };
162 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
163 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
164 };
165
166 let local_var_req = local_var_req_builder.build()?;
167 let local_var_resp = local_var_client.execute(local_var_req).await?;
168
169 let local_var_status = local_var_resp.status();
170 let local_var_content = local_var_resp.text().await?;
171
172 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
173 Ok(())
174 } else {
175 let local_var_entity: Option<RemoveVoteError> = serde_json::from_str(&local_var_content).ok();
176 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
177 Err(Error::ResponseError(local_var_error))
178 }
179}
180