use crate::client::Unosend;
use crate::error::UnosendError;
use serde::{Deserialize, Serialize};
pub struct DomainsApi {
client: Unosend,
}
impl DomainsApi {
pub(crate) fn new(client: Unosend) -> Self {
Self { client }
}
pub async fn create(&self, domain: &str) -> Result<Domain, UnosendError> {
self.client
.post("/domains", &CreateDomainRequest { domain: domain.to_string() })
.await
}
pub async fn list(&self) -> Result<DomainList, UnosendError> {
self.client.get("/domains").await
}
pub async fn get(&self, domain_id: &str) -> Result<Domain, UnosendError> {
self.client.get(&format!("/domains/{}", domain_id)).await
}
pub async fn verify(&self, domain_id: &str) -> Result<Domain, UnosendError> {
self.client
.post(&format!("/domains/{}/verify", domain_id), &())
.await
}
pub async fn delete(&self, domain_id: &str) -> Result<(), UnosendError> {
self.client.delete(&format!("/domains/{}", domain_id)).await
}
}
#[derive(Serialize)]
struct CreateDomainRequest {
domain: String,
}
#[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,
}
#[derive(Debug, Clone, Deserialize)]
pub struct DnsRecord {
pub r#type: String,
pub name: String,
pub value: String,
pub status: String,
}
#[derive(Debug, Clone, Deserialize)]
pub struct DomainList {
pub data: Vec<Domain>,
}