Skip to main content

dfns_sdk_rust/webhooks/
mod.rs

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