use crate::{Paging, Param, ParamError, ParamList};
#[derive(Debug)]
pub enum GetEventsParam<'a> {
Pretty(bool),
Begin(&'a str),
End(&'a str),
Ascending(bool),
Limit(usize),
Event(&'a str),
List(&'a str),
Attachment(&'a str),
From(&'a str),
MessageId(&'a str),
Subject(&'a str),
To(&'a str),
Size(&'a str),
Recipient(&'a str),
Recipients(&'a str),
Tags(&'a str),
Severity(&'a str),
}
impl<'a> Param for GetEventsParam<'a> {
fn try_as_tuple(&self) -> Result<(String, String), ParamError> {
Ok(match self {
Self::Pretty(v) => ("pretty".to_string(), v.to_string()),
Self::Begin(v) => ("begin".to_string(), v.to_string()),
Self::End(v) => ("end".to_string(), v.to_string()),
Self::Ascending(v) => ("ascending".to_string(), if *v { "yes".to_string() } else { "no".to_string() }),
Self::Limit(v) => ("limit".to_string(), v.to_string()),
Self::Event(v) => ("event".to_string(), v.to_string()),
Self::List(v) => ("list".to_string(), v.to_string()),
Self::Attachment(v) => ("attachment".to_string(), v.to_string()),
Self::From(v) => ("from".to_string(), v.to_string()),
Self::MessageId(v) => ("message_id".to_string(), v.to_string()),
Self::Subject(v) => ("subject".to_string(), v.to_string()),
Self::To(v) => ("to".to_string(), v.to_string()),
Self::Size(v) => ("size".to_string(), v.to_string()),
Self::Recipient(v) => ("recipient".to_string(), v.to_string()),
Self::Recipients(v) => ("recipients".to_string(), v.to_string()),
Self::Tags(v) => ("tags".to_string(), v.to_string()),
Self::Severity(v) => ("severity".to_string(), v.to_string()),
})
}
}
#[derive(Debug)]
pub struct GetEventsParamList<'a> {
pub values: Vec<GetEventsParam<'a>>,
}
impl<'a> Default for GetEventsParamList<'a> {
fn default() -> Self {
Self {
values: vec![
GetEventsParam::Pretty(false),
],
}
}
}
impl<'a> ParamList for GetEventsParamList<'a> {
type ParamType = GetEventsParam<'a>;
fn add(mut self, param: Self::ParamType) -> Self {
self.values.push(param);
self
}
}
#[derive(Debug, Deserialize, Serialize)]
pub struct GetEventsResponse {
pub items: Vec<EventItem>,
pub paging: Paging,
}
#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
pub struct EventItem {
pub event: String,
pub id: String,
pub timestamp: f64,
pub log_level: Option<String>,
pub method: Option<String>,
pub severity: Option<String>,
pub envelope: Option<EventEnvelope>,
pub flags: Option<EventFlags>,
pub reject: Option<EventReject>,
pub delivery_status: Option<EventDeliveryStatus>,
pub message: EventMessage,
pub storage: Option<EventStorage>,
pub recipient: String,
pub recipient_domain: Option<String>,
pub geolocation: Option<EventGeolocation>,
pub tags: Option<Vec<String>>,
pub ip: Option<String>,
pub client_info: Option<EventClientInfo>,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct EventEnvelope {
pub targets: String,
pub transport: String,
pub sender: String,
}
#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
pub struct EventFlags {
pub is_authenticated: Option<bool>,
pub is_delayed_bounce: Option<bool>,
pub is_routed: Option<bool>,
pub is_system_test: Option<bool>,
pub is_test_mode: Option<bool>,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct EventReject {
pub reason: Option<String>,
pub description: Option<String>,
}
#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
pub struct EventDeliveryStatus {
pub tls: Option<bool>,
pub mx_host: Option<String>,
pub code: Option<i64>,
pub description: Option<String>,
pub session_seconds: Option<f64>,
pub utf8: Option<bool>,
pub attempt_no: Option<usize>,
pub message: Option<String>,
pub certificate_verified: Option<bool>,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct EventMessage {
pub headers: Option<EventMessageHeader>,
pub attachments: Option<Vec<EventMessageAttachment>>,
pub recipients: Option<Vec<String>>,
pub size: Option<i64>,
}
#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
pub struct EventMessageHeader {
pub to: Option<String>,
pub message_id: Option<String>,
pub from: Option<String>,
pub subject: Option<String>,
}
#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
pub struct EventMessageAttachment {
pub size: Option<i64>,
pub content_type: Option<String>,
pub filename: Option<String>,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct EventStorage {
pub url: String,
pub key: String,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct EventGeolocation {
pub country: String,
pub region: String,
pub city: String,
}
#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
pub struct EventClientInfo {
pub client_type: Option<String>,
pub client_os: Option<String>,
pub device_type: Option<String>,
pub client_name: Option<String>,
pub user_agent: Option<String>,
}