1use {
10 super::{Error, configuration},
11 crate::{
12 apis::{ContentType, ResponseContent},
13 models,
14 },
15 async_trait::async_trait,
16 reqwest,
17 serde::{Deserialize, Serialize, de::Error as _},
18 std::sync::Arc,
19};
20
21#[async_trait]
22pub trait WebhooksV2Api: Send + Sync {
23 async fn create_webhook(
28 &self,
29 params: CreateWebhookParams,
30 ) -> Result<models::Webhook, Error<CreateWebhookError>>;
31
32 async fn delete_webhook(
37 &self,
38 params: DeleteWebhookParams,
39 ) -> Result<models::Webhook, Error<DeleteWebhookError>>;
40
41 async fn get_notification(
46 &self,
47 params: GetNotificationParams,
48 ) -> Result<models::NotificationWithData, Error<GetNotificationError>>;
49
50 async fn get_notification_attempts(
54 &self,
55 params: GetNotificationAttemptsParams,
56 ) -> Result<models::NotificationAttemptsPaginatedResponse, Error<GetNotificationAttemptsError>>;
57
58 async fn get_notifications(
63 &self,
64 params: GetNotificationsParams,
65 ) -> Result<models::NotificationPaginatedResponse, Error<GetNotificationsError>>;
66
67 async fn get_resend_job_status(
71 &self,
72 params: GetResendJobStatusParams,
73 ) -> Result<models::ResendFailedNotificationsJobStatusResponse, Error<GetResendJobStatusError>>;
74
75 async fn get_webhook(
80 &self,
81 params: GetWebhookParams,
82 ) -> Result<models::Webhook, Error<GetWebhookError>>;
83
84 async fn get_webhooks(
89 &self,
90 params: GetWebhooksParams,
91 ) -> Result<models::WebhookPaginatedResponse, Error<GetWebhooksError>>;
92
93 async fn resend_failed_notifications(
99 &self,
100 params: ResendFailedNotificationsParams,
101 ) -> Result<models::ResendFailedNotificationsResponse, Error<ResendFailedNotificationsError>>;
102
103 async fn resend_notification_by_id(
108 &self,
109 params: ResendNotificationByIdParams,
110 ) -> Result<(), Error<ResendNotificationByIdError>>;
111
112 async fn resend_notifications_by_resource_id(
117 &self,
118 params: ResendNotificationsByResourceIdParams,
119 ) -> Result<(), Error<ResendNotificationsByResourceIdError>>;
120
121 async fn update_webhook(
126 &self,
127 params: UpdateWebhookParams,
128 ) -> Result<models::Webhook, Error<UpdateWebhookError>>;
129}
130
131pub struct WebhooksV2ApiClient {
132 configuration: Arc<configuration::Configuration>,
133}
134
135impl WebhooksV2ApiClient {
136 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
137 Self { configuration }
138 }
139}
140
141#[derive(Clone, Debug)]
144#[cfg_attr(feature = "bon", derive(::bon::Builder))]
145pub struct CreateWebhookParams {
146 pub create_webhook_request: models::CreateWebhookRequest,
147 pub idempotency_key: Option<String>,
152}
153
154#[derive(Clone, Debug)]
157#[cfg_attr(feature = "bon", derive(::bon::Builder))]
158pub struct DeleteWebhookParams {
159 pub webhook_id: String,
161}
162
163#[derive(Clone, Debug)]
166#[cfg_attr(feature = "bon", derive(::bon::Builder))]
167pub struct GetNotificationParams {
168 pub webhook_id: String,
170 pub notification_id: String,
172 pub include_data: Option<bool>,
174}
175
176#[derive(Clone, Debug)]
179#[cfg_attr(feature = "bon", derive(::bon::Builder))]
180pub struct GetNotificationAttemptsParams {
181 pub webhook_id: String,
183 pub notification_id: String,
185 pub page_cursor: Option<String>,
187 pub page_size: Option<f64>,
189}
190
191#[derive(Clone, Debug)]
194#[cfg_attr(feature = "bon", derive(::bon::Builder))]
195pub struct GetNotificationsParams {
196 pub webhook_id: String,
197 pub order: Option<String>,
199 pub sort_by: Option<String>,
201 pub page_cursor: Option<String>,
203 pub page_size: Option<f64>,
205 pub start_time: Option<String>,
208 pub end_time: Option<String>,
211 pub statuses: Option<Vec<models::NotificationStatus>>,
213 pub events: Option<Vec<models::WebhookEvent>>,
215 pub resource_id: Option<String>,
217}
218
219#[derive(Clone, Debug)]
222#[cfg_attr(feature = "bon", derive(::bon::Builder))]
223pub struct GetResendJobStatusParams {
224 pub webhook_id: String,
226 pub job_id: String,
228}
229
230#[derive(Clone, Debug)]
232#[cfg_attr(feature = "bon", derive(::bon::Builder))]
233pub struct GetWebhookParams {
234 pub webhook_id: String,
236}
237
238#[derive(Clone, Debug)]
240#[cfg_attr(feature = "bon", derive(::bon::Builder))]
241pub struct GetWebhooksParams {
242 pub order: Option<String>,
244 pub page_cursor: Option<String>,
246 pub page_size: Option<f64>,
248}
249
250#[derive(Clone, Debug)]
253#[cfg_attr(feature = "bon", derive(::bon::Builder))]
254pub struct ResendFailedNotificationsParams {
255 pub webhook_id: String,
257 pub resend_failed_notifications_request: models::ResendFailedNotificationsRequest,
258 pub idempotency_key: Option<String>,
263}
264
265#[derive(Clone, Debug)]
268#[cfg_attr(feature = "bon", derive(::bon::Builder))]
269pub struct ResendNotificationByIdParams {
270 pub webhook_id: String,
272 pub notification_id: String,
274 pub idempotency_key: Option<String>,
279}
280
281#[derive(Clone, Debug)]
284#[cfg_attr(feature = "bon", derive(::bon::Builder))]
285pub struct ResendNotificationsByResourceIdParams {
286 pub webhook_id: String,
288 pub resend_notifications_by_resource_id_request: models::ResendNotificationsByResourceIdRequest,
289 pub idempotency_key: Option<String>,
294}
295
296#[derive(Clone, Debug)]
299#[cfg_attr(feature = "bon", derive(::bon::Builder))]
300pub struct UpdateWebhookParams {
301 pub webhook_id: String,
303 pub update_webhook_request: models::UpdateWebhookRequest,
304}
305
306#[async_trait]
307impl WebhooksV2Api for WebhooksV2ApiClient {
308 async fn create_webhook(
311 &self,
312 params: CreateWebhookParams,
313 ) -> Result<models::Webhook, Error<CreateWebhookError>> {
314 let CreateWebhookParams {
315 create_webhook_request,
316 idempotency_key,
317 } = params;
318
319 let local_var_configuration = &self.configuration;
320
321 let local_var_client = &local_var_configuration.client;
322
323 let local_var_uri_str = format!("{}/webhooks", local_var_configuration.base_path);
324 let mut local_var_req_builder =
325 local_var_client.request(reqwest::Method::POST, 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 if let Some(local_var_param_value) = idempotency_key {
332 local_var_req_builder =
333 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
334 }
335 local_var_req_builder = local_var_req_builder.json(&create_webhook_request);
336
337 let local_var_req = local_var_req_builder.build()?;
338 let local_var_resp = local_var_client.execute(local_var_req).await?;
339
340 let local_var_status = local_var_resp.status();
341 let local_var_content_type = local_var_resp
342 .headers()
343 .get("content-type")
344 .and_then(|v| v.to_str().ok())
345 .unwrap_or("application/octet-stream");
346 let local_var_content_type = super::ContentType::from(local_var_content_type);
347 let local_var_content = local_var_resp.text().await?;
348
349 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
350 match local_var_content_type {
351 ContentType::Json => {
352 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
353 }
354 ContentType::Text => {
355 return Err(Error::from(serde_json::Error::custom(
356 "Received `text/plain` content type response that cannot be converted to \
357 `models::Webhook`",
358 )));
359 }
360 ContentType::Unsupported(local_var_unknown_type) => {
361 return Err(Error::from(serde_json::Error::custom(format!(
362 "Received `{local_var_unknown_type}` content type response that cannot be \
363 converted to `models::Webhook`"
364 ))));
365 }
366 }
367 } else {
368 let local_var_entity: Option<CreateWebhookError> =
369 serde_json::from_str(&local_var_content).ok();
370 let local_var_error = ResponseContent {
371 status: local_var_status,
372 content: local_var_content,
373 entity: local_var_entity,
374 };
375 Err(Error::ResponseError(local_var_error))
376 }
377 }
378
379 async fn delete_webhook(
382 &self,
383 params: DeleteWebhookParams,
384 ) -> Result<models::Webhook, Error<DeleteWebhookError>> {
385 let DeleteWebhookParams { webhook_id } = params;
386
387 let local_var_configuration = &self.configuration;
388
389 let local_var_client = &local_var_configuration.client;
390
391 let local_var_uri_str = format!(
392 "{}/webhooks/{webhookId}",
393 local_var_configuration.base_path,
394 webhookId = crate::apis::urlencode(webhook_id)
395 );
396 let mut local_var_req_builder =
397 local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
398
399 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
400 local_var_req_builder = local_var_req_builder
401 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
402 }
403
404 let local_var_req = local_var_req_builder.build()?;
405 let local_var_resp = local_var_client.execute(local_var_req).await?;
406
407 let local_var_status = local_var_resp.status();
408 let local_var_content_type = local_var_resp
409 .headers()
410 .get("content-type")
411 .and_then(|v| v.to_str().ok())
412 .unwrap_or("application/octet-stream");
413 let local_var_content_type = super::ContentType::from(local_var_content_type);
414 let local_var_content = local_var_resp.text().await?;
415
416 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
417 match local_var_content_type {
418 ContentType::Json => {
419 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
420 }
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::Webhook`",
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::Webhook`"
431 ))));
432 }
433 }
434 } else {
435 let local_var_entity: Option<DeleteWebhookError> =
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 async fn get_notification(
449 &self,
450 params: GetNotificationParams,
451 ) -> Result<models::NotificationWithData, Error<GetNotificationError>> {
452 let GetNotificationParams {
453 webhook_id,
454 notification_id,
455 include_data,
456 } = params;
457
458 let local_var_configuration = &self.configuration;
459
460 let local_var_client = &local_var_configuration.client;
461
462 let local_var_uri_str = format!(
463 "{}/webhooks/{webhookId}/notifications/{notificationId}",
464 local_var_configuration.base_path,
465 webhookId = crate::apis::urlencode(webhook_id),
466 notificationId = crate::apis::urlencode(notification_id)
467 );
468 let mut local_var_req_builder =
469 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
470
471 if let Some(ref param_value) = include_data {
472 local_var_req_builder =
473 local_var_req_builder.query(&[("includeData", ¶m_value.to_string())]);
474 }
475 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
476 local_var_req_builder = local_var_req_builder
477 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
478 }
479
480 let local_var_req = local_var_req_builder.build()?;
481 let local_var_resp = local_var_client.execute(local_var_req).await?;
482
483 let local_var_status = local_var_resp.status();
484 let local_var_content_type = local_var_resp
485 .headers()
486 .get("content-type")
487 .and_then(|v| v.to_str().ok())
488 .unwrap_or("application/octet-stream");
489 let local_var_content_type = super::ContentType::from(local_var_content_type);
490 let local_var_content = local_var_resp.text().await?;
491
492 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
493 match local_var_content_type {
494 ContentType::Json => {
495 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
496 }
497 ContentType::Text => {
498 return Err(Error::from(serde_json::Error::custom(
499 "Received `text/plain` content type response that cannot be converted to \
500 `models::NotificationWithData`",
501 )));
502 }
503 ContentType::Unsupported(local_var_unknown_type) => {
504 return Err(Error::from(serde_json::Error::custom(format!(
505 "Received `{local_var_unknown_type}` content type response that cannot be \
506 converted to `models::NotificationWithData`"
507 ))));
508 }
509 }
510 } else {
511 let local_var_entity: Option<GetNotificationError> =
512 serde_json::from_str(&local_var_content).ok();
513 let local_var_error = ResponseContent {
514 status: local_var_status,
515 content: local_var_content,
516 entity: local_var_entity,
517 };
518 Err(Error::ResponseError(local_var_error))
519 }
520 }
521
522 async fn get_notification_attempts(
524 &self,
525 params: GetNotificationAttemptsParams,
526 ) -> Result<models::NotificationAttemptsPaginatedResponse, Error<GetNotificationAttemptsError>>
527 {
528 let GetNotificationAttemptsParams {
529 webhook_id,
530 notification_id,
531 page_cursor,
532 page_size,
533 } = params;
534
535 let local_var_configuration = &self.configuration;
536
537 let local_var_client = &local_var_configuration.client;
538
539 let local_var_uri_str = format!(
540 "{}/webhooks/{webhookId}/notifications/{notificationId}/attempts",
541 local_var_configuration.base_path,
542 webhookId = crate::apis::urlencode(webhook_id),
543 notificationId = crate::apis::urlencode(notification_id)
544 );
545 let mut local_var_req_builder =
546 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
547
548 if let Some(ref param_value) = page_cursor {
549 local_var_req_builder =
550 local_var_req_builder.query(&[("pageCursor", ¶m_value.to_string())]);
551 }
552 if let Some(ref param_value) = page_size {
553 local_var_req_builder =
554 local_var_req_builder.query(&[("pageSize", ¶m_value.to_string())]);
555 }
556 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
557 local_var_req_builder = local_var_req_builder
558 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
559 }
560
561 let local_var_req = local_var_req_builder.build()?;
562 let local_var_resp = local_var_client.execute(local_var_req).await?;
563
564 let local_var_status = local_var_resp.status();
565 let local_var_content_type = local_var_resp
566 .headers()
567 .get("content-type")
568 .and_then(|v| v.to_str().ok())
569 .unwrap_or("application/octet-stream");
570 let local_var_content_type = super::ContentType::from(local_var_content_type);
571 let local_var_content = local_var_resp.text().await?;
572
573 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
574 match local_var_content_type {
575 ContentType::Json => {
576 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
577 }
578 ContentType::Text => {
579 return Err(Error::from(serde_json::Error::custom(
580 "Received `text/plain` content type response that cannot be converted to \
581 `models::NotificationAttemptsPaginatedResponse`",
582 )));
583 }
584 ContentType::Unsupported(local_var_unknown_type) => {
585 return Err(Error::from(serde_json::Error::custom(format!(
586 "Received `{local_var_unknown_type}` content type response that cannot be \
587 converted to `models::NotificationAttemptsPaginatedResponse`"
588 ))));
589 }
590 }
591 } else {
592 let local_var_entity: Option<GetNotificationAttemptsError> =
593 serde_json::from_str(&local_var_content).ok();
594 let local_var_error = ResponseContent {
595 status: local_var_status,
596 content: local_var_content,
597 entity: local_var_entity,
598 };
599 Err(Error::ResponseError(local_var_error))
600 }
601 }
602
603 async fn get_notifications(
606 &self,
607 params: GetNotificationsParams,
608 ) -> Result<models::NotificationPaginatedResponse, Error<GetNotificationsError>> {
609 let GetNotificationsParams {
610 webhook_id,
611 order,
612 sort_by,
613 page_cursor,
614 page_size,
615 start_time,
616 end_time,
617 statuses,
618 events,
619 resource_id,
620 } = params;
621
622 let local_var_configuration = &self.configuration;
623
624 let local_var_client = &local_var_configuration.client;
625
626 let local_var_uri_str = format!(
627 "{}/webhooks/{webhookId}/notifications",
628 local_var_configuration.base_path,
629 webhookId = crate::apis::urlencode(webhook_id)
630 );
631 let mut local_var_req_builder =
632 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
633
634 if let Some(ref param_value) = order {
635 local_var_req_builder =
636 local_var_req_builder.query(&[("order", ¶m_value.to_string())]);
637 }
638 if let Some(ref param_value) = sort_by {
639 local_var_req_builder =
640 local_var_req_builder.query(&[("sortBy", ¶m_value.to_string())]);
641 }
642 if let Some(ref param_value) = page_cursor {
643 local_var_req_builder =
644 local_var_req_builder.query(&[("pageCursor", ¶m_value.to_string())]);
645 }
646 if let Some(ref param_value) = page_size {
647 local_var_req_builder =
648 local_var_req_builder.query(&[("pageSize", ¶m_value.to_string())]);
649 }
650 if let Some(ref param_value) = start_time {
651 local_var_req_builder =
652 local_var_req_builder.query(&[("startTime", ¶m_value.to_string())]);
653 }
654 if let Some(ref param_value) = end_time {
655 local_var_req_builder =
656 local_var_req_builder.query(&[("endTime", ¶m_value.to_string())]);
657 }
658 if let Some(ref param_value) = statuses {
659 local_var_req_builder = match "multi" {
660 "multi" => local_var_req_builder.query(
661 ¶m_value
662 .into_iter()
663 .map(|p| ("statuses".to_owned(), p.to_string()))
664 .collect::<Vec<(std::string::String, std::string::String)>>(),
665 ),
666 _ => local_var_req_builder.query(&[(
667 "statuses",
668 ¶m_value
669 .into_iter()
670 .map(|p| p.to_string())
671 .collect::<Vec<String>>()
672 .join(",")
673 .to_string(),
674 )]),
675 };
676 }
677 if let Some(ref param_value) = events {
678 local_var_req_builder = match "multi" {
679 "multi" => local_var_req_builder.query(
680 ¶m_value
681 .into_iter()
682 .map(|p| ("events".to_owned(), p.to_string()))
683 .collect::<Vec<(std::string::String, std::string::String)>>(),
684 ),
685 _ => local_var_req_builder.query(&[(
686 "events",
687 ¶m_value
688 .into_iter()
689 .map(|p| p.to_string())
690 .collect::<Vec<String>>()
691 .join(",")
692 .to_string(),
693 )]),
694 };
695 }
696 if let Some(ref param_value) = resource_id {
697 local_var_req_builder =
698 local_var_req_builder.query(&[("resourceId", ¶m_value.to_string())]);
699 }
700 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
701 local_var_req_builder = local_var_req_builder
702 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
703 }
704
705 let local_var_req = local_var_req_builder.build()?;
706 let local_var_resp = local_var_client.execute(local_var_req).await?;
707
708 let local_var_status = local_var_resp.status();
709 let local_var_content_type = local_var_resp
710 .headers()
711 .get("content-type")
712 .and_then(|v| v.to_str().ok())
713 .unwrap_or("application/octet-stream");
714 let local_var_content_type = super::ContentType::from(local_var_content_type);
715 let local_var_content = local_var_resp.text().await?;
716
717 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
718 match local_var_content_type {
719 ContentType::Json => {
720 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
721 }
722 ContentType::Text => {
723 return Err(Error::from(serde_json::Error::custom(
724 "Received `text/plain` content type response that cannot be converted to \
725 `models::NotificationPaginatedResponse`",
726 )));
727 }
728 ContentType::Unsupported(local_var_unknown_type) => {
729 return Err(Error::from(serde_json::Error::custom(format!(
730 "Received `{local_var_unknown_type}` content type response that cannot be \
731 converted to `models::NotificationPaginatedResponse`"
732 ))));
733 }
734 }
735 } else {
736 let local_var_entity: Option<GetNotificationsError> =
737 serde_json::from_str(&local_var_content).ok();
738 let local_var_error = ResponseContent {
739 status: local_var_status,
740 content: local_var_content,
741 entity: local_var_entity,
742 };
743 Err(Error::ResponseError(local_var_error))
744 }
745 }
746
747 async fn get_resend_job_status(
749 &self,
750 params: GetResendJobStatusParams,
751 ) -> Result<models::ResendFailedNotificationsJobStatusResponse, Error<GetResendJobStatusError>>
752 {
753 let GetResendJobStatusParams { webhook_id, job_id } = params;
754
755 let local_var_configuration = &self.configuration;
756
757 let local_var_client = &local_var_configuration.client;
758
759 let local_var_uri_str = format!(
760 "{}/webhooks/{webhookId}/notifications/resend_failed/jobs/{jobId}",
761 local_var_configuration.base_path,
762 webhookId = crate::apis::urlencode(webhook_id),
763 jobId = crate::apis::urlencode(job_id)
764 );
765 let mut local_var_req_builder =
766 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
767
768 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
769 local_var_req_builder = local_var_req_builder
770 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
771 }
772
773 let local_var_req = local_var_req_builder.build()?;
774 let local_var_resp = local_var_client.execute(local_var_req).await?;
775
776 let local_var_status = local_var_resp.status();
777 let local_var_content_type = local_var_resp
778 .headers()
779 .get("content-type")
780 .and_then(|v| v.to_str().ok())
781 .unwrap_or("application/octet-stream");
782 let local_var_content_type = super::ContentType::from(local_var_content_type);
783 let local_var_content = local_var_resp.text().await?;
784
785 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
786 match local_var_content_type {
787 ContentType::Json => {
788 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
789 }
790 ContentType::Text => {
791 return Err(Error::from(serde_json::Error::custom(
792 "Received `text/plain` content type response that cannot be converted to \
793 `models::ResendFailedNotificationsJobStatusResponse`",
794 )));
795 }
796 ContentType::Unsupported(local_var_unknown_type) => {
797 return Err(Error::from(serde_json::Error::custom(format!(
798 "Received `{local_var_unknown_type}` content type response that cannot be \
799 converted to `models::ResendFailedNotificationsJobStatusResponse`"
800 ))));
801 }
802 }
803 } else {
804 let local_var_entity: Option<GetResendJobStatusError> =
805 serde_json::from_str(&local_var_content).ok();
806 let local_var_error = ResponseContent {
807 status: local_var_status,
808 content: local_var_content,
809 entity: local_var_entity,
810 };
811 Err(Error::ResponseError(local_var_error))
812 }
813 }
814
815 async fn get_webhook(
818 &self,
819 params: GetWebhookParams,
820 ) -> Result<models::Webhook, Error<GetWebhookError>> {
821 let GetWebhookParams { webhook_id } = params;
822
823 let local_var_configuration = &self.configuration;
824
825 let local_var_client = &local_var_configuration.client;
826
827 let local_var_uri_str = format!(
828 "{}/webhooks/{webhookId}",
829 local_var_configuration.base_path,
830 webhookId = crate::apis::urlencode(webhook_id)
831 );
832 let mut local_var_req_builder =
833 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
834
835 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
836 local_var_req_builder = local_var_req_builder
837 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
838 }
839
840 let local_var_req = local_var_req_builder.build()?;
841 let local_var_resp = local_var_client.execute(local_var_req).await?;
842
843 let local_var_status = local_var_resp.status();
844 let local_var_content_type = local_var_resp
845 .headers()
846 .get("content-type")
847 .and_then(|v| v.to_str().ok())
848 .unwrap_or("application/octet-stream");
849 let local_var_content_type = super::ContentType::from(local_var_content_type);
850 let local_var_content = local_var_resp.text().await?;
851
852 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
853 match local_var_content_type {
854 ContentType::Json => {
855 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
856 }
857 ContentType::Text => {
858 return Err(Error::from(serde_json::Error::custom(
859 "Received `text/plain` content type response that cannot be converted to \
860 `models::Webhook`",
861 )));
862 }
863 ContentType::Unsupported(local_var_unknown_type) => {
864 return Err(Error::from(serde_json::Error::custom(format!(
865 "Received `{local_var_unknown_type}` content type response that cannot be \
866 converted to `models::Webhook`"
867 ))));
868 }
869 }
870 } else {
871 let local_var_entity: Option<GetWebhookError> =
872 serde_json::from_str(&local_var_content).ok();
873 let local_var_error = ResponseContent {
874 status: local_var_status,
875 content: local_var_content,
876 entity: local_var_entity,
877 };
878 Err(Error::ResponseError(local_var_error))
879 }
880 }
881
882 async fn get_webhooks(
885 &self,
886 params: GetWebhooksParams,
887 ) -> Result<models::WebhookPaginatedResponse, Error<GetWebhooksError>> {
888 let GetWebhooksParams {
889 order,
890 page_cursor,
891 page_size,
892 } = params;
893
894 let local_var_configuration = &self.configuration;
895
896 let local_var_client = &local_var_configuration.client;
897
898 let local_var_uri_str = format!("{}/webhooks", local_var_configuration.base_path);
899 let mut local_var_req_builder =
900 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
901
902 if let Some(ref param_value) = order {
903 local_var_req_builder =
904 local_var_req_builder.query(&[("order", ¶m_value.to_string())]);
905 }
906 if let Some(ref param_value) = page_cursor {
907 local_var_req_builder =
908 local_var_req_builder.query(&[("pageCursor", ¶m_value.to_string())]);
909 }
910 if let Some(ref param_value) = page_size {
911 local_var_req_builder =
912 local_var_req_builder.query(&[("pageSize", ¶m_value.to_string())]);
913 }
914 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
915 local_var_req_builder = local_var_req_builder
916 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
917 }
918
919 let local_var_req = local_var_req_builder.build()?;
920 let local_var_resp = local_var_client.execute(local_var_req).await?;
921
922 let local_var_status = local_var_resp.status();
923 let local_var_content_type = local_var_resp
924 .headers()
925 .get("content-type")
926 .and_then(|v| v.to_str().ok())
927 .unwrap_or("application/octet-stream");
928 let local_var_content_type = super::ContentType::from(local_var_content_type);
929 let local_var_content = local_var_resp.text().await?;
930
931 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
932 match local_var_content_type {
933 ContentType::Json => {
934 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
935 }
936 ContentType::Text => {
937 return Err(Error::from(serde_json::Error::custom(
938 "Received `text/plain` content type response that cannot be converted to \
939 `models::WebhookPaginatedResponse`",
940 )));
941 }
942 ContentType::Unsupported(local_var_unknown_type) => {
943 return Err(Error::from(serde_json::Error::custom(format!(
944 "Received `{local_var_unknown_type}` content type response that cannot be \
945 converted to `models::WebhookPaginatedResponse`"
946 ))));
947 }
948 }
949 } else {
950 let local_var_entity: Option<GetWebhooksError> =
951 serde_json::from_str(&local_var_content).ok();
952 let local_var_error = ResponseContent {
953 status: local_var_status,
954 content: local_var_content,
955 entity: local_var_entity,
956 };
957 Err(Error::ResponseError(local_var_error))
958 }
959 }
960
961 async fn resend_failed_notifications(
965 &self,
966 params: ResendFailedNotificationsParams,
967 ) -> Result<models::ResendFailedNotificationsResponse, Error<ResendFailedNotificationsError>>
968 {
969 let ResendFailedNotificationsParams {
970 webhook_id,
971 resend_failed_notifications_request,
972 idempotency_key,
973 } = params;
974
975 let local_var_configuration = &self.configuration;
976
977 let local_var_client = &local_var_configuration.client;
978
979 let local_var_uri_str = format!(
980 "{}/webhooks/{webhookId}/notifications/resend_failed",
981 local_var_configuration.base_path,
982 webhookId = crate::apis::urlencode(webhook_id)
983 );
984 let mut local_var_req_builder =
985 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
986
987 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
988 local_var_req_builder = local_var_req_builder
989 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
990 }
991 if let Some(local_var_param_value) = idempotency_key {
992 local_var_req_builder =
993 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
994 }
995 local_var_req_builder = local_var_req_builder.json(&resend_failed_notifications_request);
996
997 let local_var_req = local_var_req_builder.build()?;
998 let local_var_resp = local_var_client.execute(local_var_req).await?;
999
1000 let local_var_status = local_var_resp.status();
1001 let local_var_content_type = local_var_resp
1002 .headers()
1003 .get("content-type")
1004 .and_then(|v| v.to_str().ok())
1005 .unwrap_or("application/octet-stream");
1006 let local_var_content_type = super::ContentType::from(local_var_content_type);
1007 let local_var_content = local_var_resp.text().await?;
1008
1009 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
1010 match local_var_content_type {
1011 ContentType::Json => {
1012 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
1013 }
1014 ContentType::Text => {
1015 return Err(Error::from(serde_json::Error::custom(
1016 "Received `text/plain` content type response that cannot be converted to \
1017 `models::ResendFailedNotificationsResponse`",
1018 )));
1019 }
1020 ContentType::Unsupported(local_var_unknown_type) => {
1021 return Err(Error::from(serde_json::Error::custom(format!(
1022 "Received `{local_var_unknown_type}` content type response that cannot be \
1023 converted to `models::ResendFailedNotificationsResponse`"
1024 ))));
1025 }
1026 }
1027 } else {
1028 let local_var_entity: Option<ResendFailedNotificationsError> =
1029 serde_json::from_str(&local_var_content).ok();
1030 let local_var_error = ResponseContent {
1031 status: local_var_status,
1032 content: local_var_content,
1033 entity: local_var_entity,
1034 };
1035 Err(Error::ResponseError(local_var_error))
1036 }
1037 }
1038
1039 async fn resend_notification_by_id(
1042 &self,
1043 params: ResendNotificationByIdParams,
1044 ) -> Result<(), Error<ResendNotificationByIdError>> {
1045 let ResendNotificationByIdParams {
1046 webhook_id,
1047 notification_id,
1048 idempotency_key,
1049 } = params;
1050
1051 let local_var_configuration = &self.configuration;
1052
1053 let local_var_client = &local_var_configuration.client;
1054
1055 let local_var_uri_str = format!(
1056 "{}/webhooks/{webhookId}/notifications/{notificationId}/resend",
1057 local_var_configuration.base_path,
1058 webhookId = crate::apis::urlencode(webhook_id),
1059 notificationId = crate::apis::urlencode(notification_id)
1060 );
1061 let mut local_var_req_builder =
1062 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
1063
1064 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
1065 local_var_req_builder = local_var_req_builder
1066 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
1067 }
1068 if let Some(local_var_param_value) = idempotency_key {
1069 local_var_req_builder =
1070 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
1071 }
1072
1073 let local_var_req = local_var_req_builder.build()?;
1074 let local_var_resp = local_var_client.execute(local_var_req).await?;
1075
1076 let local_var_status = local_var_resp.status();
1077 let local_var_content = local_var_resp.text().await?;
1078
1079 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
1080 Ok(())
1081 } else {
1082 let local_var_entity: Option<ResendNotificationByIdError> =
1083 serde_json::from_str(&local_var_content).ok();
1084 let local_var_error = ResponseContent {
1085 status: local_var_status,
1086 content: local_var_content,
1087 entity: local_var_entity,
1088 };
1089 Err(Error::ResponseError(local_var_error))
1090 }
1091 }
1092
1093 async fn resend_notifications_by_resource_id(
1096 &self,
1097 params: ResendNotificationsByResourceIdParams,
1098 ) -> Result<(), Error<ResendNotificationsByResourceIdError>> {
1099 let ResendNotificationsByResourceIdParams {
1100 webhook_id,
1101 resend_notifications_by_resource_id_request,
1102 idempotency_key,
1103 } = params;
1104
1105 let local_var_configuration = &self.configuration;
1106
1107 let local_var_client = &local_var_configuration.client;
1108
1109 let local_var_uri_str = format!(
1110 "{}/webhooks/{webhookId}/notifications/resend_by_resource",
1111 local_var_configuration.base_path,
1112 webhookId = crate::apis::urlencode(webhook_id)
1113 );
1114 let mut local_var_req_builder =
1115 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
1116
1117 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
1118 local_var_req_builder = local_var_req_builder
1119 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
1120 }
1121 if let Some(local_var_param_value) = idempotency_key {
1122 local_var_req_builder =
1123 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
1124 }
1125 local_var_req_builder =
1126 local_var_req_builder.json(&resend_notifications_by_resource_id_request);
1127
1128 let local_var_req = local_var_req_builder.build()?;
1129 let local_var_resp = local_var_client.execute(local_var_req).await?;
1130
1131 let local_var_status = local_var_resp.status();
1132 let local_var_content = local_var_resp.text().await?;
1133
1134 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
1135 Ok(())
1136 } else {
1137 let local_var_entity: Option<ResendNotificationsByResourceIdError> =
1138 serde_json::from_str(&local_var_content).ok();
1139 let local_var_error = ResponseContent {
1140 status: local_var_status,
1141 content: local_var_content,
1142 entity: local_var_entity,
1143 };
1144 Err(Error::ResponseError(local_var_error))
1145 }
1146 }
1147
1148 async fn update_webhook(
1151 &self,
1152 params: UpdateWebhookParams,
1153 ) -> Result<models::Webhook, Error<UpdateWebhookError>> {
1154 let UpdateWebhookParams {
1155 webhook_id,
1156 update_webhook_request,
1157 } = params;
1158
1159 let local_var_configuration = &self.configuration;
1160
1161 let local_var_client = &local_var_configuration.client;
1162
1163 let local_var_uri_str = format!(
1164 "{}/webhooks/{webhookId}",
1165 local_var_configuration.base_path,
1166 webhookId = crate::apis::urlencode(webhook_id)
1167 );
1168 let mut local_var_req_builder =
1169 local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
1170
1171 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
1172 local_var_req_builder = local_var_req_builder
1173 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
1174 }
1175 local_var_req_builder = local_var_req_builder.json(&update_webhook_request);
1176
1177 let local_var_req = local_var_req_builder.build()?;
1178 let local_var_resp = local_var_client.execute(local_var_req).await?;
1179
1180 let local_var_status = local_var_resp.status();
1181 let local_var_content_type = local_var_resp
1182 .headers()
1183 .get("content-type")
1184 .and_then(|v| v.to_str().ok())
1185 .unwrap_or("application/octet-stream");
1186 let local_var_content_type = super::ContentType::from(local_var_content_type);
1187 let local_var_content = local_var_resp.text().await?;
1188
1189 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
1190 match local_var_content_type {
1191 ContentType::Json => {
1192 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
1193 }
1194 ContentType::Text => {
1195 return Err(Error::from(serde_json::Error::custom(
1196 "Received `text/plain` content type response that cannot be converted to \
1197 `models::Webhook`",
1198 )));
1199 }
1200 ContentType::Unsupported(local_var_unknown_type) => {
1201 return Err(Error::from(serde_json::Error::custom(format!(
1202 "Received `{local_var_unknown_type}` content type response that cannot be \
1203 converted to `models::Webhook`"
1204 ))));
1205 }
1206 }
1207 } else {
1208 let local_var_entity: Option<UpdateWebhookError> =
1209 serde_json::from_str(&local_var_content).ok();
1210 let local_var_error = ResponseContent {
1211 status: local_var_status,
1212 content: local_var_content,
1213 entity: local_var_entity,
1214 };
1215 Err(Error::ResponseError(local_var_error))
1216 }
1217 }
1218}
1219
1220#[derive(Debug, Clone, Serialize, Deserialize)]
1222#[serde(untagged)]
1223pub enum CreateWebhookError {
1224 DefaultResponse(models::ErrorSchema),
1225 UnknownValue(serde_json::Value),
1226}
1227
1228#[derive(Debug, Clone, Serialize, Deserialize)]
1230#[serde(untagged)]
1231pub enum DeleteWebhookError {
1232 DefaultResponse(models::ErrorSchema),
1233 UnknownValue(serde_json::Value),
1234}
1235
1236#[derive(Debug, Clone, Serialize, Deserialize)]
1238#[serde(untagged)]
1239pub enum GetNotificationError {
1240 UnknownValue(serde_json::Value),
1241}
1242
1243#[derive(Debug, Clone, Serialize, Deserialize)]
1246#[serde(untagged)]
1247pub enum GetNotificationAttemptsError {
1248 DefaultResponse(models::ErrorSchema),
1249 UnknownValue(serde_json::Value),
1250}
1251
1252#[derive(Debug, Clone, Serialize, Deserialize)]
1254#[serde(untagged)]
1255pub enum GetNotificationsError {
1256 UnknownValue(serde_json::Value),
1257}
1258
1259#[derive(Debug, Clone, Serialize, Deserialize)]
1261#[serde(untagged)]
1262pub enum GetResendJobStatusError {
1263 DefaultResponse(models::ErrorSchema),
1264 UnknownValue(serde_json::Value),
1265}
1266
1267#[derive(Debug, Clone, Serialize, Deserialize)]
1269#[serde(untagged)]
1270pub enum GetWebhookError {
1271 DefaultResponse(models::ErrorSchema),
1272 UnknownValue(serde_json::Value),
1273}
1274
1275#[derive(Debug, Clone, Serialize, Deserialize)]
1277#[serde(untagged)]
1278pub enum GetWebhooksError {
1279 DefaultResponse(models::ErrorSchema),
1280 UnknownValue(serde_json::Value),
1281}
1282
1283#[derive(Debug, Clone, Serialize, Deserialize)]
1286#[serde(untagged)]
1287pub enum ResendFailedNotificationsError {
1288 DefaultResponse(models::ErrorSchema),
1289 UnknownValue(serde_json::Value),
1290}
1291
1292#[derive(Debug, Clone, Serialize, Deserialize)]
1295#[serde(untagged)]
1296pub enum ResendNotificationByIdError {
1297 DefaultResponse(models::ErrorSchema),
1298 UnknownValue(serde_json::Value),
1299}
1300
1301#[derive(Debug, Clone, Serialize, Deserialize)]
1304#[serde(untagged)]
1305pub enum ResendNotificationsByResourceIdError {
1306 DefaultResponse(models::ErrorSchema),
1307 UnknownValue(serde_json::Value),
1308}
1309
1310#[derive(Debug, Clone, Serialize, Deserialize)]
1312#[serde(untagged)]
1313pub enum UpdateWebhookError {
1314 DefaultResponse(models::ErrorSchema),
1315 UnknownValue(serde_json::Value),
1316}