vynfi/resources/
webhooks.rs1use reqwest::Method;
2
3use crate::client::{extract_list, Client};
4use crate::error::VynFiError;
5use crate::types::*;
6
7pub struct Webhooks<'a> {
9 client: &'a Client,
10}
11
12impl<'a> Webhooks<'a> {
13 pub(crate) fn new(client: &'a Client) -> Self {
14 Self { client }
15 }
16
17 pub async fn create(&self, req: &CreateWebhookRequest) -> Result<WebhookCreated, VynFiError> {
20 self.client
21 .request_with_body(Method::POST, "/v1/webhooks", Some(req))
22 .await
23 }
24
25 pub async fn list(&self) -> Result<Vec<Webhook>, VynFiError> {
27 let value: serde_json::Value = self.client.request(Method::GET, "/v1/webhooks").await?;
28 extract_list(value)
29 }
30
31 pub async fn get(&self, webhook_id: &str) -> Result<WebhookDetail, VynFiError> {
33 self.client
34 .request(Method::GET, &format!("/v1/webhooks/{}", webhook_id))
35 .await
36 }
37
38 pub async fn update(
40 &self,
41 webhook_id: &str,
42 req: &UpdateWebhookRequest,
43 ) -> Result<Webhook, VynFiError> {
44 self.client
45 .request_with_body(
46 Method::PATCH,
47 &format!("/v1/webhooks/{}", webhook_id),
48 Some(req),
49 )
50 .await
51 }
52
53 pub async fn delete(&self, webhook_id: &str) -> Result<(), VynFiError> {
55 self.client
56 .request::<()>(Method::DELETE, &format!("/v1/webhooks/{}", webhook_id))
57 .await
58 }
59
60 pub async fn test(&self, webhook_id: &str) -> Result<serde_json::Value, VynFiError> {
62 self.client
63 .request_with_body::<serde_json::Value, ()>(
64 Method::POST,
65 &format!("/v1/webhooks/{}/test", webhook_id),
66 None,
67 )
68 .await
69 }
70}