dfns_sdk_rust/webhooks/
mod.rs1pub mod delegated;
4pub mod types;
5
6#[allow(unused_imports)]
7use types::*;
8
9#[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 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 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 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 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 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 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 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 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}