Class: Postal::Mailing
Constant Summary collapse
- DEFAULT_ATTRIBUTES =
{:additional_headers => nil, :attachments => nil, :bypass_moderation => nil, :campaign => nil, :char_set_id => nil, :detect_html => nil, :dont_attempt_after_date => nil, :enable_recovery => nil, :from => nil, :html_message => nil, :html_section_encoding => nil, :is_html_section_encoded => nil, :is_text_section_encoded => nil, :list_name => nil, :recency_number_of_mailings => nil, :recency_which => nil, :reply_to => nil, :resend_after_days => nil, :sample_size => nil, :scheduled_mailing_date => nil, :subject => nil, :text_message => nil, :text_section_encoding => nil, :title => nil, :to => nil, :track_opens => nil, :rewrite_date_when_sent => nil, :mailing => nil }
Instance Attribute Summary collapse
-
#additional_headers ⇒ Object
Returns the value of attribute additional_headers.
-
#attachments ⇒ Object
Returns the value of attribute attachments.
-
#bypass_moderation ⇒ Object
Returns the value of attribute bypass_moderation.
-
#campaign ⇒ Object
Returns the value of attribute campaign.
-
#char_set_id ⇒ Object
Returns the value of attribute char_set_id.
-
#detect_html ⇒ Object
Returns the value of attribute detect_html.
-
#dont_attempt_after_date ⇒ Object
Returns the value of attribute dont_attempt_after_date.
-
#enable_recovery ⇒ Object
Returns the value of attribute enable_recovery.
-
#from ⇒ Object
Returns the value of attribute from.
-
#html_message ⇒ Object
Returns the value of attribute html_message.
-
#html_section_encoding ⇒ Object
Returns the value of attribute html_section_encoding.
-
#is_html_section_encoded ⇒ Object
Returns the value of attribute is_html_section_encoded.
-
#is_text_section_encoded ⇒ Object
Returns the value of attribute is_text_section_encoded.
-
#list_name ⇒ Object
Returns the value of attribute list_name.
-
#mailing ⇒ Object
Returns the value of attribute mailing.
-
#recency_number_of_mailings ⇒ Object
Returns the value of attribute recency_number_of_mailings.
-
#recency_which ⇒ Object
Returns the value of attribute recency_which.
-
#reply_to ⇒ Object
Returns the value of attribute reply_to.
-
#resend_after_days ⇒ Object
Returns the value of attribute resend_after_days.
-
#rewrite_date_when_sent ⇒ Object
Returns the value of attribute rewrite_date_when_sent.
-
#sample_size ⇒ Object
Returns the value of attribute sample_size.
-
#scheduled_mailing_date ⇒ Object
Returns the value of attribute scheduled_mailing_date.
-
#subject ⇒ Object
Returns the value of attribute subject.
-
#text_message ⇒ Object
Returns the value of attribute text_message.
-
#text_section_encoding ⇒ Object
Returns the value of attribute text_section_encoding.
-
#title ⇒ Object
Returns the value of attribute title.
-
#to ⇒ Object
Returns the value of attribute to.
-
#track_opens ⇒ Object
Returns the value of attribute track_opens.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ Mailing
constructor
Create a new mailing ready to send.
-
#send ⇒ Object
(also: #save)
Send the mailing.
-
#send! ⇒ Object
(also: #save!)
same as send() but throws an error instead of just returning false.
-
#valid? ⇒ Boolean
Determines whether the email is valid to send.
-
#validate ⇒ Object
Determines whether we have everything we need to send an email.
Methods inherited from Base
Constructor Details
#initialize(args = {}) ⇒ Mailing
Create a new mailing ready to send
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/postal/mailing.rb', line 73 def initialize(args={}) args = DEFAULT_ATTRIBUTES.merge(args) @list_name = args[:list_name] || Postal.[:list_name] @to = args[:to] if args[:mailing].nil? @additional_headers = args[:additional_headers] @attachments = args[:attachments] @bypass_moderation = args[:bypass_moderation] @campaign = args[:campaign] @char_set_id = args[:char_set_id] @detect_html = args[:detect_html] @dont_attempt_after_date = args[:dont_attempt_after_date] @enable_recovery = args[:enable_recovery] @from = args[:from] @html_message = args[:html_message] @html_section_encoding = args[:html_section_encoding] @is_html_section_encoded = args[:is_html_section_encoded] @is_text_section_encoded = args[:is_text_section_encoded] @recency_number_of_mailings = args[:recency_number_of_mailings] @recency_which = args[:recency_which] @reply_to = args[:reply_to] @resend_after_days = args[:resend_after_days] @sample_size = args[:sample_size] @scheduled_mailing_date = args[:scheduled_mailing_date] @subject = args[:subject] @text_message = args[:text_message] @text_section_encoding = args[:text_section_encoding] @title = args[:title] @to = args[:to] @track_opens = args[:track_opens] @rewrite_date_when_sent = args[:rewrite_date_when_sent] @mailing = args[:mailing] else @subject = args[:mailing].subject @is_html_section_encoded = args[:mailing].isHtmlSectionEncoded @html_section_encoding = args[:mailing].htmlSectionEncoding @html_message = args[:mailing].htmlMessage @char_set_id = args[:mailing].charSetID @is_text_section_encoded = args[:mailing].isTextSectionEncoded @text_section_encoding = args[:mailing].textSectionEncoding @title = args[:mailing].title @text_message = args[:mailing].textMessage @attachments = args[:mailing]. @from = args[:mailing].from @additional_headers = args[:mailing].additionalHeaders @mailing = args[:mailing] end end |
Instance Attribute Details
#additional_headers ⇒ Object
Returns the value of attribute additional_headers.
43 44 45 |
# File 'lib/postal/mailing.rb', line 43 def additional_headers @additional_headers end |
#attachments ⇒ Object
Returns the value of attribute attachments.
43 44 45 |
# File 'lib/postal/mailing.rb', line 43 def @attachments end |
#bypass_moderation ⇒ Object
Returns the value of attribute bypass_moderation.
43 44 45 |
# File 'lib/postal/mailing.rb', line 43 def bypass_moderation @bypass_moderation end |
#campaign ⇒ Object
Returns the value of attribute campaign.
43 44 45 |
# File 'lib/postal/mailing.rb', line 43 def campaign @campaign end |
#char_set_id ⇒ Object
Returns the value of attribute char_set_id.
43 44 45 |
# File 'lib/postal/mailing.rb', line 43 def char_set_id @char_set_id end |
#detect_html ⇒ Object
Returns the value of attribute detect_html.
43 44 45 |
# File 'lib/postal/mailing.rb', line 43 def detect_html @detect_html end |
#dont_attempt_after_date ⇒ Object
Returns the value of attribute dont_attempt_after_date.
43 44 45 |
# File 'lib/postal/mailing.rb', line 43 def dont_attempt_after_date @dont_attempt_after_date end |
#enable_recovery ⇒ Object
Returns the value of attribute enable_recovery.
43 44 45 |
# File 'lib/postal/mailing.rb', line 43 def enable_recovery @enable_recovery end |
#from ⇒ Object
Returns the value of attribute from.
43 44 45 |
# File 'lib/postal/mailing.rb', line 43 def from @from end |
#html_message ⇒ Object
Returns the value of attribute html_message.
43 44 45 |
# File 'lib/postal/mailing.rb', line 43 def @html_message end |
#html_section_encoding ⇒ Object
Returns the value of attribute html_section_encoding.
43 44 45 |
# File 'lib/postal/mailing.rb', line 43 def html_section_encoding @html_section_encoding end |
#is_html_section_encoded ⇒ Object
Returns the value of attribute is_html_section_encoded.
43 44 45 |
# File 'lib/postal/mailing.rb', line 43 def is_html_section_encoded @is_html_section_encoded end |
#is_text_section_encoded ⇒ Object
Returns the value of attribute is_text_section_encoded.
43 44 45 |
# File 'lib/postal/mailing.rb', line 43 def is_text_section_encoded @is_text_section_encoded end |
#list_name ⇒ Object
Returns the value of attribute list_name.
43 44 45 |
# File 'lib/postal/mailing.rb', line 43 def list_name @list_name end |
#mailing ⇒ Object
Returns the value of attribute mailing.
43 44 45 |
# File 'lib/postal/mailing.rb', line 43 def mailing @mailing end |
#recency_number_of_mailings ⇒ Object
Returns the value of attribute recency_number_of_mailings.
43 44 45 |
# File 'lib/postal/mailing.rb', line 43 def recency_number_of_mailings @recency_number_of_mailings end |
#recency_which ⇒ Object
Returns the value of attribute recency_which.
43 44 45 |
# File 'lib/postal/mailing.rb', line 43 def recency_which @recency_which end |
#reply_to ⇒ Object
Returns the value of attribute reply_to.
43 44 45 |
# File 'lib/postal/mailing.rb', line 43 def reply_to @reply_to end |
#resend_after_days ⇒ Object
Returns the value of attribute resend_after_days.
43 44 45 |
# File 'lib/postal/mailing.rb', line 43 def resend_after_days @resend_after_days end |
#rewrite_date_when_sent ⇒ Object
Returns the value of attribute rewrite_date_when_sent.
43 44 45 |
# File 'lib/postal/mailing.rb', line 43 def rewrite_date_when_sent @rewrite_date_when_sent end |
#sample_size ⇒ Object
Returns the value of attribute sample_size.
43 44 45 |
# File 'lib/postal/mailing.rb', line 43 def sample_size @sample_size end |
#scheduled_mailing_date ⇒ Object
Returns the value of attribute scheduled_mailing_date.
43 44 45 |
# File 'lib/postal/mailing.rb', line 43 def scheduled_mailing_date @scheduled_mailing_date end |
#subject ⇒ Object
Returns the value of attribute subject.
43 44 45 |
# File 'lib/postal/mailing.rb', line 43 def subject @subject end |
#text_message ⇒ Object
Returns the value of attribute text_message.
43 44 45 |
# File 'lib/postal/mailing.rb', line 43 def @text_message end |
#text_section_encoding ⇒ Object
Returns the value of attribute text_section_encoding.
43 44 45 |
# File 'lib/postal/mailing.rb', line 43 def text_section_encoding @text_section_encoding end |
#title ⇒ Object
Returns the value of attribute title.
43 44 45 |
# File 'lib/postal/mailing.rb', line 43 def title @title end |
#to ⇒ Object
Returns the value of attribute to.
43 44 45 |
# File 'lib/postal/mailing.rb', line 43 def to @to end |
#track_opens ⇒ Object
Returns the value of attribute track_opens.
43 44 45 |
# File 'lib/postal/mailing.rb', line 43 def track_opens @track_opens end |
Class Method Details
Instance Method Details
#send ⇒ Object Also known as: save
Send the mailing
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/postal/mailing.rb', line 126 def send if valid? # are we sending to a list of email addresses or member ids case @to.to_a.first when ::String emails = @to.to_a member_ids = [] when ::Fixnum emails = [] member_ids = @to.to_a end if @mailing.nil? mail = Postal::Lmapi::MailingStruct.new(:additionalHeaders => @additional_headers, :attachments => @attachments, :bypassModeration => @bypass_moderation, :campaign => @campaign, :charSetID => @char_set_id, :detectHtml => @detect_html, :dontAttemptAfterDate => @dont_attempt_after_date, :enableRecovery => @enable_recovery, :from => @from, :htmlMessage => @html_message, :htmlSectionEncoding => @html_section_encoding, :isHtmlSectionEncoded => @is_html_section_encoded, :isTextSectionEncoded => @is_text_section_encoded, :listName => @list_name, :recencyNumberOfMailings => @recency_number_of_mailings, :recencyWhich => @recency_which, :replyTo => @reply_to, :resendAfterDays => @resend_after_days, :sampleSize => @sample_size, :scheduledMailingDate => @scheduled_mailing_date, :subject => @subject, :textMessage => @text_message, :textSectionEncoding => @text_section_encoding, :title => @title, # :to => @to, :trackOpens => @track_opens, :rewriteDateWhenSent => @rewrite_date_when_sent ) return Postal.driver.sendMailingDirect(emails,member_ids,mail) else mail = Postal::Lmapi::MailingStruct.new(@mailing) mail.listName = @list_name || Postal.[:list_name] return Postal.driver.sendMailingDirect(emails,member_ids,mail) end else # mail wasn't valid return false end end |
#send! ⇒ Object Also known as: save!
same as send() but throws an error instead of just returning false
182 183 184 185 186 187 188 |
# File 'lib/postal/mailing.rb', line 182 def send! if id = send return id else raise Postal::CouldNotSendMailing, 'Your mail was invalid and could not be sent.' end end |
#valid? ⇒ Boolean
Determines whether the email is valid to send
195 196 197 |
# File 'lib/postal/mailing.rb', line 195 def valid? return validate end |
#validate ⇒ Object
Determines whether we have everything we need to send an email
201 202 203 |
# File 'lib/postal/mailing.rb', line 201 def validate return (@list_name && @to && @subject) ? true : false end |