hi_jira2/apis/
webhooks_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;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17/// struct for passing parameters to the method [`delete_webhook_by_id`]
18#[derive(Clone, Debug, Default)]
19pub struct DeleteWebhookByIdParams {
20    pub container_for_webhook_ids: crate::models::ContainerForWebhookIds
21}
22
23/// struct for passing parameters to the method [`get_dynamic_webhooks_for_app`]
24#[derive(Clone, Debug, Default)]
25pub struct GetDynamicWebhooksForAppParams {
26    /// The index of the first item to return in a page of results (page offset).
27    pub start_at: Option<i64>,
28    /// The maximum number of items to return per page.
29    pub max_results: Option<i32>
30}
31
32/// struct for passing parameters to the method [`get_failed_webhooks`]
33#[derive(Clone, Debug, Default)]
34pub struct GetFailedWebhooksParams {
35    /// The maximum number of webhooks to return per page. If obeying the maxResults directive would result in records with the same failure time being split across pages, the directive is ignored and all records with the same failure time included on the page.
36    pub max_results: Option<i32>,
37    /// The time after which any webhook failure must have occurred for the record to be returned, expressed as milliseconds since the UNIX epoch.
38    pub after: Option<i64>
39}
40
41/// struct for passing parameters to the method [`refresh_webhooks`]
42#[derive(Clone, Debug, Default)]
43pub struct RefreshWebhooksParams {
44    pub container_for_webhook_ids: crate::models::ContainerForWebhookIds
45}
46
47/// struct for passing parameters to the method [`register_dynamic_webhooks`]
48#[derive(Clone, Debug, Default)]
49pub struct RegisterDynamicWebhooksParams {
50    pub webhook_registration_details: crate::models::WebhookRegistrationDetails
51}
52
53
54/// struct for typed errors of method [`delete_webhook_by_id`]
55#[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/// struct for typed errors of method [`get_dynamic_webhooks_for_app`]
64#[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/// struct for typed errors of method [`get_failed_webhooks`]
73#[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/// struct for typed errors of method [`refresh_webhooks`]
82#[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/// struct for typed errors of method [`register_dynamic_webhooks`]
91#[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
100/// Removes webhooks by ID. Only webhooks registered by the calling app are removed. If webhooks created by other apps are specified, they are ignored.  **[Permissions](#permissions) required:** Only [Connect](https://developer.atlassian.com/cloud/jira/platform/#connect-apps) and [OAuth 2.0](https://developer.atlassian.com/cloud/jira/platform/oauth-2-3lo-apps) apps can use this operation.
101pub async fn delete_webhook_by_id(configuration: &configuration::Configuration, params: DeleteWebhookByIdParams) -> Result<(), Error<DeleteWebhookByIdError>> {
102    let local_var_configuration = configuration;
103
104    // unbox the parameters
105    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
139/// Returns a [paginated](#pagination) list of the webhooks registered by the calling app.  **[Permissions](#permissions) required:** Only [Connect](https://developer.atlassian.com/cloud/jira/platform/#connect-apps) and [OAuth 2.0](https://developer.atlassian.com/cloud/jira/platform/oauth-2-3lo-apps) apps can use this operation.
140pub 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    // unbox the parameters
144    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
184/// Returns webhooks that have recently failed to be delivered to the requesting app after the maximum number of retries.  After 72 hours the failure may no longer be returned by this operation.  The oldest failure is returned first.  This method uses a cursor-based pagination. To request the next page use the failure time of the last webhook on the list as the `failedAfter` value or use the URL provided in `next`.  **[Permissions](#permissions) required:** Only [Connect apps](https://developer.atlassian.com/cloud/jira/platform/index/#connect-apps) can use this operation.
185pub async fn get_failed_webhooks(configuration: &configuration::Configuration, params: GetFailedWebhooksParams) -> Result<crate::models::FailedWebhooks, Error<GetFailedWebhooksError>> {
186    let local_var_configuration = configuration;
187
188    // unbox the parameters
189    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
229/// Extends the life of webhook. Webhooks registered through the REST API expire after 30 days. Call this operation to keep them alive.  Unrecognized webhook IDs (those that are not found or belong to other apps) are ignored.  **[Permissions](#permissions) required:** Only [Connect](https://developer.atlassian.com/cloud/jira/platform/#connect-apps) and [OAuth 2.0](https://developer.atlassian.com/cloud/jira/platform/oauth-2-3lo-apps) apps can use this operation.
230pub async fn refresh_webhooks(configuration: &configuration::Configuration, params: RefreshWebhooksParams) -> Result<crate::models::WebhooksExpirationDate, Error<RefreshWebhooksError>> {
231    let local_var_configuration = configuration;
232
233    // unbox the parameters
234    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
268/// Registers webhooks.  **[Permissions](#permissions) required:** Only [Connect](https://developer.atlassian.com/cloud/jira/platform/#connect-apps) and [OAuth 2.0](https://developer.atlassian.com/cloud/jira/platform/oauth-2-3lo-apps) apps can use this operation.
269pub async fn register_dynamic_webhooks(configuration: &configuration::Configuration, params: RegisterDynamicWebhooksParams) -> Result<crate::models::ContainerForRegisteredWebhooks, Error<RegisterDynamicWebhooksError>> {
270    let local_var_configuration = configuration;
271
272    // unbox the parameters
273    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