class SendGridMailer::Definition
Constants
- METHODS
Public Instance Methods
add_attachment(file, name, type, disposition = "inline", content_id = nil)
click to toggle source
# File lib/send_grid_mailer/definition.rb, line 66 def add_attachment(file, name, type, disposition = "inline", content_id = nil) attachment = SendGrid::Attachment.new attachment.content = Base64.strict_encode64(file) attachment.type = type attachment.filename = name attachment.disposition = disposition attachment.content_id = content_id mail.add_attachment(attachment) end
add_category(value)
click to toggle source
# File lib/send_grid_mailer/definition.rb, line 82 def add_category(value) return unless value mail.add_category(SendGrid::Category.new(name: value)) end
add_header(key, value)
click to toggle source
# File lib/send_grid_mailer/definition.rb, line 76 def add_header(key, value) return if !key || !value personalization.add_header(SendGrid::Header.new(key: key, value: value)) end
clean_recipients(mode)
click to toggle source
# File lib/send_grid_mailer/definition.rb, line 97 def clean_recipients(mode) personalization.instance_variable_set("@#{mode}s", []) end
content?()
click to toggle source
# File lib/send_grid_mailer/definition.rb, line 107 def content?; mail.contents.present? end
dynamic_template_data(object)
click to toggle source
# File lib/send_grid_mailer/definition.rb, line 22 def dynamic_template_data(object) personalization.add_dynamic_template_data(object) end
mail()
click to toggle source
# File lib/send_grid_mailer/definition.rb, line 93 def mail @mail ||= SendGrid::Mail.new end
personalization()
click to toggle source
# File lib/send_grid_mailer/definition.rb, line 101 def personalization @personalization ||= SendGrid::Personalization.new end
personalization?()
click to toggle source
# File lib/send_grid_mailer/definition.rb, line 105 def personalization?; !personalization.to_json.empty? end
sender?()
click to toggle source
# File lib/send_grid_mailer/definition.rb, line 109 def sender?; mail.from.present? end
set_content(value, type = nil)
click to toggle source
# File lib/send_grid_mailer/definition.rb, line 59 def set_content(value, type = nil) return unless value type ||= "text/plain" mail.add_content(SendGrid::Content.new(type: type, value: value)) end
set_recipients(mode, *emails)
click to toggle source
# File lib/send_grid_mailer/definition.rb, line 45 def set_recipients(mode, *emails) emails.flatten.each do |email| next unless email personalization.send("add_#{mode}", SendGrid::Email.new(email: email)) end end
set_sender(email)
click to toggle source
# File lib/send_grid_mailer/definition.rb, line 32 def set_sender(email) return unless email matched_format = email.match(/<(.+)>/) if matched_format address = matched_format[1] name = email.match(/\"?([^<^\"]*)\"?\s?/)[1].strip mail.from = SendGrid::Email.new(email: address, name: name) else mail.from = SendGrid::Email.new(email: email) end end
set_subject(value)
click to toggle source
# File lib/send_grid_mailer/definition.rb, line 53 def set_subject(value) return unless value personalization.subject = value end
set_template_id(value)
click to toggle source
# File lib/send_grid_mailer/definition.rb, line 26 def set_template_id(value) return unless value mail.template_id = value end
subject?()
click to toggle source
# File lib/send_grid_mailer/definition.rb, line 111 def subject?; personalization.subject.present? end
substitute(key, value, default = "")
click to toggle source
# File lib/send_grid_mailer/definition.rb, line 16 def substitute(key, value, default = "") personalization.add_substitution( SendGrid::Substitution.new(key: key, value: value.to_s || default) ) end
template_id?()
click to toggle source
# File lib/send_grid_mailer/definition.rb, line 113 def template_id?; mail.template_id.present? end
to_json()
click to toggle source
# File lib/send_grid_mailer/definition.rb, line 88 def to_json mail.add_personalization(personalization) if personalization? mail.to_json end