use serde::Serialize;
use crate::client::Sentd;
use crate::error::Error;
use crate::types::*;
pub struct Webhooks {
client: Sentd,
}
impl Webhooks {
pub(crate) fn new(client: Sentd) -> Self {
Self { client }
}
pub async fn list(&self) -> Result<ListWebhooksResponse, Error> {
self.client.get("/api/webhooks").await
}
pub async fn get(&self, id: &str) -> Result<WebhookResponse, Error> {
self.client.get(&format!("/api/webhooks/{}", id)).await
}
pub async fn create(&self, request: CreateWebhookRequest) -> Result<WebhookResponse, Error> {
self.client.post("/api/webhooks", &request).await
}
pub async fn update(&self, id: &str, request: UpdateWebhookRequest) -> Result<WebhookResponse, Error> {
self.client.put(&format!("/api/webhooks/{}", id), &request).await
}
pub async fn delete(&self, id: &str) -> Result<SuccessResponse, Error> {
self.client.delete(&format!("/api/webhooks/{}", id)).await
}
pub async fn rotate_secret(&self, id: &str) -> Result<WebhookResponse, Error> {
self.client.post(&format!("/api/webhooks/{}/rotate-secret", id), &()).await
}
pub async fn test(&self, id: &str) -> Result<TestWebhookResponse, Error> {
self.client.post(&format!("/api/webhooks/{}/test", id), &()).await
}
}
#[derive(Debug, Clone, Serialize, Default)]
pub struct UpdateWebhookRequest {
#[serde(skip_serializing_if = "Option::is_none")]
pub url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub events: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub active: Option<bool>,
}
#[derive(Debug, Clone, serde::Deserialize)]
pub struct TestWebhookResponse {
pub success: bool,
pub status_code: Option<i32>,
}