use std::sync::Arc;
use crate::error::Result;
use crate::http::Config;
use crate::types::{
BatchResponse, CancelEmailResponse, CreateEmailResponse, Email, SendEmailOptions,
};
#[derive(Clone)]
pub struct Emails(pub(crate) Arc<Config>);
impl Emails {
pub async fn send(&self, email: &SendEmailOptions) -> Result<CreateEmailResponse> {
self.0.post(&["emails"], email, None).await
}
pub async fn send_with_idempotency_key(
&self,
email: &SendEmailOptions,
idempotency_key: &str,
) -> Result<CreateEmailResponse> {
self.0.post(&["emails"], email, Some(idempotency_key)).await
}
pub async fn get(&self, id: &str) -> Result<Email> {
self.0.get(&["emails", id], &[]).await
}
pub async fn cancel(&self, id: &str) -> Result<CancelEmailResponse> {
self.0.post_empty(&["emails", id, "cancel"]).await
}
}
#[derive(Clone)]
pub struct Batch(pub(crate) Arc<Config>);
impl Batch {
pub async fn send(&self, emails: &[SendEmailOptions]) -> Result<BatchResponse> {
self.0.post(&["emails", "batch"], emails, None).await
}
pub async fn send_with_idempotency_key(
&self,
emails: &[SendEmailOptions],
idempotency_key: &str,
) -> Result<BatchResponse> {
self.0
.post(&["emails", "batch"], emails, Some(idempotency_key))
.await
}
}