use crate::client::Client;
use crate::error::Error;
use crate::types::{
CreateWebhookRequest, EmptyResponse, ItemsList, UpdateWebhookRequest,
Webhook, WebhookTestResponse,
};
pub struct Webhooks<'a> {
client: &'a Client,
}
impl<'a> Webhooks<'a> {
pub fn new(client: &'a Client) -> Self {
Self { client }
}
pub async fn list(&self) -> Result<ItemsList<Webhook>, Error> {
self.client.get("/webhooks").await
}
pub async fn get(&self, id: &str) -> Result<Webhook, Error> {
self.client.get(&format!("/webhooks/{}", id)).await
}
pub async fn create(&self, data: CreateWebhookRequest) -> Result<Webhook, Error> {
self.client.post("/webhooks", &data).await
}
pub async fn update(
&self,
id: &str,
data: UpdateWebhookRequest,
) -> Result<Webhook, Error> {
self.client
.put(&format!("/webhooks/{}", id), &data)
.await
}
pub async fn delete(&self, id: &str) -> Result<EmptyResponse, Error> {
self.client.delete(&format!("/webhooks/{}", id)).await
}
pub async fn test(&self, id: &str) -> Result<WebhookTestResponse, Error> {
self.client
.post(&format!("/webhooks/{}/test", id), &serde_json::json!({}))
.await
}
pub async fn list_events(&self) -> Result<serde_json::Value, Error> {
self.client.get("/webhooks/events").await
}
}