unosend 1.0.0

Official Rust SDK for Unosend - Email API for developers
Documentation
use crate::client::Unosend;
use crate::error::UnosendError;
use serde::{Deserialize, Serialize};

/// Domain management API.
pub struct DomainsApi {
    client: Unosend,
}

impl DomainsApi {
    pub(crate) fn new(client: Unosend) -> Self {
        Self { client }
    }

    /// Add a new domain.
    pub async fn create(&self, domain: &str) -> Result<Domain, UnosendError> {
        self.client
            .post("/domains", &CreateDomainRequest { domain: domain.to_string() })
            .await
    }

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

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

    /// Verify a domain's DNS records.
    pub async fn verify(&self, domain_id: &str) -> Result<Domain, UnosendError> {
        self.client
            .post(&format!("/domains/{}/verify", domain_id), &())
            .await
    }

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

#[derive(Serialize)]
struct CreateDomainRequest {
    domain: String,
}

/// Domain information.
#[derive(Debug, Clone, Deserialize)]
pub struct Domain {
    pub id: String,
    pub name: String,
    pub status: String,
    pub records: Option<Vec<DnsRecord>>,
    pub created_at: String,
}

/// DNS record for domain verification.
#[derive(Debug, Clone, Deserialize)]
pub struct DnsRecord {
    pub r#type: String,
    pub name: String,
    pub value: String,
    pub status: String,
}

/// List of domains.
#[derive(Debug, Clone, Deserialize)]
pub struct DomainList {
    pub data: Vec<Domain>,
}