-
Notifications
You must be signed in to change notification settings - Fork 322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extend Gem with additional Template and Recipient Functionality #23
Conversation
Two main models: Client and Mail now have specs covering their public api
Spec suite for existing logic
This will add filters to the smtpapi gem: https://github.com/sendgrid/smtpapi-ruby The template_id will be passed in like other attributes to mail Example: ``` mail = SendGrid::Mail.new do |m| m.to = '[email protected]' m.from = '[email protected]' m.subject = 'Hello world!' m.text = 'I heard you like pineapple.' m.template_id = 1234 end ```
Add support for templates
Add travis config for automagic builds
To help encapsulate the substitution logic for templates and how they correlate with email recipients, this model has been introduced. The benefit is now something like this is possible: ```ruby template = Template.new(TEMPLATE_ID) users = User.find(['[email protected]', '[email protected]']) users.each do |user| recipient = Recipient.new(user) recipient.add_substitution(:name, user.name) recipient.add_substitution(:location, user.location) template.add_recipient(recipient) end ``` The next step will be to integrate the `Recipient` and `Template` with `Mail`.
Recipient introduced
Wrong variable names for x-smtpapi header
…-for-recipient Fail on initialization instead of silently on output
This will add an accessor for the template without an initialization through a template_id
Bug with substitution calling in template and change to association
This is the final piece of abstracting recipients, templates and the sending of mail. The use of this would look like: ```ruby users = User.where(email: ['[email protected]', '[email protected]']) recipients = [] users.each do |user| recipient = SendGrid::Recipient.new(user.email) recipient.add_substitution('first_name', user.first_name) recipient.add_substitution('city', user.city) recipients << recipient end template = SendGrid::Template.new('MY_TEMPLATE_ID') client = SendGrid::Client.new(api_user: my_user, api_key: my_key) mail_defaults = { from: '[email protected]', html: '<h1>I like email</h1>', text: 'I like email' subject: 'Email is great', } mailer = TemplateMailer.new(client, template, recipients) mailer.mail(mail_defaults) ```
Template Mailer
Thanks @yez, you rock. We very much appreciate the effort and will work to get this reviewed and merged soon! |
@thinkingserious looks like #24 was recently merged in and this PR is now conflict ridden. Was this PR able to be reviewed at all to see which parts SendGrid would like to include? |
Hi @yez, Now that I've spent some playing with this code and a possible merge with the new code, here are my thoughts:
To move forward I suggest either:
Again, we greatly appreciate your contribution and want to figure out the best approach of achieving the goal of getting the template engine functionality added to the library. Please let me know your thoughts. Thanks in advance! |
I am going to go ahead and close this PR and then try and salvage the template pieces that will fit with the new code architecture. When that is done, I will open a new PR with the changes. |
That's awesome, thanks! |
Add TROUBLESHOOTING.md
@rbin and anyone else at SendGrid
Recipient
of template substitutions.
SMTPAPI
Template
template_id
and managingRecipients
SMTPAPI
TemplateMailer
Template
and 1 to manyRecipients
Mail
andClient
objects to handle actual delivery