Module: SendGrid
- Defined in:
- lib/sendgrid.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- VALID_OPTIONS =
[ :opentrack, :clicktrack, :ganalytics, :gravatar, :subscriptiontrack, :footer, :spamcheck, :bypass_list_management ]
- VALID_GANALYTICS_OPTIONS =
[ :utm_source, :utm_medium, :utm_campaign, :utm_term, :utm_content ]
Class Method Summary collapse
Instance Method Summary collapse
-
#create!(method_name, *parameters) ⇒ Object
Sets the custom X-SMTPAPI header after creating the email but before delivery NOTE: This override is used for Rails 2 ActionMailer classes.
-
#sendgrid_category(category) ⇒ Object
Call within mailer method to override the default value.
-
#sendgrid_disable(*options) ⇒ Object
Call within mailer method to remove one of the defaults.
-
#sendgrid_enable(*options) ⇒ Object
Call within mailer method to add an option not in the defaults.
-
#sendgrid_footer_text(texts) ⇒ Object
Call within mailer method to override the default value.
-
#sendgrid_ganalytics_options(options) ⇒ Object
Call within mailer method to set custom google analytics options sendgrid.com/documentation/appsGoogleAnalytics.
-
#sendgrid_recipients(emails) ⇒ Object
Call within mailer method to add an array of recipients.
-
#sendgrid_spamcheck_maxscore(score) ⇒ Object
Call within mailer method to override the default value.
-
#sendgrid_subscriptiontrack_text(texts) ⇒ Object
Call within mailer method to override the default value.
-
#sendgrid_substitute(placeholder, subs) ⇒ Object
Call within mailer method to add an array of substitions NOTE: you must ensure that the length of the substitions equals the length of the sendgrid_recipients.
-
#sendgrid_unique_args(unique_args = {}) ⇒ Object
Call within mailer method to set unique args for this email.
Class Method Details
.included(base) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/sendgrid.rb', line 24 def self.included(base) base.class_eval do class << self attr_accessor :default_sg_category, :default_sg_options, :default_subscriptiontrack_text, :default_footer_text, :default_spamcheck_score, :default_sg_unique_args end attr_accessor :sg_category, :sg_options, :sg_disabled_options, :sg_recipients, :sg_substitutions, :subscriptiontrack_text, :footer_text, :spamcheck_score, :sg_unique_args end # NOTE: This commented-out approach may be a "safer" option for Rails 3, but it # would cause the headers to get set during delivery, and not when the message is initialized. # If base supports register_interceptor (i.e., Rails 3 ActionMailer), use it... # if base.respond_to?(:register_interceptor) # base.register_interceptor(SendgridInterceptor) # end base.extend(ClassMethods) end |
Instance Method Details
#create!(method_name, *parameters) ⇒ Object
Sets the custom X-SMTPAPI header after creating the email but before delivery NOTE: This override is used for Rails 2 ActionMailer classes.
183 184 185 186 187 188 189 190 191 192 |
# File 'lib/sendgrid.rb', line 183 def create!(method_name, *parameters) super if @sg_substitutions && !@sg_substitutions.empty? @sg_substitutions.each do |find, replace| raise ArgumentError.new("Array for #{find} is not the same size as the recipient array") if replace.size != @sg_recipients.size end end puts "SendGrid X-SMTPAPI: #{sendgrid_json_headers(mail)}" if Object.const_defined?("SENDGRID_DEBUG_OUTPUT") && SENDGRID_DEBUG_OUTPUT @mail['X-SMTPAPI'] = sendgrid_json_headers(mail) end |
#sendgrid_category(category) ⇒ Object
Call within mailer method to override the default value.
102 103 104 |
# File 'lib/sendgrid.rb', line 102 def sendgrid_category(category) @sg_category = category end |
#sendgrid_disable(*options) ⇒ Object
Call within mailer method to remove one of the defaults.
119 120 121 122 |
# File 'lib/sendgrid.rb', line 119 def sendgrid_disable(*) @sg_disabled_options = Array.new unless @sg_disabled_options .each { |option| @sg_disabled_options << option if VALID_OPTIONS.include?(option) } end |
#sendgrid_enable(*options) ⇒ Object
Call within mailer method to add an option not in the defaults.
113 114 115 116 |
# File 'lib/sendgrid.rb', line 113 def sendgrid_enable(*) @sg_options = Array.new unless @sg_options .each { |option| @sg_options << option if VALID_OPTIONS.include?(option) } end |
#sendgrid_footer_text(texts) ⇒ Object
Call within mailer method to override the default value.
144 145 146 |
# File 'lib/sendgrid.rb', line 144 def (texts) @footer_text = texts end |
#sendgrid_ganalytics_options(options) ⇒ Object
Call within mailer method to set custom google analytics options sendgrid.com/documentation/appsGoogleAnalytics
155 156 157 158 |
# File 'lib/sendgrid.rb', line 155 def () @ganalytics_options = [] .each { |option| @ganalytics_options << option if VALID_GANALYTICS_OPTIONS.include?(option[0].to_sym) } end |
#sendgrid_recipients(emails) ⇒ Object
Call within mailer method to add an array of recipients
125 126 127 128 |
# File 'lib/sendgrid.rb', line 125 def sendgrid_recipients(emails) @sg_recipients = Array.new unless @sg_recipients @sg_recipients = emails end |
#sendgrid_spamcheck_maxscore(score) ⇒ Object
Call within mailer method to override the default value.
149 150 151 |
# File 'lib/sendgrid.rb', line 149 def sendgrid_spamcheck_maxscore(score) @spamcheck_score = score end |
#sendgrid_subscriptiontrack_text(texts) ⇒ Object
Call within mailer method to override the default value.
139 140 141 |
# File 'lib/sendgrid.rb', line 139 def sendgrid_subscriptiontrack_text(texts) @subscriptiontrack_text = texts end |
#sendgrid_substitute(placeholder, subs) ⇒ Object
Call within mailer method to add an array of substitions NOTE: you must ensure that the length of the substitions equals the
length of the sendgrid_recipients.
133 134 135 136 |
# File 'lib/sendgrid.rb', line 133 def sendgrid_substitute(placeholder, subs) @sg_substitutions = Hash.new unless @sg_substitutions @sg_substitutions[placeholder] = subs end |
#sendgrid_unique_args(unique_args = {}) ⇒ Object
Call within mailer method to set unique args for this email. Merged with class-level unique args, if any exist.
108 109 110 |
# File 'lib/sendgrid.rb', line 108 def sendgrid_unique_args(unique_args = {}) @sg_unique_args = unique_args end |