Skip to content
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

Closed
wants to merge 26 commits into from

Conversation

yez
Copy link

@yez yez commented Sep 11, 2015

@rbin and anyone else at SendGrid

  1. Wrote RSpec 3 compatible spec suite
  2. Added Travis integration for Continuous Integration
  3. README updated to remove Eddie Zane (He informed me he has left SendGrid)
  4. POROs introduced to ease with Template Calling
    • Recipient
      • Responsible for holding user data and optionally keeping track
        of template substitutions.
      • Has ability to add itself to an SMTPAPI
    • Template
      • Responsible for keeping track of template_id and managing Recipients
      • Has ability to add itself to an SMTPAPI
    • TemplateMailer
      • Responsible for composing requests given a Template and 1 to many Recipients
      • Handles common error cases
      • Invokes the existing Mail and Client objects to handle actual delivery

Jake Yesbeck and others added 26 commits August 25, 2015 14:43
Two main models: Client and Mail now have specs covering their
  public api
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 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`.
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)
```
@mbernier
Copy link

Thanks @yez, you rock. We very much appreciate the effort and will work to get this reviewed and merged soon!

@yez
Copy link
Author

yez commented Sep 29, 2015

@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?

@thinkingserious
Copy link
Contributor

Hi @yez,

We needed to merge #24 before we tackled your PR.

We are hoping to review this one before the end of the week, thanks again!

With Best Regards,

Elmer

@thinkingserious
Copy link
Contributor

Hi @yez,

Now that I've spent some playing with this code and a possible merge with the new code, here are my thoughts:

  1. I think the code that you based this PR on changed significantly enough that I can't easily resolve the merge conflicts.
  2. I was able to get the code working by manually integrating your changes, but it got messy quickly (probably because I'm just getting familiar both with your and Eddie's code) and it feels like we need to rethink how to implement attachments considering the new changes to the library.
  3. I tried another approach that involved no extra classes, just new modules in the Mail Class, but I suspect you had good reason to extract out the template code into it's own class. I'm interested to hear your thoughts on this.

To move forward I suggest either:

  1. You try your hand at submitting a new pull request based on the newly updated library, since you best understand this code.
  2. I can take some bits and pieces of your code with the end result of a working integration with our template engine, but it may not hold true to your original implementation.

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!

@yez
Copy link
Author

yez commented Oct 1, 2015

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.

@yez yez closed this Oct 1, 2015
@thinkingserious
Copy link
Contributor

That's awesome, thanks!

jamietanna pushed a commit to jamietanna/sendgrid-ruby that referenced this pull request Oct 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants