use serde::Serialize;
pub mod attachment;
pub mod mail_settings;
pub mod message;
pub mod personalization;
pub mod tracking_settings;
pub use crate::attachment::AttachmentBuilder;
pub use crate::mail_settings::MailSettingsBuilder;
pub use crate::message::MessageBuilder;
pub use crate::personalization::PersonalizationBuilder;
pub use crate::tracking_settings::{GaTrackingSettingBuilder, TrackingSettingsBuilder};
#[derive(Debug, Serialize)]
pub struct Asm {
group_id: i32,
groups_to_display: Vec<i32>,
}
pub struct AsmBuilder {
asm: Asm,
}
impl AsmBuilder {
pub fn new(group_id: i32) -> Self {
AsmBuilder {
asm: Asm {
group_id,
groups_to_display: vec![],
},
}
}
pub fn group_to_display(mut self, group: i32) -> Self {
self.asm.groups_to_display.push(group);
self
}
pub fn build(self) -> Asm {
self.asm
}
}
#[derive(Debug, Serialize)]
pub struct Content {
#[serde(rename = "type")]
c_type: String,
value: String,
}
impl Content {
pub fn new<S: Into<String>>(c_type: S, value: S) -> Self {
Content {
c_type: c_type.into(),
value: value.into(),
}
}
}
#[derive(Serialize, Debug)]
pub struct Contact {
email: String,
name: Option<String>,
}
impl Contact {
fn new(email: impl Into<String>, name: Option<String>) -> Contact {
Contact {
email: email.into(),
name,
}
}
}
pub struct ContactBuilder {
contact: Contact,
}
impl ContactBuilder {
pub fn new(email: impl Into<String>) -> Self {
ContactBuilder {
contact: Contact::new(email, None),
}
}
pub fn name(mut self, name: impl Into<String>) -> Self {
self.contact.name = Some(name.into());
self
}
pub fn build(self) -> Contact {
self.contact
}
}
#[cfg(test)]
mod tests {
use crate::{ContactBuilder, MessageBuilder};
#[test]
fn it_works() {
let m = MessageBuilder::new(
ContactBuilder::new("from@from.com").name("from").build(),
"subject",
)
.build();
println!("{}", m.to_json());
}
}