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

Commits on Oct 19, 2015

  1. Gitignore update

    Jake Yesbeck committed Oct 19, 2015
    Configuration menu
    Copy the full SHA
    a129e27 View commit details
    Browse the repository at this point in the history
  2. Add support for templates

    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
    ```
    Jake Yesbeck committed Oct 19, 2015
    Configuration menu
    Copy the full SHA
    ce97bb1 View commit details
    Browse the repository at this point in the history
  3. Recipient introduced

    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`.
    Jake Yesbeck committed Oct 19, 2015
    Configuration menu
    Copy the full SHA
    942bea1 View commit details
    Browse the repository at this point in the history
  4. Wrong variable names for x-smtpapi header

    Jake Yesbeck committed Oct 19, 2015
    Configuration menu
    Copy the full SHA
    417d012 View commit details
    Browse the repository at this point in the history
  5. Fail on initialization instead of silently on output

    Jake Yesbeck committed Oct 19, 2015
    Configuration menu
    Copy the full SHA
    88a1bf3 View commit details
    Browse the repository at this point in the history
  6. Bug with substitution calling in template and change to association

    This will add an accessor for the template without an initialization
      through a template_id
    Jake Yesbeck committed Oct 19, 2015
    Configuration menu
    Copy the full SHA
    0a82049 View commit details
    Browse the repository at this point in the history
  7. Spec fixes

    Jake Yesbeck committed Oct 19, 2015
    Configuration menu
    Copy the full SHA
    9970702 View commit details
    Browse the repository at this point in the history
  8. Template Mailer

    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)
    ```
    Jake Yesbeck committed Oct 19, 2015
    Configuration menu
    Copy the full SHA
    aa93e11 View commit details
    Browse the repository at this point in the history
  9. Make sure substitutions are not constantly overwritten

    Jake Yesbeck committed Oct 19, 2015
    Configuration menu
    Copy the full SHA
    0ad3426 View commit details
    Browse the repository at this point in the history
  10. Explanitory comment about how to use template mailer

    Jake Yesbeck committed Oct 19, 2015
    Configuration menu
    Copy the full SHA
    dbb4454 View commit details
    Browse the repository at this point in the history
  11. Configuration menu
    Copy the full SHA
    ebe0dcf View commit details
    Browse the repository at this point in the history
  12. Update README with new Template pattern

    Jake Yesbeck committed Oct 19, 2015
    Configuration menu
    Copy the full SHA
    531c748 View commit details
    Browse the repository at this point in the history
  13. Make spec suite pass with two code paths together

    Jake Yesbeck committed Oct 19, 2015
    Configuration menu
    Copy the full SHA
    9163914 View commit details
    Browse the repository at this point in the history
  14. Conform to new require pattern

    Jake Yesbeck committed Oct 19, 2015
    Configuration menu
    Copy the full SHA
    e92ebd8 View commit details
    Browse the repository at this point in the history
  15. Enable use of template with Mail object

    Jake Yesbeck committed Oct 19, 2015
    Configuration menu
    Copy the full SHA
    3bd805f View commit details
    Browse the repository at this point in the history
  16. New spec asserting initialize can take a block

    Jake Yesbeck committed Oct 19, 2015
    Configuration menu
    Copy the full SHA
    c02d195 View commit details
    Browse the repository at this point in the history
  17. Update README with additional template usages

    Jake Yesbeck committed Oct 19, 2015
    Configuration menu
    Copy the full SHA
    439f899 View commit details
    Browse the repository at this point in the history