fireblocks_sdk/apis/
webhooks_v2_beta_api.rs

1// Fireblocks API
2//
3// Fireblocks provides a suite of applications to manage digital asset operations and a complete development platform to build your business on the blockchain.  - Visit our website for more information: [Fireblocks Website](https://fireblocks.com) - Visit our developer docs: [Fireblocks DevPortal](https://developers.fireblocks.com)
4//
5// The version of the OpenAPI document: 1.8.0
6// Contact: developers@fireblocks.com
7// Generated by: https://openapi-generator.tech
8
9use {
10    super::{configuration, Error},
11    crate::{
12        apis::{ContentType, ResponseContent},
13        models,
14    },
15    async_trait::async_trait,
16    reqwest,
17    serde::{de::Error as _, Deserialize, Serialize},
18    std::sync::Arc,
19};
20
21#[async_trait]
22pub trait WebhooksV2BetaApi: Send + Sync {
23    /// POST /webhooks
24    ///
25    /// Creates a new webhook, which will be triggered on the specified events
26    /// **Note:**  - This endpoint is currently in beta and might be subject to
27    /// changes.  - This endpoint requires Admin privilege or above due to the
28    /// sensitivity of actions.
29    async fn create_webhook(
30        &self,
31        params: CreateWebhookParams,
32    ) -> Result<models::Webhook, Error<CreateWebhookError>>;
33
34    /// DELETE /webhooks/{webhookId}
35    ///
36    /// Delete a webhook by its id  **Note:**  - This endpoint is currently in
37    /// beta and might be subject to changes.  - This endpoint requires Admin
38    /// privilege or above due to the sensitivity of actions.
39    async fn delete_webhook(
40        &self,
41        params: DeleteWebhookParams,
42    ) -> Result<models::Webhook, Error<DeleteWebhookError>>;
43
44    /// GET /webhooks/{webhookId}/notifications/{notificationId}
45    ///
46    /// Get notification by id **Note:** These endpoints are currently in beta
47    /// and might be subject to changes.
48    async fn get_notification(
49        &self,
50        params: GetNotificationParams,
51    ) -> Result<models::NotificationWithData, Error<GetNotificationError>>;
52
53    /// GET /webhooks/{webhookId}/notifications
54    ///
55    /// Get all notifications by webhook id (paginated) **Note:** These
56    /// endpoints are currently in beta and might be subject to changes.
57    async fn get_notifications(
58        &self,
59        params: GetNotificationsParams,
60    ) -> Result<models::NotificationPaginatedResponse, Error<GetNotificationsError>>;
61
62    /// GET /webhooks/{webhookId}
63    ///
64    /// Retrieve a webhook by its id **Note:** These endpoints are currently in
65    /// beta and might be subject to changes.
66    async fn get_webhook(
67        &self,
68        params: GetWebhookParams,
69    ) -> Result<models::Webhook, Error<GetWebhookError>>;
70
71    /// GET /webhooks
72    ///
73    /// Get all webhooks (paginated) **Note:** These endpoints are currently in
74    /// beta and might be subject to changes.
75    async fn get_webhooks(
76        &self,
77        params: GetWebhooksParams,
78    ) -> Result<models::WebhookPaginatedResponse, Error<GetWebhooksError>>;
79
80    /// POST /webhooks/{webhookId}/notifications/{notificationId}/resend
81    ///
82    /// Resend notification by ID **Note:** These endpoints are currently in
83    /// beta and might be subject to changes.
84    async fn resend_notification_by_id(
85        &self,
86        params: ResendNotificationByIdParams,
87    ) -> Result<(), Error<ResendNotificationByIdError>>;
88
89    /// POST /webhooks/{webhookId}/notifications/resend_by_resource
90    ///
91    /// Resend notifications by resource Id **Note:** These endpoints are
92    /// currently in beta and might be subject to changes.
93    async fn resend_notifications_by_resource_id(
94        &self,
95        params: ResendNotificationsByResourceIdParams,
96    ) -> Result<(), Error<ResendNotificationsByResourceIdError>>;
97
98    /// PATCH /webhooks/{webhookId}
99    ///
100    /// Update a webhook by its id  **Note:**  - This endpoint is currently in
101    /// beta and might be subject to changes.  - This endpoint requires Admin
102    /// privilege or above due to the sensitivity of actions.
103    async fn update_webhook(
104        &self,
105        params: UpdateWebhookParams,
106    ) -> Result<models::Webhook, Error<UpdateWebhookError>>;
107}
108
109pub struct WebhooksV2BetaApiClient {
110    configuration: Arc<configuration::Configuration>,
111}
112
113impl WebhooksV2BetaApiClient {
114    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
115        Self { configuration }
116    }
117}
118
119/// struct for passing parameters to the method [`create_webhook`]
120#[derive(Clone, Debug)]
121#[cfg_attr(feature = "bon", derive(::bon::Builder))]
122pub struct CreateWebhookParams {
123    pub create_webhook_request: models::CreateWebhookRequest,
124    /// A unique identifier for the request. If the request is sent multiple
125    /// times with the same idempotency key, the server will return the same
126    /// response as the first request. The idempotency key is valid for 24
127    /// hours.
128    pub idempotency_key: Option<String>,
129}
130
131/// struct for passing parameters to the method [`delete_webhook`]
132#[derive(Clone, Debug)]
133#[cfg_attr(feature = "bon", derive(::bon::Builder))]
134pub struct DeleteWebhookParams {
135    /// The unique identifier of the webhook
136    pub webhook_id: String,
137}
138
139/// struct for passing parameters to the method [`get_notification`]
140#[derive(Clone, Debug)]
141#[cfg_attr(feature = "bon", derive(::bon::Builder))]
142pub struct GetNotificationParams {
143    /// The ID of the webhook to fetch
144    pub webhook_id: String,
145    /// The ID of the notification to fetch
146    pub notification_id: String,
147    /// Include the data of the notification
148    pub include_data: Option<bool>,
149}
150
151/// struct for passing parameters to the method [`get_notifications`]
152#[derive(Clone, Debug)]
153#[cfg_attr(feature = "bon", derive(::bon::Builder))]
154pub struct GetNotificationsParams {
155    pub webhook_id: String,
156    /// ASC / DESC ordering (default DESC)
157    pub order: Option<String>,
158    /// Cursor of the required page
159    pub page_cursor: Option<String>,
160    /// Maximum number of items in the page
161    pub page_size: Option<f64>,
162    /// sort by start date
163    pub created_start_date: Option<String>,
164    /// sort by end date
165    pub created_end_date: Option<String>,
166    /// Filter by Notification statues
167    pub statuses: Option<Vec<models::NotificationStatus>>,
168    /// Filter by Notification eventTypes
169    pub event_types: Option<Vec<models::WebhookEvent>>,
170    /// Filter by resourceId
171    pub resource_id: Option<String>,
172}
173
174/// struct for passing parameters to the method [`get_webhook`]
175#[derive(Clone, Debug)]
176#[cfg_attr(feature = "bon", derive(::bon::Builder))]
177pub struct GetWebhookParams {
178    /// The unique identifier of the webhook
179    pub webhook_id: String,
180}
181
182/// struct for passing parameters to the method [`get_webhooks`]
183#[derive(Clone, Debug)]
184#[cfg_attr(feature = "bon", derive(::bon::Builder))]
185pub struct GetWebhooksParams {
186    /// ASC / DESC ordering (default DESC)
187    pub order: Option<String>,
188    /// Cursor of the required page
189    pub page_cursor: Option<String>,
190    /// Maximum number of items in the page
191    pub page_size: Option<f64>,
192}
193
194/// struct for passing parameters to the method [`resend_notification_by_id`]
195#[derive(Clone, Debug)]
196#[cfg_attr(feature = "bon", derive(::bon::Builder))]
197pub struct ResendNotificationByIdParams {
198    /// The ID of the webhook
199    pub webhook_id: String,
200    /// The ID of the notification
201    pub notification_id: String,
202    /// A unique identifier for the request. If the request is sent multiple
203    /// times with the same idempotency key, the server will return the same
204    /// response as the first request. The idempotency key is valid for 24
205    /// hours.
206    pub idempotency_key: Option<String>,
207}
208
209/// struct for passing parameters to the method
210/// [`resend_notifications_by_resource_id`]
211#[derive(Clone, Debug)]
212#[cfg_attr(feature = "bon", derive(::bon::Builder))]
213pub struct ResendNotificationsByResourceIdParams {
214    /// The ID of the webhook
215    pub webhook_id: String,
216    pub resend_notifications_by_resource_id_request: models::ResendNotificationsByResourceIdRequest,
217    /// A unique identifier for the request. If the request is sent multiple
218    /// times with the same idempotency key, the server will return the same
219    /// response as the first request. The idempotency key is valid for 24
220    /// hours.
221    pub idempotency_key: Option<String>,
222}
223
224/// struct for passing parameters to the method [`update_webhook`]
225#[derive(Clone, Debug)]
226#[cfg_attr(feature = "bon", derive(::bon::Builder))]
227pub struct UpdateWebhookParams {
228    /// The unique identifier of the webhook
229    pub webhook_id: String,
230    pub update_webhook_request: models::UpdateWebhookRequest,
231}
232
233#[async_trait]
234impl WebhooksV2BetaApi for WebhooksV2BetaApiClient {
235    /// Creates a new webhook, which will be triggered on the specified events
236    /// **Note:**  - This endpoint is currently in beta and might be subject to
237    /// changes.  - This endpoint requires Admin privilege or above due to the
238    /// sensitivity of actions.
239    async fn create_webhook(
240        &self,
241        params: CreateWebhookParams,
242    ) -> Result<models::Webhook, Error<CreateWebhookError>> {
243        let CreateWebhookParams {
244            create_webhook_request,
245            idempotency_key,
246        } = params;
247
248        let local_var_configuration = &self.configuration;
249
250        let local_var_client = &local_var_configuration.client;
251
252        let local_var_uri_str = format!("{}/webhooks", local_var_configuration.base_path);
253        let mut local_var_req_builder =
254            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
255
256        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
257            local_var_req_builder = local_var_req_builder
258                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
259        }
260        if let Some(local_var_param_value) = idempotency_key {
261            local_var_req_builder =
262                local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
263        }
264        local_var_req_builder = local_var_req_builder.json(&create_webhook_request);
265
266        let local_var_req = local_var_req_builder.build()?;
267        let local_var_resp = local_var_client.execute(local_var_req).await?;
268
269        let local_var_status = local_var_resp.status();
270        let local_var_content_type = local_var_resp
271            .headers()
272            .get("content-type")
273            .and_then(|v| v.to_str().ok())
274            .unwrap_or("application/octet-stream");
275        let local_var_content_type = super::ContentType::from(local_var_content_type);
276        let local_var_content = local_var_resp.text().await?;
277
278        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
279            match local_var_content_type {
280                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
281                ContentType::Text => {
282                    return Err(Error::from(serde_json::Error::custom(
283                        "Received `text/plain` content type response that cannot be converted to \
284                         `models::Webhook`",
285                    )))
286                }
287                ContentType::Unsupported(local_var_unknown_type) => {
288                    return Err(Error::from(serde_json::Error::custom(format!(
289                        "Received `{local_var_unknown_type}` content type response that cannot be \
290                         converted to `models::Webhook`"
291                    ))))
292                }
293            }
294        } else {
295            let local_var_entity: Option<CreateWebhookError> =
296                serde_json::from_str(&local_var_content).ok();
297            let local_var_error = ResponseContent {
298                status: local_var_status,
299                content: local_var_content,
300                entity: local_var_entity,
301            };
302            Err(Error::ResponseError(local_var_error))
303        }
304    }
305
306    /// Delete a webhook by its id  **Note:**  - This endpoint is currently in
307    /// beta and might be subject to changes.  - This endpoint requires Admin
308    /// privilege or above due to the sensitivity of actions.
309    async fn delete_webhook(
310        &self,
311        params: DeleteWebhookParams,
312    ) -> Result<models::Webhook, Error<DeleteWebhookError>> {
313        let DeleteWebhookParams { webhook_id } = params;
314
315        let local_var_configuration = &self.configuration;
316
317        let local_var_client = &local_var_configuration.client;
318
319        let local_var_uri_str = format!(
320            "{}/webhooks/{webhookId}",
321            local_var_configuration.base_path,
322            webhookId = crate::apis::urlencode(webhook_id)
323        );
324        let mut local_var_req_builder =
325            local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
326
327        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
328            local_var_req_builder = local_var_req_builder
329                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
330        }
331
332        let local_var_req = local_var_req_builder.build()?;
333        let local_var_resp = local_var_client.execute(local_var_req).await?;
334
335        let local_var_status = local_var_resp.status();
336        let local_var_content_type = local_var_resp
337            .headers()
338            .get("content-type")
339            .and_then(|v| v.to_str().ok())
340            .unwrap_or("application/octet-stream");
341        let local_var_content_type = super::ContentType::from(local_var_content_type);
342        let local_var_content = local_var_resp.text().await?;
343
344        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
345            match local_var_content_type {
346                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
347                ContentType::Text => {
348                    return Err(Error::from(serde_json::Error::custom(
349                        "Received `text/plain` content type response that cannot be converted to \
350                         `models::Webhook`",
351                    )))
352                }
353                ContentType::Unsupported(local_var_unknown_type) => {
354                    return Err(Error::from(serde_json::Error::custom(format!(
355                        "Received `{local_var_unknown_type}` content type response that cannot be \
356                         converted to `models::Webhook`"
357                    ))))
358                }
359            }
360        } else {
361            let local_var_entity: Option<DeleteWebhookError> =
362                serde_json::from_str(&local_var_content).ok();
363            let local_var_error = ResponseContent {
364                status: local_var_status,
365                content: local_var_content,
366                entity: local_var_entity,
367            };
368            Err(Error::ResponseError(local_var_error))
369        }
370    }
371
372    /// Get notification by id **Note:** These endpoints are currently in beta
373    /// and might be subject to changes.
374    async fn get_notification(
375        &self,
376        params: GetNotificationParams,
377    ) -> Result<models::NotificationWithData, Error<GetNotificationError>> {
378        let GetNotificationParams {
379            webhook_id,
380            notification_id,
381            include_data,
382        } = params;
383
384        let local_var_configuration = &self.configuration;
385
386        let local_var_client = &local_var_configuration.client;
387
388        let local_var_uri_str = format!(
389            "{}/webhooks/{webhookId}/notifications/{notificationId}",
390            local_var_configuration.base_path,
391            webhookId = crate::apis::urlencode(webhook_id),
392            notificationId = crate::apis::urlencode(notification_id)
393        );
394        let mut local_var_req_builder =
395            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
396
397        if let Some(ref local_var_str) = include_data {
398            local_var_req_builder =
399                local_var_req_builder.query(&[("includeData", &local_var_str.to_string())]);
400        }
401        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
402            local_var_req_builder = local_var_req_builder
403                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
404        }
405
406        let local_var_req = local_var_req_builder.build()?;
407        let local_var_resp = local_var_client.execute(local_var_req).await?;
408
409        let local_var_status = local_var_resp.status();
410        let local_var_content_type = local_var_resp
411            .headers()
412            .get("content-type")
413            .and_then(|v| v.to_str().ok())
414            .unwrap_or("application/octet-stream");
415        let local_var_content_type = super::ContentType::from(local_var_content_type);
416        let local_var_content = local_var_resp.text().await?;
417
418        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
419            match local_var_content_type {
420                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
421                ContentType::Text => {
422                    return Err(Error::from(serde_json::Error::custom(
423                        "Received `text/plain` content type response that cannot be converted to \
424                         `models::NotificationWithData`",
425                    )))
426                }
427                ContentType::Unsupported(local_var_unknown_type) => {
428                    return Err(Error::from(serde_json::Error::custom(format!(
429                        "Received `{local_var_unknown_type}` content type response that cannot be \
430                         converted to `models::NotificationWithData`"
431                    ))))
432                }
433            }
434        } else {
435            let local_var_entity: Option<GetNotificationError> =
436                serde_json::from_str(&local_var_content).ok();
437            let local_var_error = ResponseContent {
438                status: local_var_status,
439                content: local_var_content,
440                entity: local_var_entity,
441            };
442            Err(Error::ResponseError(local_var_error))
443        }
444    }
445
446    /// Get all notifications by webhook id (paginated) **Note:** These
447    /// endpoints are currently in beta and might be subject to changes.
448    async fn get_notifications(
449        &self,
450        params: GetNotificationsParams,
451    ) -> Result<models::NotificationPaginatedResponse, Error<GetNotificationsError>> {
452        let GetNotificationsParams {
453            webhook_id,
454            order,
455            page_cursor,
456            page_size,
457            created_start_date,
458            created_end_date,
459            statuses,
460            event_types,
461            resource_id,
462        } = params;
463
464        let local_var_configuration = &self.configuration;
465
466        let local_var_client = &local_var_configuration.client;
467
468        let local_var_uri_str = format!(
469            "{}/webhooks/{webhookId}/notifications",
470            local_var_configuration.base_path,
471            webhookId = crate::apis::urlencode(webhook_id)
472        );
473        let mut local_var_req_builder =
474            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
475
476        if let Some(ref local_var_str) = order {
477            local_var_req_builder =
478                local_var_req_builder.query(&[("order", &local_var_str.to_string())]);
479        }
480        if let Some(ref local_var_str) = page_cursor {
481            local_var_req_builder =
482                local_var_req_builder.query(&[("pageCursor", &local_var_str.to_string())]);
483        }
484        if let Some(ref local_var_str) = page_size {
485            local_var_req_builder =
486                local_var_req_builder.query(&[("pageSize", &local_var_str.to_string())]);
487        }
488        if let Some(ref local_var_str) = created_start_date {
489            local_var_req_builder =
490                local_var_req_builder.query(&[("createdStartDate", &local_var_str.to_string())]);
491        }
492        if let Some(ref local_var_str) = created_end_date {
493            local_var_req_builder =
494                local_var_req_builder.query(&[("createdEndDate", &local_var_str.to_string())]);
495        }
496        if let Some(ref local_var_str) = statuses {
497            local_var_req_builder = match "multi" {
498                "multi" => local_var_req_builder.query(
499                    &local_var_str
500                        .into_iter()
501                        .map(|p| ("statuses".to_owned(), p.to_string()))
502                        .collect::<Vec<(std::string::String, std::string::String)>>(),
503                ),
504                _ => local_var_req_builder.query(&[(
505                    "statuses",
506                    &local_var_str
507                        .into_iter()
508                        .map(|p| p.to_string())
509                        .collect::<Vec<String>>()
510                        .join(",")
511                        .to_string(),
512                )]),
513            };
514        }
515        if let Some(ref local_var_str) = event_types {
516            local_var_req_builder = match "multi" {
517                "multi" => local_var_req_builder.query(
518                    &local_var_str
519                        .into_iter()
520                        .map(|p| ("eventTypes".to_owned(), p.to_string()))
521                        .collect::<Vec<(std::string::String, std::string::String)>>(),
522                ),
523                _ => local_var_req_builder.query(&[(
524                    "eventTypes",
525                    &local_var_str
526                        .into_iter()
527                        .map(|p| p.to_string())
528                        .collect::<Vec<String>>()
529                        .join(",")
530                        .to_string(),
531                )]),
532            };
533        }
534        if let Some(ref local_var_str) = resource_id {
535            local_var_req_builder =
536                local_var_req_builder.query(&[("resourceId", &local_var_str.to_string())]);
537        }
538        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
539            local_var_req_builder = local_var_req_builder
540                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
541        }
542
543        let local_var_req = local_var_req_builder.build()?;
544        let local_var_resp = local_var_client.execute(local_var_req).await?;
545
546        let local_var_status = local_var_resp.status();
547        let local_var_content_type = local_var_resp
548            .headers()
549            .get("content-type")
550            .and_then(|v| v.to_str().ok())
551            .unwrap_or("application/octet-stream");
552        let local_var_content_type = super::ContentType::from(local_var_content_type);
553        let local_var_content = local_var_resp.text().await?;
554
555        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
556            match local_var_content_type {
557                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
558                ContentType::Text => {
559                    return Err(Error::from(serde_json::Error::custom(
560                        "Received `text/plain` content type response that cannot be converted to \
561                         `models::NotificationPaginatedResponse`",
562                    )))
563                }
564                ContentType::Unsupported(local_var_unknown_type) => {
565                    return Err(Error::from(serde_json::Error::custom(format!(
566                        "Received `{local_var_unknown_type}` content type response that cannot be \
567                         converted to `models::NotificationPaginatedResponse`"
568                    ))))
569                }
570            }
571        } else {
572            let local_var_entity: Option<GetNotificationsError> =
573                serde_json::from_str(&local_var_content).ok();
574            let local_var_error = ResponseContent {
575                status: local_var_status,
576                content: local_var_content,
577                entity: local_var_entity,
578            };
579            Err(Error::ResponseError(local_var_error))
580        }
581    }
582
583    /// Retrieve a webhook by its id **Note:** These endpoints are currently in
584    /// beta and might be subject to changes.
585    async fn get_webhook(
586        &self,
587        params: GetWebhookParams,
588    ) -> Result<models::Webhook, Error<GetWebhookError>> {
589        let GetWebhookParams { webhook_id } = params;
590
591        let local_var_configuration = &self.configuration;
592
593        let local_var_client = &local_var_configuration.client;
594
595        let local_var_uri_str = format!(
596            "{}/webhooks/{webhookId}",
597            local_var_configuration.base_path,
598            webhookId = crate::apis::urlencode(webhook_id)
599        );
600        let mut local_var_req_builder =
601            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
602
603        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
604            local_var_req_builder = local_var_req_builder
605                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
606        }
607
608        let local_var_req = local_var_req_builder.build()?;
609        let local_var_resp = local_var_client.execute(local_var_req).await?;
610
611        let local_var_status = local_var_resp.status();
612        let local_var_content_type = local_var_resp
613            .headers()
614            .get("content-type")
615            .and_then(|v| v.to_str().ok())
616            .unwrap_or("application/octet-stream");
617        let local_var_content_type = super::ContentType::from(local_var_content_type);
618        let local_var_content = local_var_resp.text().await?;
619
620        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
621            match local_var_content_type {
622                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
623                ContentType::Text => {
624                    return Err(Error::from(serde_json::Error::custom(
625                        "Received `text/plain` content type response that cannot be converted to \
626                         `models::Webhook`",
627                    )))
628                }
629                ContentType::Unsupported(local_var_unknown_type) => {
630                    return Err(Error::from(serde_json::Error::custom(format!(
631                        "Received `{local_var_unknown_type}` content type response that cannot be \
632                         converted to `models::Webhook`"
633                    ))))
634                }
635            }
636        } else {
637            let local_var_entity: Option<GetWebhookError> =
638                serde_json::from_str(&local_var_content).ok();
639            let local_var_error = ResponseContent {
640                status: local_var_status,
641                content: local_var_content,
642                entity: local_var_entity,
643            };
644            Err(Error::ResponseError(local_var_error))
645        }
646    }
647
648    /// Get all webhooks (paginated) **Note:** These endpoints are currently in
649    /// beta and might be subject to changes.
650    async fn get_webhooks(
651        &self,
652        params: GetWebhooksParams,
653    ) -> Result<models::WebhookPaginatedResponse, Error<GetWebhooksError>> {
654        let GetWebhooksParams {
655            order,
656            page_cursor,
657            page_size,
658        } = params;
659
660        let local_var_configuration = &self.configuration;
661
662        let local_var_client = &local_var_configuration.client;
663
664        let local_var_uri_str = format!("{}/webhooks", local_var_configuration.base_path);
665        let mut local_var_req_builder =
666            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
667
668        if let Some(ref local_var_str) = order {
669            local_var_req_builder =
670                local_var_req_builder.query(&[("order", &local_var_str.to_string())]);
671        }
672        if let Some(ref local_var_str) = page_cursor {
673            local_var_req_builder =
674                local_var_req_builder.query(&[("pageCursor", &local_var_str.to_string())]);
675        }
676        if let Some(ref local_var_str) = page_size {
677            local_var_req_builder =
678                local_var_req_builder.query(&[("pageSize", &local_var_str.to_string())]);
679        }
680        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
681            local_var_req_builder = local_var_req_builder
682                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
683        }
684
685        let local_var_req = local_var_req_builder.build()?;
686        let local_var_resp = local_var_client.execute(local_var_req).await?;
687
688        let local_var_status = local_var_resp.status();
689        let local_var_content_type = local_var_resp
690            .headers()
691            .get("content-type")
692            .and_then(|v| v.to_str().ok())
693            .unwrap_or("application/octet-stream");
694        let local_var_content_type = super::ContentType::from(local_var_content_type);
695        let local_var_content = local_var_resp.text().await?;
696
697        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
698            match local_var_content_type {
699                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
700                ContentType::Text => {
701                    return Err(Error::from(serde_json::Error::custom(
702                        "Received `text/plain` content type response that cannot be converted to \
703                         `models::WebhookPaginatedResponse`",
704                    )))
705                }
706                ContentType::Unsupported(local_var_unknown_type) => {
707                    return Err(Error::from(serde_json::Error::custom(format!(
708                        "Received `{local_var_unknown_type}` content type response that cannot be \
709                         converted to `models::WebhookPaginatedResponse`"
710                    ))))
711                }
712            }
713        } else {
714            let local_var_entity: Option<GetWebhooksError> =
715                serde_json::from_str(&local_var_content).ok();
716            let local_var_error = ResponseContent {
717                status: local_var_status,
718                content: local_var_content,
719                entity: local_var_entity,
720            };
721            Err(Error::ResponseError(local_var_error))
722        }
723    }
724
725    /// Resend notification by ID **Note:** These endpoints are currently in
726    /// beta and might be subject to changes.
727    async fn resend_notification_by_id(
728        &self,
729        params: ResendNotificationByIdParams,
730    ) -> Result<(), Error<ResendNotificationByIdError>> {
731        let ResendNotificationByIdParams {
732            webhook_id,
733            notification_id,
734            idempotency_key,
735        } = params;
736
737        let local_var_configuration = &self.configuration;
738
739        let local_var_client = &local_var_configuration.client;
740
741        let local_var_uri_str = format!(
742            "{}/webhooks/{webhookId}/notifications/{notificationId}/resend",
743            local_var_configuration.base_path,
744            webhookId = crate::apis::urlencode(webhook_id),
745            notificationId = crate::apis::urlencode(notification_id)
746        );
747        let mut local_var_req_builder =
748            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
749
750        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
751            local_var_req_builder = local_var_req_builder
752                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
753        }
754        if let Some(local_var_param_value) = idempotency_key {
755            local_var_req_builder =
756                local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
757        }
758
759        let local_var_req = local_var_req_builder.build()?;
760        let local_var_resp = local_var_client.execute(local_var_req).await?;
761
762        let local_var_status = local_var_resp.status();
763        let local_var_content = local_var_resp.text().await?;
764
765        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
766            Ok(())
767        } else {
768            let local_var_entity: Option<ResendNotificationByIdError> =
769                serde_json::from_str(&local_var_content).ok();
770            let local_var_error = ResponseContent {
771                status: local_var_status,
772                content: local_var_content,
773                entity: local_var_entity,
774            };
775            Err(Error::ResponseError(local_var_error))
776        }
777    }
778
779    /// Resend notifications by resource Id **Note:** These endpoints are
780    /// currently in beta and might be subject to changes.
781    async fn resend_notifications_by_resource_id(
782        &self,
783        params: ResendNotificationsByResourceIdParams,
784    ) -> Result<(), Error<ResendNotificationsByResourceIdError>> {
785        let ResendNotificationsByResourceIdParams {
786            webhook_id,
787            resend_notifications_by_resource_id_request,
788            idempotency_key,
789        } = params;
790
791        let local_var_configuration = &self.configuration;
792
793        let local_var_client = &local_var_configuration.client;
794
795        let local_var_uri_str = format!(
796            "{}/webhooks/{webhookId}/notifications/resend_by_resource",
797            local_var_configuration.base_path,
798            webhookId = crate::apis::urlencode(webhook_id)
799        );
800        let mut local_var_req_builder =
801            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
802
803        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
804            local_var_req_builder = local_var_req_builder
805                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
806        }
807        if let Some(local_var_param_value) = idempotency_key {
808            local_var_req_builder =
809                local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
810        }
811        local_var_req_builder =
812            local_var_req_builder.json(&resend_notifications_by_resource_id_request);
813
814        let local_var_req = local_var_req_builder.build()?;
815        let local_var_resp = local_var_client.execute(local_var_req).await?;
816
817        let local_var_status = local_var_resp.status();
818        let local_var_content = local_var_resp.text().await?;
819
820        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
821            Ok(())
822        } else {
823            let local_var_entity: Option<ResendNotificationsByResourceIdError> =
824                serde_json::from_str(&local_var_content).ok();
825            let local_var_error = ResponseContent {
826                status: local_var_status,
827                content: local_var_content,
828                entity: local_var_entity,
829            };
830            Err(Error::ResponseError(local_var_error))
831        }
832    }
833
834    /// Update a webhook by its id  **Note:**  - This endpoint is currently in
835    /// beta and might be subject to changes.  - This endpoint requires Admin
836    /// privilege or above due to the sensitivity of actions.
837    async fn update_webhook(
838        &self,
839        params: UpdateWebhookParams,
840    ) -> Result<models::Webhook, Error<UpdateWebhookError>> {
841        let UpdateWebhookParams {
842            webhook_id,
843            update_webhook_request,
844        } = params;
845
846        let local_var_configuration = &self.configuration;
847
848        let local_var_client = &local_var_configuration.client;
849
850        let local_var_uri_str = format!(
851            "{}/webhooks/{webhookId}",
852            local_var_configuration.base_path,
853            webhookId = crate::apis::urlencode(webhook_id)
854        );
855        let mut local_var_req_builder =
856            local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
857
858        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
859            local_var_req_builder = local_var_req_builder
860                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
861        }
862        local_var_req_builder = local_var_req_builder.json(&update_webhook_request);
863
864        let local_var_req = local_var_req_builder.build()?;
865        let local_var_resp = local_var_client.execute(local_var_req).await?;
866
867        let local_var_status = local_var_resp.status();
868        let local_var_content_type = local_var_resp
869            .headers()
870            .get("content-type")
871            .and_then(|v| v.to_str().ok())
872            .unwrap_or("application/octet-stream");
873        let local_var_content_type = super::ContentType::from(local_var_content_type);
874        let local_var_content = local_var_resp.text().await?;
875
876        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
877            match local_var_content_type {
878                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
879                ContentType::Text => {
880                    return Err(Error::from(serde_json::Error::custom(
881                        "Received `text/plain` content type response that cannot be converted to \
882                         `models::Webhook`",
883                    )))
884                }
885                ContentType::Unsupported(local_var_unknown_type) => {
886                    return Err(Error::from(serde_json::Error::custom(format!(
887                        "Received `{local_var_unknown_type}` content type response that cannot be \
888                         converted to `models::Webhook`"
889                    ))))
890                }
891            }
892        } else {
893            let local_var_entity: Option<UpdateWebhookError> =
894                serde_json::from_str(&local_var_content).ok();
895            let local_var_error = ResponseContent {
896                status: local_var_status,
897                content: local_var_content,
898                entity: local_var_entity,
899            };
900            Err(Error::ResponseError(local_var_error))
901        }
902    }
903}
904
905/// struct for typed errors of method [`create_webhook`]
906#[derive(Debug, Clone, Serialize, Deserialize)]
907#[serde(untagged)]
908pub enum CreateWebhookError {
909    DefaultResponse(models::ErrorSchema),
910    UnknownValue(serde_json::Value),
911}
912
913/// struct for typed errors of method [`delete_webhook`]
914#[derive(Debug, Clone, Serialize, Deserialize)]
915#[serde(untagged)]
916pub enum DeleteWebhookError {
917    DefaultResponse(models::ErrorSchema),
918    UnknownValue(serde_json::Value),
919}
920
921/// struct for typed errors of method [`get_notification`]
922#[derive(Debug, Clone, Serialize, Deserialize)]
923#[serde(untagged)]
924pub enum GetNotificationError {
925    UnknownValue(serde_json::Value),
926}
927
928/// struct for typed errors of method [`get_notifications`]
929#[derive(Debug, Clone, Serialize, Deserialize)]
930#[serde(untagged)]
931pub enum GetNotificationsError {
932    UnknownValue(serde_json::Value),
933}
934
935/// struct for typed errors of method [`get_webhook`]
936#[derive(Debug, Clone, Serialize, Deserialize)]
937#[serde(untagged)]
938pub enum GetWebhookError {
939    DefaultResponse(models::ErrorSchema),
940    UnknownValue(serde_json::Value),
941}
942
943/// struct for typed errors of method [`get_webhooks`]
944#[derive(Debug, Clone, Serialize, Deserialize)]
945#[serde(untagged)]
946pub enum GetWebhooksError {
947    DefaultResponse(models::ErrorSchema),
948    UnknownValue(serde_json::Value),
949}
950
951/// struct for typed errors of method [`resend_notification_by_id`]
952#[derive(Debug, Clone, Serialize, Deserialize)]
953#[serde(untagged)]
954pub enum ResendNotificationByIdError {
955    DefaultResponse(models::ErrorSchema),
956    UnknownValue(serde_json::Value),
957}
958
959/// struct for typed errors of method [`resend_notifications_by_resource_id`]
960#[derive(Debug, Clone, Serialize, Deserialize)]
961#[serde(untagged)]
962pub enum ResendNotificationsByResourceIdError {
963    DefaultResponse(models::ErrorSchema),
964    UnknownValue(serde_json::Value),
965}
966
967/// struct for typed errors of method [`update_webhook`]
968#[derive(Debug, Clone, Serialize, Deserialize)]
969#[serde(untagged)]
970pub enum UpdateWebhookError {
971    DefaultResponse(models::ErrorSchema),
972    UnknownValue(serde_json::Value),
973}