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