Class: SendGrid::Mail
- Inherits:
-
Object
- Object
- SendGrid::Mail
- Defined in:
- lib/sendgrid/helpers/mail/mail.rb
Instance Attribute Summary collapse
- #asm ⇒ Object
-
#attachments ⇒ Object
readonly
Returns the value of attribute attachments.
-
#batch_id ⇒ Object
Returns the value of attribute batch_id.
-
#categories ⇒ Object
readonly
Returns the value of attribute categories.
-
#contents ⇒ Object
readonly
Returns the value of attribute contents.
-
#custom_args ⇒ Object
readonly
Returns the value of attribute custom_args.
- #from ⇒ Object
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#ip_pool_name ⇒ Object
Returns the value of attribute ip_pool_name.
- #mail_settings ⇒ Object
-
#personalizations ⇒ Object
readonly
Returns the value of attribute personalizations.
- #reply_to ⇒ Object
-
#sections ⇒ Object
readonly
Returns the value of attribute sections.
-
#send_at ⇒ Object
Returns the value of attribute send_at.
-
#subject ⇒ Object
Returns the value of attribute subject.
-
#template_id ⇒ Object
Returns the value of attribute template_id.
- #tracking_settings ⇒ Object
Instance Method Summary collapse
- #add_attachment(attachment) ⇒ Object
- #add_category(category) ⇒ Object
- #add_content(content) ⇒ Object
- #add_custom_arg(custom_arg) ⇒ Object
- #add_header(header) ⇒ Object
- #add_personalization(personalization) ⇒ Object
- #add_section(section) ⇒ Object
- #check_for_secrets(patterns) ⇒ Object
-
#initialize(from_email = nil, subj = nil, to_email = nil, cont = nil) ⇒ Mail
constructor
We allow for all nil values here to create uninitialized Mail objects (e.g. <project-root>/use-cases/transactional-templates.md).
- #to_json ⇒ Object
Constructor Details
#initialize(from_email = nil, subj = nil, to_email = nil, cont = nil) ⇒ Mail
We allow for all nil values here to create uninitialized Mail objects (e.g. <project-root>/use-cases/transactional-templates.md)
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 13 def initialize(from_email = nil, subj = nil, to_email = nil, cont = nil) # rubocop:disable Metrics/ParameterLists @from = nil @subject = nil @personalizations = [] @contents = [] @attachments = [] @template_id = nil @sections = {} @headers = {} @categories = [] @custom_args = {} @send_at = nil @batch_id = nil @asm = nil @ip_pool_name = nil @mail_settings = nil @tracking_settings = nil @reply_to = nil return if from_email.nil? && subj.nil? && to_email.nil? && cont.nil? self.from = from_email self.subject = subj personalization = Personalization.new personalization.add_to(to_email) add_personalization(personalization) add_content(cont) end |
Instance Attribute Details
#asm ⇒ Object
84 85 86 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 84 def asm @asm.nil? ? nil : @asm.to_json end |
#attachments ⇒ Object (readonly)
Returns the value of attribute attachments.
8 9 10 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 8 def @attachments end |
#batch_id ⇒ Object
Returns the value of attribute batch_id.
7 8 9 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 7 def batch_id @batch_id end |
#categories ⇒ Object (readonly)
Returns the value of attribute categories.
8 9 10 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 8 def categories @categories end |
#contents ⇒ Object (readonly)
Returns the value of attribute contents.
8 9 10 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 8 def contents @contents end |
#custom_args ⇒ Object (readonly)
Returns the value of attribute custom_args.
8 9 10 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 8 def custom_args @custom_args end |
#from ⇒ Object
42 43 44 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 42 def from @from.nil? ? nil : @from.to_json end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
8 9 10 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 8 def headers @headers end |
#ip_pool_name ⇒ Object
Returns the value of attribute ip_pool_name.
7 8 9 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 7 def ip_pool_name @ip_pool_name end |
#mail_settings ⇒ Object
88 89 90 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 88 def mail_settings @mail_settings.nil? ? nil : @mail_settings.to_json end |
#personalizations ⇒ Object (readonly)
Returns the value of attribute personalizations.
8 9 10 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 8 def personalizations @personalizations end |
#reply_to ⇒ Object
96 97 98 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 96 def reply_to @reply_to.nil? ? nil : @reply_to.to_json end |
#sections ⇒ Object (readonly)
Returns the value of attribute sections.
8 9 10 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 8 def sections @sections end |
#send_at ⇒ Object
Returns the value of attribute send_at.
7 8 9 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 7 def send_at @send_at end |
#subject ⇒ Object
Returns the value of attribute subject.
7 8 9 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 7 def subject @subject end |
#template_id ⇒ Object
Returns the value of attribute template_id.
7 8 9 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 7 def template_id @template_id end |
#tracking_settings ⇒ Object
92 93 94 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 92 def tracking_settings @tracking_settings.nil? ? nil : @tracking_settings.to_json end |
Instance Method Details
#add_attachment(attachment) ⇒ Object
61 62 63 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 61 def () @attachments << .to_json end |
#add_category(category) ⇒ Object
65 66 67 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 65 def add_category(category) @categories << category.name end |
#add_content(content) ⇒ Object
50 51 52 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 50 def add_content(content) @contents << content.to_json end |
#add_custom_arg(custom_arg) ⇒ Object
79 80 81 82 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 79 def add_custom_arg(custom_arg) custom_arg = custom_arg.to_json @custom_args = @custom_args.merge(custom_arg['custom_arg']) end |
#add_header(header) ⇒ Object
74 75 76 77 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 74 def add_header(header) header = header.to_json @headers = @headers.merge(header['header']) end |
#add_personalization(personalization) ⇒ Object
46 47 48 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 46 def add_personalization(personalization) @personalizations << personalization.to_json end |
#add_section(section) ⇒ Object
69 70 71 72 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 69 def add_section(section) section = section.to_json @sections = @sections.merge(section['section']) end |
#check_for_secrets(patterns) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 54 def check_for_secrets(patterns) contents = @contents.map { |content| content['value'] }.join(' ') patterns.each do |pattern| raise SecurityError, 'Content contains sensitive information.' if contents.match(pattern) end end |
#to_json ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 100 def to_json(*) { 'from' => from, 'subject' => subject, 'personalizations' => personalizations, 'content' => contents, 'attachments' => , 'template_id' => template_id, 'sections' => sections, 'headers' => headers, 'categories' => categories, 'custom_args' => custom_args, 'send_at' => send_at, 'batch_id' => batch_id, 'asm' => asm, 'ip_pool_name' => ip_pool_name, 'mail_settings' => mail_settings, 'tracking_settings' => tracking_settings, 'reply_to' => reply_to }.delete_if { |_, value| value.to_s.strip == '' || value == [] || value == {} } end |