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::*;

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

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

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

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

    /// Add a new domain
    pub async fn add(&self, domain: &str) -> Result<DomainResponse, Error> {
        #[derive(Serialize)]
        struct AddDomainRequest<'a> {
            domain: &'a str,
        }

        self.client.post("/api/domains", &AddDomainRequest { domain }).await
    }

    /// Verify a domain
    pub async fn verify(&self, id: &str) -> Result<VerifyDomainResponse, Error> {
        self.client.post(&format!("/api/domains/{}/verify", id), &()).await
    }

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