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 (round 2) #28

Merged
merged 17 commits into from
Oct 28, 2015

Conversation

yez
Copy link

@yez yez commented Oct 13, 2015

@thinkingserious

After #23, I have successfully added my changes to the new version of the gem.

  1. Added ability to assign a Template to a Mail object.
    • If a Mail object has a template when the Mail's to_h method is called, it automatically adds the required template parameters to the smtpapi header.
  2. POROs introduced to ease with Template Calling. This is an alternative way to use the Template system and is highlighted in changes to the README.
    • 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
  3. Spec files for new objects and standardized on require pattern.

@thinkingserious
Copy link
Contributor

Awesome! We'll get to this as soon as we can.

Jake Yesbeck added 17 commits October 19, 2015 13:01
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
```
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`.
This will add an accessor for the template without an initialization
  through a template_id
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)
```
thinkingserious added a commit that referenced this pull request Oct 28, 2015
Extend Gem with additional Template and Recipient Functionality (round 2)
@thinkingserious thinkingserious merged commit f28d913 into sendgrid:master Oct 28, 2015
@thinkingserious
Copy link
Contributor

Thanks for contributing to SendGrid Open Source! We think it's awesome when community members contribute to our projects and want to celebrate that.

The following link will ask you to authenticate with Github (so we can verify your identity). You'll then be asked for your shipping address so that we can send you a thanks for contributing.

Click Here to Continue »

Once again, thank you!

@yez
Copy link
Author

yez commented Oct 28, 2015

Glad to contribute and thanks for the shirt!

jamietanna pushed a commit to jamietanna/sendgrid-ruby that referenced this pull request Oct 13, 2018
update readme - add license, remove logo from bottom, add ToC
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.

2 participants