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 }
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.
-
#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.
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
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/postal/mailing.rb', line 66 def initialize(args={}) args = DEFAULT_ATTRIBUTES.merge(args) @to = args[:to] @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] @list_name = args[:list_name] || Postal.[:list_name] @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] end |
Instance Attribute Details
#additional_headers ⇒ Object
Returns the value of attribute additional_headers.
37 38 39 |
# File 'lib/postal/mailing.rb', line 37 def additional_headers @additional_headers end |
#attachments ⇒ Object
Returns the value of attribute attachments.
37 38 39 |
# File 'lib/postal/mailing.rb', line 37 def @attachments end |
#bypass_moderation ⇒ Object
Returns the value of attribute bypass_moderation.
37 38 39 |
# File 'lib/postal/mailing.rb', line 37 def bypass_moderation @bypass_moderation end |
#campaign ⇒ Object
Returns the value of attribute campaign.
37 38 39 |
# File 'lib/postal/mailing.rb', line 37 def campaign @campaign end |
#char_set_id ⇒ Object
Returns the value of attribute char_set_id.
37 38 39 |
# File 'lib/postal/mailing.rb', line 37 def char_set_id @char_set_id end |
#detect_html ⇒ Object
Returns the value of attribute detect_html.
37 38 39 |
# File 'lib/postal/mailing.rb', line 37 def detect_html @detect_html end |
#dont_attempt_after_date ⇒ Object
Returns the value of attribute dont_attempt_after_date.
37 38 39 |
# File 'lib/postal/mailing.rb', line 37 def dont_attempt_after_date @dont_attempt_after_date end |
#enable_recovery ⇒ Object
Returns the value of attribute enable_recovery.
37 38 39 |
# File 'lib/postal/mailing.rb', line 37 def enable_recovery @enable_recovery end |
#from ⇒ Object
Returns the value of attribute from.
37 38 39 |
# File 'lib/postal/mailing.rb', line 37 def from @from end |
#html_message ⇒ Object
Returns the value of attribute html_message.
37 38 39 |
# File 'lib/postal/mailing.rb', line 37 def @html_message end |
#html_section_encoding ⇒ Object
Returns the value of attribute html_section_encoding.
37 38 39 |
# File 'lib/postal/mailing.rb', line 37 def html_section_encoding @html_section_encoding end |
#is_html_section_encoded ⇒ Object
Returns the value of attribute is_html_section_encoded.
37 38 39 |
# File 'lib/postal/mailing.rb', line 37 def is_html_section_encoded @is_html_section_encoded end |
#is_text_section_encoded ⇒ Object
Returns the value of attribute is_text_section_encoded.
37 38 39 |
# File 'lib/postal/mailing.rb', line 37 def is_text_section_encoded @is_text_section_encoded end |
#list_name ⇒ Object
Returns the value of attribute list_name.
37 38 39 |
# File 'lib/postal/mailing.rb', line 37 def list_name @list_name end |
#recency_number_of_mailings ⇒ Object
Returns the value of attribute recency_number_of_mailings.
37 38 39 |
# File 'lib/postal/mailing.rb', line 37 def recency_number_of_mailings @recency_number_of_mailings end |
#recency_which ⇒ Object
Returns the value of attribute recency_which.
37 38 39 |
# File 'lib/postal/mailing.rb', line 37 def recency_which @recency_which end |
#reply_to ⇒ Object
Returns the value of attribute reply_to.
37 38 39 |
# File 'lib/postal/mailing.rb', line 37 def reply_to @reply_to end |
#resend_after_days ⇒ Object
Returns the value of attribute resend_after_days.
37 38 39 |
# File 'lib/postal/mailing.rb', line 37 def resend_after_days @resend_after_days end |
#rewrite_date_when_sent ⇒ Object
Returns the value of attribute rewrite_date_when_sent.
37 38 39 |
# File 'lib/postal/mailing.rb', line 37 def rewrite_date_when_sent @rewrite_date_when_sent end |
#sample_size ⇒ Object
Returns the value of attribute sample_size.
37 38 39 |
# File 'lib/postal/mailing.rb', line 37 def sample_size @sample_size end |
#scheduled_mailing_date ⇒ Object
Returns the value of attribute scheduled_mailing_date.
37 38 39 |
# File 'lib/postal/mailing.rb', line 37 def scheduled_mailing_date @scheduled_mailing_date end |
#subject ⇒ Object
Returns the value of attribute subject.
37 38 39 |
# File 'lib/postal/mailing.rb', line 37 def subject @subject end |
#text_message ⇒ Object
Returns the value of attribute text_message.
37 38 39 |
# File 'lib/postal/mailing.rb', line 37 def @text_message end |
#text_section_encoding ⇒ Object
Returns the value of attribute text_section_encoding.
37 38 39 |
# File 'lib/postal/mailing.rb', line 37 def text_section_encoding @text_section_encoding end |
#title ⇒ Object
Returns the value of attribute title.
37 38 39 |
# File 'lib/postal/mailing.rb', line 37 def title @title end |
#to ⇒ Object
Returns the value of attribute to.
37 38 39 |
# File 'lib/postal/mailing.rb', line 37 def to @to end |
#track_opens ⇒ Object
Returns the value of attribute track_opens.
37 38 39 |
# File 'lib/postal/mailing.rb', line 37 def track_opens @track_opens end |
Instance Method Details
#send ⇒ Object Also known as: save
Send the mailing
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/postal/mailing.rb', line 100 def send if valid? 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, :trackOpens => @track_opens, :rewriteDateWhenSent => @rewrite_date_when_sent ) # 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 return Postal.driver.sendMailingDirect(emails,member_ids,mail) else return false end end |
#send! ⇒ Object Also known as: save!
same as send() but throws an error instead of just returning false
147 148 149 150 151 152 153 |
# File 'lib/postal/mailing.rb', line 147 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
160 161 162 |
# File 'lib/postal/mailing.rb', line 160 def valid? return validate end |
#validate ⇒ Object
Determines whether we have everything we need to send an email
166 167 168 |
# File 'lib/postal/mailing.rb', line 166 def validate return (@list_name && @to && @subject) ? true : false end |