1use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17#[derive(Clone, Debug, Default)]
19pub struct DeleteWebhookByIdParams {
20 pub container_for_webhook_ids: crate::models::ContainerForWebhookIds
21}
22
23#[derive(Clone, Debug, Default)]
25pub struct GetDynamicWebhooksForAppParams {
26 pub start_at: Option<i64>,
28 pub max_results: Option<i32>
30}
31
32#[derive(Clone, Debug, Default)]
34pub struct GetFailedWebhooksParams {
35 pub max_results: Option<i32>,
37 pub after: Option<i64>
39}
40
41#[derive(Clone, Debug, Default)]
43pub struct RefreshWebhooksParams {
44 pub container_for_webhook_ids: crate::models::ContainerForWebhookIds
45}
46
47#[derive(Clone, Debug, Default)]
49pub struct RegisterDynamicWebhooksParams {
50 pub webhook_registration_details: crate::models::WebhookRegistrationDetails
51}
52
53
54#[derive(Debug, Clone, Serialize, Deserialize)]
56#[serde(untagged)]
57pub enum DeleteWebhookByIdError {
58 Status400(crate::models::ErrorCollection),
59 Status403(crate::models::ErrorCollection),
60 UnknownValue(serde_json::Value),
61}
62
63#[derive(Debug, Clone, Serialize, Deserialize)]
65#[serde(untagged)]
66pub enum GetDynamicWebhooksForAppError {
67 Status400(crate::models::ErrorCollection),
68 Status403(crate::models::ErrorCollection),
69 UnknownValue(serde_json::Value),
70}
71
72#[derive(Debug, Clone, Serialize, Deserialize)]
74#[serde(untagged)]
75pub enum GetFailedWebhooksError {
76 Status400(crate::models::ErrorCollection),
77 Status403(crate::models::ErrorCollection),
78 UnknownValue(serde_json::Value),
79}
80
81#[derive(Debug, Clone, Serialize, Deserialize)]
83#[serde(untagged)]
84pub enum RefreshWebhooksError {
85 Status400(crate::models::ErrorCollection),
86 Status403(crate::models::ErrorCollection),
87 UnknownValue(serde_json::Value),
88}
89
90#[derive(Debug, Clone, Serialize, Deserialize)]
92#[serde(untagged)]
93pub enum RegisterDynamicWebhooksError {
94 Status400(crate::models::ErrorCollection),
95 Status403(crate::models::ErrorCollection),
96 UnknownValue(serde_json::Value),
97}
98
99
100pub async fn delete_webhook_by_id(configuration: &configuration::Configuration, params: DeleteWebhookByIdParams) -> Result<(), Error<DeleteWebhookByIdError>> {
102 let local_var_configuration = configuration;
103
104 let container_for_webhook_ids = params.container_for_webhook_ids;
106
107
108 let local_var_client = &local_var_configuration.client;
109
110 let local_var_uri_str = format!("{}/rest/api/2/webhook", local_var_configuration.base_path);
111 let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
112
113 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
114 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
115 }
116 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
117 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
118 };
119 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
120 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
121 };
122 local_var_req_builder = local_var_req_builder.json(&container_for_webhook_ids);
123
124 let local_var_req = local_var_req_builder.build()?;
125 let local_var_resp = local_var_client.execute(local_var_req).await?;
126
127 let local_var_status = local_var_resp.status();
128 let local_var_content = local_var_resp.text().await?;
129
130 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
131 Ok(())
132 } else {
133 let local_var_entity: Option<DeleteWebhookByIdError> = serde_json::from_str(&local_var_content).ok();
134 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
135 Err(Error::ResponseError(local_var_error))
136 }
137}
138
139pub async fn get_dynamic_webhooks_for_app(configuration: &configuration::Configuration, params: GetDynamicWebhooksForAppParams) -> Result<crate::models::PageBeanWebhook, Error<GetDynamicWebhooksForAppError>> {
141 let local_var_configuration = configuration;
142
143 let start_at = params.start_at;
145 let max_results = params.max_results;
146
147
148 let local_var_client = &local_var_configuration.client;
149
150 let local_var_uri_str = format!("{}/rest/api/2/webhook", local_var_configuration.base_path);
151 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
152
153 if let Some(ref local_var_str) = start_at {
154 local_var_req_builder = local_var_req_builder.query(&[("startAt", &local_var_str.to_string())]);
155 }
156 if let Some(ref local_var_str) = max_results {
157 local_var_req_builder = local_var_req_builder.query(&[("maxResults", &local_var_str.to_string())]);
158 }
159 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
160 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
161 }
162 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
163 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
164 };
165 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
166 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
167 };
168
169 let local_var_req = local_var_req_builder.build()?;
170 let local_var_resp = local_var_client.execute(local_var_req).await?;
171
172 let local_var_status = local_var_resp.status();
173 let local_var_content = local_var_resp.text().await?;
174
175 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
176 serde_json::from_str(&local_var_content).map_err(Error::from)
177 } else {
178 let local_var_entity: Option<GetDynamicWebhooksForAppError> = serde_json::from_str(&local_var_content).ok();
179 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
180 Err(Error::ResponseError(local_var_error))
181 }
182}
183
184pub async fn get_failed_webhooks(configuration: &configuration::Configuration, params: GetFailedWebhooksParams) -> Result<crate::models::FailedWebhooks, Error<GetFailedWebhooksError>> {
186 let local_var_configuration = configuration;
187
188 let max_results = params.max_results;
190 let after = params.after;
191
192
193 let local_var_client = &local_var_configuration.client;
194
195 let local_var_uri_str = format!("{}/rest/api/2/webhook/failed", local_var_configuration.base_path);
196 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
197
198 if let Some(ref local_var_str) = max_results {
199 local_var_req_builder = local_var_req_builder.query(&[("maxResults", &local_var_str.to_string())]);
200 }
201 if let Some(ref local_var_str) = after {
202 local_var_req_builder = local_var_req_builder.query(&[("after", &local_var_str.to_string())]);
203 }
204 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
205 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
206 }
207 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
208 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
209 };
210 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
211 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
212 };
213
214 let local_var_req = local_var_req_builder.build()?;
215 let local_var_resp = local_var_client.execute(local_var_req).await?;
216
217 let local_var_status = local_var_resp.status();
218 let local_var_content = local_var_resp.text().await?;
219
220 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
221 serde_json::from_str(&local_var_content).map_err(Error::from)
222 } else {
223 let local_var_entity: Option<GetFailedWebhooksError> = serde_json::from_str(&local_var_content).ok();
224 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
225 Err(Error::ResponseError(local_var_error))
226 }
227}
228
229pub async fn refresh_webhooks(configuration: &configuration::Configuration, params: RefreshWebhooksParams) -> Result<crate::models::WebhooksExpirationDate, Error<RefreshWebhooksError>> {
231 let local_var_configuration = configuration;
232
233 let container_for_webhook_ids = params.container_for_webhook_ids;
235
236
237 let local_var_client = &local_var_configuration.client;
238
239 let local_var_uri_str = format!("{}/rest/api/2/webhook/refresh", local_var_configuration.base_path);
240 let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
241
242 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
243 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
244 }
245 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
246 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
247 };
248 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
249 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
250 };
251 local_var_req_builder = local_var_req_builder.json(&container_for_webhook_ids);
252
253 let local_var_req = local_var_req_builder.build()?;
254 let local_var_resp = local_var_client.execute(local_var_req).await?;
255
256 let local_var_status = local_var_resp.status();
257 let local_var_content = local_var_resp.text().await?;
258
259 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
260 serde_json::from_str(&local_var_content).map_err(Error::from)
261 } else {
262 let local_var_entity: Option<RefreshWebhooksError> = serde_json::from_str(&local_var_content).ok();
263 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
264 Err(Error::ResponseError(local_var_error))
265 }
266}
267
268pub async fn register_dynamic_webhooks(configuration: &configuration::Configuration, params: RegisterDynamicWebhooksParams) -> Result<crate::models::ContainerForRegisteredWebhooks, Error<RegisterDynamicWebhooksError>> {
270 let local_var_configuration = configuration;
271
272 let webhook_registration_details = params.webhook_registration_details;
274
275
276 let local_var_client = &local_var_configuration.client;
277
278 let local_var_uri_str = format!("{}/rest/api/2/webhook", local_var_configuration.base_path);
279 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
280
281 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
282 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
283 }
284 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
285 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
286 };
287 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
288 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
289 };
290 local_var_req_builder = local_var_req_builder.json(&webhook_registration_details);
291
292 let local_var_req = local_var_req_builder.build()?;
293 let local_var_resp = local_var_client.execute(local_var_req).await?;
294
295 let local_var_status = local_var_resp.status();
296 let local_var_content = local_var_resp.text().await?;
297
298 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
299 serde_json::from_str(&local_var_content).map_err(Error::from)
300 } else {
301 let local_var_entity: Option<RegisterDynamicWebhooksError> = serde_json::from_str(&local_var_content).ok();
302 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
303 Err(Error::ResponseError(local_var_error))
304 }
305}
306