Class: SendGrid::Mail
- Inherits:
-
Object
- Object
- SendGrid::Mail
- Defined in:
- lib/sendgrid/helpers/mail/mail.rb
Instance Attribute Summary collapse
-
#attachments ⇒ Object
readonly
Returns the value of attribute attachments.
-
#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.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#personalizations ⇒ Object
readonly
Returns the value of attribute personalizations.
-
#sections ⇒ Object
readonly
Returns the value of attribute sections.
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
- #asm ⇒ Object
- #asm=(asm) ⇒ Object
- #batch_id ⇒ Object
- #batch_id=(batch_id) ⇒ Object
- #from ⇒ Object
- #from=(from) ⇒ Object
-
#initialize(from_email = nil, subj = nil, to_email = nil, cont = nil) ⇒ Mail
constructor
A new instance of Mail.
- #ip_pool_name ⇒ Object
- #ip_pool_name=(ip_pool_name) ⇒ Object
- #mail_settings ⇒ Object
- #mail_settings=(mail_settings) ⇒ Object
- #reply_to ⇒ Object
- #reply_to=(reply_to) ⇒ Object
- #send_at ⇒ Object
- #send_at=(send_at) ⇒ Object
- #subject ⇒ Object
- #subject=(subject) ⇒ Object
- #template_id ⇒ Object
- #template_id=(template_id) ⇒ Object
- #to_json ⇒ Object
- #tracking_settings ⇒ Object
- #tracking_settings=(tracking_settings) ⇒ Object
Constructor Details
#initialize(from_email = nil, subj = nil, to_email = nil, cont = nil) ⇒ Mail
Returns a new instance of Mail.
10 11 12 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 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 10 def initialize(from_email=nil, subj=nil, to_email=nil, cont=nil) @from = nil @subject = nil @personalizations = [] @contents = [] = [] @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 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) self.add_personalization(personalization) self.add_content(cont) end end |
Instance Attribute Details
#attachments ⇒ Object (readonly)
Returns the value of attribute attachments.
8 9 10 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 8 def 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 |
#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 |
#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 |
#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 |
Instance Method Details
#add_attachment(attachment) ⇒ Object
63 64 65 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 63 def () << .to_json end |
#add_category(category) ⇒ Object
67 68 69 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 67 def add_category(category) @categories << category.name end |
#add_content(content) ⇒ Object
59 60 61 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 59 def add_content(content) @contents << content.to_json end |
#add_custom_arg(custom_arg) ⇒ Object
89 90 91 92 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 89 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
84 85 86 87 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 84 def add_header(header) header = header.to_json @headers = @headers.merge(header['header']) end |
#add_personalization(personalization) ⇒ Object
55 56 57 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 55 def add_personalization(personalization) @personalizations << personalization.to_json end |
#add_section(section) ⇒ Object
79 80 81 82 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 79 def add_section(section) section = section.to_json @sections = @sections.merge(section['section']) end |
#asm ⇒ Object
114 115 116 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 114 def asm @asm.nil? ? nil : @asm.to_json end |
#asm=(asm) ⇒ Object
110 111 112 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 110 def asm=(asm) @asm = asm end |
#batch_id ⇒ Object
106 107 108 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 106 def batch_id @batch_id end |
#batch_id=(batch_id) ⇒ Object
102 103 104 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 102 def batch_id=(batch_id) @batch_id = batch_id end |
#from ⇒ Object
43 44 45 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 43 def from @from.nil? ? nil : @from.to_json end |
#from=(from) ⇒ Object
39 40 41 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 39 def from=(from) @from = from end |
#ip_pool_name ⇒ Object
122 123 124 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 122 def ip_pool_name @ip_pool_name end |
#ip_pool_name=(ip_pool_name) ⇒ Object
118 119 120 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 118 def ip_pool_name=(ip_pool_name) @ip_pool_name = ip_pool_name end |
#mail_settings ⇒ Object
130 131 132 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 130 def mail_settings @mail_settings.nil? ? nil : @mail_settings.to_json end |
#mail_settings=(mail_settings) ⇒ Object
126 127 128 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 126 def mail_settings=(mail_settings) @mail_settings = mail_settings end |
#reply_to ⇒ Object
146 147 148 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 146 def reply_to @reply_to.nil? ? nil : @reply_to.to_json end |
#reply_to=(reply_to) ⇒ Object
142 143 144 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 142 def reply_to=(reply_to) @reply_to = reply_to end |
#send_at ⇒ Object
98 99 100 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 98 def send_at @send_at end |
#send_at=(send_at) ⇒ Object
94 95 96 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 94 def send_at=(send_at) @send_at = send_at end |
#subject ⇒ Object
51 52 53 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 51 def subject @subject end |
#subject=(subject) ⇒ Object
47 48 49 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 47 def subject=(subject) @subject = subject end |
#template_id ⇒ Object
75 76 77 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 75 def template_id @template_id end |
#template_id=(template_id) ⇒ Object
71 72 73 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 71 def template_id=(template_id) @template_id = template_id end |
#to_json ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 150 def to_json(*) { 'from' => self.from, 'subject' => self.subject, 'personalizations' => self.personalizations, 'content' => self.contents, 'attachments' => self., 'template_id' => self.template_id, 'sections' => self.sections, 'headers' => self.headers, 'categories' => self.categories, 'custom_args' => self.custom_args, 'send_at' => self.send_at, 'batch_id' => self.batch_id, 'asm' => self.asm, 'ip_pool_name' => self.ip_pool_name, 'mail_settings' => self.mail_settings, 'tracking_settings' => self.tracking_settings, 'reply_to' => self.reply_to }.delete_if { |_, value| value.to_s.strip == '' || value == [] || value == {}} end |
#tracking_settings ⇒ Object
138 139 140 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 138 def tracking_settings @tracking_settings.nil? ? nil : @tracking_settings.to_json end |
#tracking_settings=(tracking_settings) ⇒ Object
134 135 136 |
# File 'lib/sendgrid/helpers/mail/mail.rb', line 134 def tracking_settings=(tracking_settings) @tracking_settings = tracking_settings end |