use std::sync::Arc;
use crate::error::Result;
use crate::http::HttpClient;
use crate::resources::to_value;
use crate::response::Response;
use crate::transport::Method;
use crate::types::email::{BatchEmail, SendEmail};
pub struct Email {
http: Arc<HttpClient>,
}
impl Email {
pub(crate) fn new(http: Arc<HttpClient>) -> Self {
Self { http }
}
pub async fn send(&self, email: &SendEmail) -> Result<Response> {
self.http
.request_object(Method::Post, "/email", Some(to_value(email)?), true, None)
.await
}
pub async fn send_with_idempotency_key(
&self,
email: &SendEmail,
key: &str,
) -> Result<Response> {
self.http
.request_object(
Method::Post,
"/email",
Some(to_value(email)?),
true,
Some(key),
)
.await
}
pub async fn send_batch(&self, batch: &BatchEmail) -> Result<Response> {
self.http
.request_object(
Method::Post,
"/email/batch",
Some(to_value(batch)?),
true,
None,
)
.await
}
pub async fn send_batch_with_idempotency_key(
&self,
batch: &BatchEmail,
key: &str,
) -> Result<Response> {
self.http
.request_object(
Method::Post,
"/email/batch",
Some(to_value(batch)?),
true,
Some(key),
)
.await
}
}