use std::sync::Arc;
use serde::Serialize;
use serde_json::Value;
use crate::client::Inner;
use crate::error::Result;
use crate::params;
const BASE: &str = "/v1/emails/inbound";
#[derive(Clone, Debug)]
pub struct InboundEmails {
inner: Arc<Inner>,
pub attachments: InboundAttachments,
}
impl InboundEmails {
pub(crate) fn new(inner: Arc<Inner>) -> Self {
Self {
attachments: InboundAttachments::new(Arc::clone(&inner)),
inner,
}
}
pub async fn list(&self, params: impl Serialize) -> Result<Value> {
self.inner
.call("GET", &format!("{BASE}{}", params::query(params)?), None)
.await
}
pub async fn get(&self, id: &str) -> Result<Value> {
self.inner
.call("GET", &format!("{BASE}/{}", params::encode(id)), None)
.await
}
pub async fn reply(&self, id: &str, params: impl Serialize) -> Result<Value> {
self.inner
.call(
"POST",
&format!("{BASE}/{}/reply", crate::params::encode(id)),
crate::params::to_body(params)?,
)
.await
}
}
#[derive(Clone, Debug)]
pub struct InboundAttachments {
inner: Arc<Inner>,
}
impl InboundAttachments {
pub(crate) fn new(inner: Arc<Inner>) -> Self {
Self { inner }
}
pub async fn list(&self, id: &str) -> Result<Value> {
self.inner
.call(
"GET",
&format!("{BASE}/{}/attachments", params::encode(id)),
None,
)
.await
}
pub async fn get(&self, id: &str, attachment_id: &str) -> Result<Value> {
self.inner
.call(
"GET",
&format!(
"{BASE}/{}/attachments/{}",
params::encode(id),
params::encode(attachment_id)
),
None,
)
.await
}
}