Class: Osm::Email::DeliveryReport
Defined Under Namespace
Constant Summary collapse
- TIME_FORMAT =
'%d/%m/%Y %H:%M'
- VALID_STATUSES =
[:processed, :delivered, :bounced]
Constants inherited from Model
Instance Attribute Summary collapse
-
#id ⇒ Fixnum
The id of the email.
- #recipients ⇒ Array<Osm::DeliveryReport::Email::Recipient>
-
#section_id ⇒ Fixnum
The id of the section which sent the email.
-
#sent_at ⇒ Time
When the email was sent.
-
#subject ⇒ String
The subject line of the email.
Class Method Summary collapse
-
.get_for_section(api, section, options = {}) ⇒ Array<Osm::Email::DeliveryReport>
Get delivery reports.
Instance Method Summary collapse
- #<=>(another) ⇒ Object
-
#bounced_recipients ⇒ Array<Osm::Email::DeliveryReport::Recipient>
Count the recipients of the message with a status of :bounced.
-
#bounced_recipients? ⇒ Boolean
Whether there are recipients of the message with a status of :bounced.
-
#delivered_recipients ⇒ Array<Osm::Email::DeliveryReport::Recipient>
Count the recipients of the message with a status of :delivered.
-
#delivered_recipients? ⇒ Boolean
Whether there are recipients of the message with a status of :delivered.
-
#get_email(api, options = {}) ⇒ Osm::Email::DeliveryReport::Email
Get email contents for this report.
-
#initialize ⇒ Object
constructor
Initialize a new DeliveryReport.
-
#processed_recipients ⇒ Array<Osm::Email::DeliveryReport::Recipient>
The recipients of the message with a status of :processed.
-
#processed_recipients? ⇒ Boolean
Whether there are recipients of the message with a status of :processed.
- #to_s ⇒ Object
Methods inherited from Model
#<, #<=, #>, #>=, #between?, #changed_attributes, configure, #reset_changed_attributes, #to_i
Constructor Details
#initialize ⇒ Object
Initialize a new DeliveryReport
|
# File 'lib/osm/email.rb', line 99
|
Instance Attribute Details
#id ⇒ Fixnum
Returns the id of the email.
82 |
# File 'lib/osm/email.rb', line 82 attribute :id, type: Integer |
#recipients ⇒ Array<Osm::DeliveryReport::Email::Recipient>
82 |
# File 'lib/osm/email.rb', line 82 attribute :id, type: Integer |
#section_id ⇒ Fixnum
Returns the id of the section which sent the email.
82 |
# File 'lib/osm/email.rb', line 82 attribute :id, type: Integer |
#sent_at ⇒ Time
Returns when the email was sent.
82 |
# File 'lib/osm/email.rb', line 82 attribute :id, type: Integer |
#subject ⇒ String
Returns the subject line of the email.
82 |
# File 'lib/osm/email.rb', line 82 attribute :id, type: Integer |
Class Method Details
.get_for_section(api, section, options = {}) ⇒ Array<Osm::Email::DeliveryReport>
Get delivery reports
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 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/osm/email.rb', line 109 def self.get_for_section(api, section, ={}) Osm::Model.require_access_to_section(api, section, ) section_id = section.to_i cache_key = ['email_delivery_reports', section_id] if ![:no_cache] && Osm::Model.cache_exist?(api, cache_key) return cache_read(api, cache_key) end reports = [] recipients = {} data = api.perform_query("ext/settings/emails/?action=getDeliveryReport§ionid=#{section_id}") data.each do |item| case item['type'] when 'email' # Create an Osm::Email::DeliveryReport in reports array id = Osm::to_i_or_nil(item['id']) sent_at_str, subject = item['name'].to_s.split(' - ', 2).map{ |i| i.to_s.strip } reports.push Osm::Email::DeliveryReport.new( id: id, sent_at: Time.strptime(sent_at_str, TIME_FORMAT), subject: subject, section_id: section_id, ) recipients[id] = [] when 'oneEmail' # Create an Osm::Email::DeliveryReport::Email::Recipient in recipients[email_id] array report_id, id = item['id'].to_s.strip.split('-').map{ |i| Osm::to_i_or_nil(i) } status = item['status_raw'].to_sym status = :bounced if status.eql?(:bounce) member_id = Osm::to_i_or_nil(item['member_id']) recipients[report_id].push Osm::Email::DeliveryReport::Recipient.new( id: id, address: item['email'], status: status, member_id: member_id, ) end end # each item in data # Add recipients to reports reports.each do |report| recs = recipients[report.id] # Set report for each recipient recs.each do |recipient| recipient.delivery_report = report end report.recipients = recs end cache_write(api, cache_key, reports) return reports end |
Instance Method Details
#<=>(another) ⇒ Object
216 217 218 219 220 |
# File 'lib/osm/email.rb', line 216 def <=>(another) result = self.sent_at <=> another.try(:sent_at) result = self.id <=> another.try(:id) if result.eql?(0) return result end |
#bounced_recipients ⇒ Array<Osm::Email::DeliveryReport::Recipient>
Count the recipients of the message with a status of :bounced
202 203 204 205 206 207 208 209 |
# File 'lib/osm/email.rb', line 202 VALID_STATUSES.each do |attribute| define_method "#{attribute}_recipients" do recipients.select{ |r| r.status.eql?(attribute) } end define_method "#{attribute}_recipients?" do send("#{attribute}_recipients").any? end end |
#bounced_recipients? ⇒ Boolean
Whether there are recipients of the message with a status of :bounced
202 203 204 205 206 207 208 209 |
# File 'lib/osm/email.rb', line 202 VALID_STATUSES.each do |attribute| define_method "#{attribute}_recipients" do recipients.select{ |r| r.status.eql?(attribute) } end define_method "#{attribute}_recipients?" do send("#{attribute}_recipients").any? end end |
#delivered_recipients ⇒ Array<Osm::Email::DeliveryReport::Recipient>
Count the recipients of the message with a status of :delivered
202 203 204 205 206 207 208 209 |
# File 'lib/osm/email.rb', line 202 VALID_STATUSES.each do |attribute| define_method "#{attribute}_recipients" do recipients.select{ |r| r.status.eql?(attribute) } end define_method "#{attribute}_recipients?" do send("#{attribute}_recipients").any? end end |
#delivered_recipients? ⇒ Boolean
Whether there are recipients of the message with a status of :delivered
202 203 204 205 206 207 208 209 |
# File 'lib/osm/email.rb', line 202 VALID_STATUSES.each do |attribute| define_method "#{attribute}_recipients" do recipients.select{ |r| r.status.eql?(attribute) } end define_method "#{attribute}_recipients?" do send("#{attribute}_recipients").any? end end |
#get_email(api, options = {}) ⇒ Osm::Email::DeliveryReport::Email
Get email contents for this report
170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/osm/email.rb', line 170 def get_email(api, ={}) Osm::Model.require_access_to_section(api, section_id, ) cache_key = ['email_delivery_reports_email', section_id, id] if ![:no_cache] && Osm::Model.cache_exist?(api, cache_key) return cache_read(api, cache_key) end email = Osm::Email::DeliveryReport::Email.fetch_from_osm(api, section_id, id) cache_write(api, cache_key, email) return email end |
#processed_recipients ⇒ Array<Osm::Email::DeliveryReport::Recipient>
The recipients of the message with a status of :processed
202 203 204 205 206 207 208 209 |
# File 'lib/osm/email.rb', line 202 VALID_STATUSES.each do |attribute| define_method "#{attribute}_recipients" do recipients.select{ |r| r.status.eql?(attribute) } end define_method "#{attribute}_recipients?" do send("#{attribute}_recipients").any? end end |
#processed_recipients? ⇒ Boolean
Whether there are recipients of the message with a status of :processed
202 203 204 205 206 207 208 209 |
# File 'lib/osm/email.rb', line 202 VALID_STATUSES.each do |attribute| define_method "#{attribute}_recipients" do recipients.select{ |r| r.status.eql?(attribute) } end define_method "#{attribute}_recipients?" do send("#{attribute}_recipients").any? end end |
#to_s ⇒ Object
212 213 214 |
# File 'lib/osm/email.rb', line 212 def to_s "#{sent_at.strftime(TIME_FORMAT)} - #{subject}" end |