Skip to content

Commit

Permalink
feat: move logic to builder
Browse files Browse the repository at this point in the history
  • Loading branch information
oloko64 committed Mar 12, 2023
1 parent 547b41c commit 38fa8a4
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,22 @@ impl SendgridBuilder {
T: Into<String>,
U: IntoIterator<Item = T>,
{
Sendgrid::builder(api_key, set_to_emails, set_from_email, subject, body)
SendgridBuilder {
api_key: api_key.into(),
sendgrid_email: {
let mut sendgrid_email = SendgridEmail::default();
sendgrid_email.get_first_personalization().to = set_to_emails
.into_iter()
.map(|email| From {
email: email.into(),
})
.collect();
sendgrid_email.from.email = set_from_email.into();
sendgrid_email.subject = subject.into();
sendgrid_email.get_first_content().value = body.into();
sendgrid_email
},
}
}

/// Add a CC email to the email.
Expand Down Expand Up @@ -334,22 +349,7 @@ impl Sendgrid {
T: Into<String>,
U: IntoIterator<Item = T>,
{
SendgridBuilder {
api_key: api_key.into(),
sendgrid_email: {
let mut sendgrid_email = SendgridEmail::default();
sendgrid_email.get_first_personalization().to = set_to_emails
.into_iter()
.map(|email| From {
email: email.into(),
})
.collect();
sendgrid_email.from.email = set_from_email.into();
sendgrid_email.subject = subject.into();
sendgrid_email.get_first_content().value = body.into();
sendgrid_email
},
}
SendgridBuilder::new(api_key, set_to_emails, set_from_email, subject, body)
}

fn is_scheduled(&self) -> Option<String> {
Expand Down

0 comments on commit 38fa8a4

Please sign in to comment.