Skip to main content

dfns_sdk_rust/webhooks/
mod.rs

1// Code generated by rust-sdk-generator. DO NOT EDIT.
2
3pub mod types;
4
5#[allow(unused_imports)]
6use types::*;
7
8/// Client for webhooks operations.
9#[derive(Clone)]
10pub struct WebhooksClient {
11    client: crate::client::Client,
12}
13
14impl WebhooksClient {
15    pub fn new(client: crate::client::Client) -> Self {
16        WebhooksClient { client }
17    }
18
19    /// List all webhooks for the authenticated user's organization. The results are paginated.
20    pub async fn list_webhooks(
21        &self,
22        query: Option<ListWebhooksQuery>,
23    ) -> Result<ListWebhooksResponse, crate::error::Error> {
24        let mut path = String::from("/webhooks");
25        if let Some(query) = &query {
26            let mut q: Vec<String> = Vec::new();
27            if let Some(v) = &query.limit {
28                q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
29            }
30            if let Some(v) = &query.pagination_token {
31                q.push(format!(
32                    "paginationToken={}",
33                    urlencoding::encode(&v.to_string())
34                ));
35            }
36            if !q.is_empty() {
37                path.push('?');
38                path.push_str(&q.join("&"));
39            }
40        }
41        self.client
42            .request::<ListWebhooksResponse>(reqwest::Method::GET, &path, None, false)
43            .await
44    }
45
46    /// Register a new webhook.
47    pub async fn create_webhook(
48        &self,
49        body: CreateWebhookRequest,
50    ) -> Result<CreateWebhookResponse, crate::error::Error> {
51        let path = String::from("/webhooks");
52        let body = serde_json::to_value(&body)?;
53        self.client
54            .request::<CreateWebhookResponse>(reqwest::Method::POST, &path, Some(&body), true)
55            .await
56    }
57
58    /// Retrieve information about a specific webhook.
59    pub async fn get_webhook(
60        &self,
61        webhook_id: String,
62    ) -> Result<GetWebhookResponse, crate::error::Error> {
63        let path = format!("/webhooks/{}", urlencoding::encode(&webhook_id));
64        self.client
65            .request::<GetWebhookResponse>(reqwest::Method::GET, &path, None, false)
66            .await
67    }
68
69    /// Update the definition of an existing webhook.
70    pub async fn update_webhook(
71        &self,
72        webhook_id: String,
73        body: UpdateWebhookRequest,
74    ) -> Result<UpdateWebhookResponse, crate::error::Error> {
75        let path = format!("/webhooks/{}", urlencoding::encode(&webhook_id));
76        let body = serde_json::to_value(&body)?;
77        self.client
78            .request::<UpdateWebhookResponse>(reqwest::Method::PUT, &path, Some(&body), true)
79            .await
80    }
81
82    /// Deletes an existing webhook registration.
83    pub async fn delete_webhook(
84        &self,
85        webhook_id: String,
86    ) -> Result<DeleteWebhookResponse, crate::error::Error> {
87        let path = format!("/webhooks/{}", urlencoding::encode(&webhook_id));
88        self.client
89            .request::<DeleteWebhookResponse>(reqwest::Method::DELETE, &path, None, true)
90            .await
91    }
92
93    /// This endpoint is meant for webhook setup and troubleshooting. Calling the endpoint will trigger a fake test event that will be pushed to the webhook URL. The fake event will not be saved and not appear in further requests to Webhook Events.
94    pub async fn ping_webhook(
95        &self,
96        webhook_id: String,
97    ) -> Result<PingWebhookResponse, crate::error::Error> {
98        let path = format!("/webhooks/{}/ping", urlencoding::encode(&webhook_id));
99        self.client
100            .request::<PingWebhookResponse>(reqwest::Method::POST, &path, None, true)
101            .await
102    }
103
104    /// Retrieve a specific webhook event details by its ID.
105    ///   
106    /// <Warning>
107    /// We only keep a trace of those Webhook Events in our system for a **retention period of 31 days**. Past that, they are discarded, so you cannot see them using [List Webhook Events](https://docs.dfns.co/api-reference/webhooks/list-webhook-events) or [Get Webhook Event](https://docs.dfns.co/api-reference/webhooks/get-webhook-event) endpoints.
108    pub async fn get_webhook_event(
109        &self,
110        webhook_id: String,
111        webhook_event_id: String,
112    ) -> Result<GetWebhookEventResponse, crate::error::Error> {
113        let path = format!(
114            "/webhooks/{}/events/{}",
115            urlencoding::encode(&webhook_id),
116            urlencoding::encode(&webhook_event_id)
117        );
118        self.client
119            .request::<GetWebhookEventResponse>(reqwest::Method::GET, &path, None, false)
120            .await
121    }
122
123    /// Lists all events for a given webhook.
124    ///
125    ///
126    /// <Warning>
127    pub async fn list_webhook_events(
128        &self,
129        webhook_id: String,
130        query: Option<ListWebhookEventsQuery>,
131    ) -> Result<ListWebhookEventsResponse, crate::error::Error> {
132        let mut path = format!("/webhooks/{}/events", urlencoding::encode(&webhook_id));
133        if let Some(query) = &query {
134            let mut q: Vec<String> = Vec::new();
135            if let Some(v) = &query.kind {
136                q.push(format!("kind={}", urlencoding::encode(&v.to_string())));
137            }
138            if let Some(v) = &query.delivery_failed {
139                q.push(format!(
140                    "deliveryFailed={}",
141                    urlencoding::encode(&v.to_string())
142                ));
143            }
144            if let Some(v) = &query.limit {
145                q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
146            }
147            if let Some(v) = &query.pagination_token {
148                q.push(format!(
149                    "paginationToken={}",
150                    urlencoding::encode(&v.to_string())
151                ));
152            }
153            if !q.is_empty() {
154                path.push('?');
155                path.push_str(&q.join("&"));
156            }
157        }
158        self.client
159            .request::<ListWebhookEventsResponse>(reqwest::Method::GET, &path, None, false)
160            .await
161    }
162}