use reqwest::Method;
use serde::{Deserialize, Serialize};
use crate::{client::Sendry, error::Error, Page};
#[derive(Debug, Clone)]
pub struct Domains {
client: Sendry,
}
impl Domains {
pub(crate) fn new(client: Sendry) -> Self {
Self { client }
}
pub async fn create(&self, params: DomainParams) -> Result<Domain, Error> {
self.client
.request(
self.client
.build(Method::POST, "/v1/domains", &[], Some(¶ms)),
)
.await
}
pub async fn verify(&self, id: &str) -> Result<Domain, Error> {
self.client
.request(self.client.build::<()>(
Method::POST,
&format!("/v1/domains/{id}/verify"),
&[],
None,
))
.await
}
pub async fn get(&self, id: &str) -> Result<Domain, Error> {
self.client
.request(
self.client
.build::<()>(Method::GET, &format!("/v1/domains/{id}"), &[], None),
)
.await
}
pub async fn list(&self) -> Result<Page<Domain>, Error> {
self.client
.request(
self.client
.build::<()>(Method::GET, "/v1/domains", &[], None),
)
.await
}
pub async fn delete(&self, id: &str) -> Result<(), Error> {
self.client
.request_unit(self.client.build::<()>(
Method::DELETE,
&format!("/v1/domains/{id}"),
&[],
None,
))
.await
}
}
#[derive(Debug, Clone, Serialize)]
pub struct DomainParams {
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub region: Option<String>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct Domain {
pub id: String,
pub name: String,
pub status: String,
pub created_at: String,
}