sentd 1.0.0

Official Rust SDK for the SENTD Email API
Documentation
use serde::Serialize;

use crate::client::Sentd;
use crate::error::Error;
use crate::types::*;

/// Webhooks API
pub struct Webhooks {
    client: Sentd,
}

impl Webhooks {
    pub(crate) fn new(client: Sentd) -> Self {
        Self { client }
    }

    /// List all webhooks
    pub async fn list(&self) -> Result<ListWebhooksResponse, Error> {
        self.client.get("/api/webhooks").await
    }

    /// Get a webhook by ID
    pub async fn get(&self, id: &str) -> Result<WebhookResponse, Error> {
        self.client.get(&format!("/api/webhooks/{}", id)).await
    }

    /// Create a new webhook
    pub async fn create(&self, request: CreateWebhookRequest) -> Result<WebhookResponse, Error> {
        self.client.post("/api/webhooks", &request).await
    }

    /// Update a webhook
    pub async fn update(&self, id: &str, request: UpdateWebhookRequest) -> Result<WebhookResponse, Error> {
        self.client.put(&format!("/api/webhooks/{}", id), &request).await
    }

    /// Delete a webhook
    pub async fn delete(&self, id: &str) -> Result<SuccessResponse, Error> {
        self.client.delete(&format!("/api/webhooks/{}", id)).await
    }

    /// Rotate a webhook's secret
    pub async fn rotate_secret(&self, id: &str) -> Result<WebhookResponse, Error> {
        self.client.post(&format!("/api/webhooks/{}/rotate-secret", id), &()).await
    }

    /// Test a webhook
    pub async fn test(&self, id: &str) -> Result<TestWebhookResponse, Error> {
        self.client.post(&format!("/api/webhooks/{}/test", id), &()).await
    }
}

/// Request to update a webhook
#[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>,
}

/// Response from testing a webhook
#[derive(Debug, Clone, serde::Deserialize)]
pub struct TestWebhookResponse {
    pub success: bool,
    pub status_code: Option<i32>,
}