use crate::{Client, Result};
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct DeliveryStat {
pub name: String,
#[serde(rename = "Type")]
pub bounce_type: Option<String>,
pub count: i64,
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct DeliveryStatsResponse {
pub inactive_mails: i64,
pub bounces: Vec<DeliveryStat>,
}
#[derive(Debug, Serialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct BouncesQueryParamaters {
pub count: u16,
pub offset: u16,
#[serde(rename = "type")]
pub bounce_type: Option<String>,
pub inactive: Option<bool>,
pub email_filter: Option<String>,
pub tag: Option<String>,
pub message_id: Option<String>,
#[serde(rename = "fromdate")]
pub from_date: Option<String>,
#[serde(rename = "todate")]
pub to_date: Option<String>,
pub message_stream: Option<String>,
}
impl BouncesQueryParamaters {
pub fn new(count: u16, offset: u16) -> BouncesQueryParamaters {
BouncesQueryParamaters{
count,
offset,
..Default::default()
}
}
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct BouncedEmail {
#[serde(rename = "ID")]
pub id: String,
#[serde(rename = "Type")]
pub bounce_type: String,
pub type_code: String,
pub name: String,
pub tag: String,
#[serde(rename = "MessageID")]
pub message_id: String,
#[serde(rename = "ServerID")]
pub server_id: String,
pub message_stream: String,
pub description: String,
pub details: String,
pub email: String,
pub from: String,
pub bounced_at: String,
pub dump_available: bool,
pub inactive: bool,
pub can_activate: bool,
pub subject: String,
pub content: String,
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct BouncedEmailsReponse {
pub total_count: u16,
pub bounces: Vec<BouncedEmail>,
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct BounceDumpResponse {
pub body: String,
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct ActivateBounceResponse {
pub message: String,
pub bounce: BouncedEmail,
}
impl Client {
pub async fn get_delivery_stats(&self) -> Result<DeliveryStatsResponse> {
Ok(self.get("/deliverystats").await?)
}
pub async fn get_bounces(
&self,
query: &BouncesQueryParamaters,
) -> Result<BouncedEmailsReponse> {
Ok(self.get_with_query("/bounces", query).await?)
}
pub async fn get_bounce(&self, bounce_id: &str) -> Result<BouncedEmail> {
Ok(self
.get(format!("/bounces/{:}", bounce_id).as_str())
.await?)
}
pub async fn get_bounce_dump(&self, bounce_id: &str) -> Result<BounceDumpResponse> {
Ok(self
.get(format!("/bounces/{:}/dump", bounce_id).as_str())
.await?)
}
pub async fn activate_bounce(&self, bounce_id: &str) -> Result<ActivateBounceResponse> {
Ok(self
.put(format!("/bounces/{:}/activate", bounce_id).as_str())
.await?)
}
}