Restructure bounced mails view

This commit is contained in:
Karl Erik Õunapuu 2020-09-17 13:26:48 +03:00
parent 140df0acf7
commit 6af37a787d
No known key found for this signature in database
GPG key ID: C9DD647298A34764
2 changed files with 55 additions and 28 deletions

View file

@ -1,2 +1,24 @@
class BouncedMailAddress < ApplicationRecord
validates :email, presence: true
validates :bounce_reason, presence: true
def diagnostic
response_json['diagnosticCode']
end
def action
response_json['action']
end
def status
response_json['status']
end
def self.record(json)
bounced_records = json['bounce']['bouncedRecipients']
bounced_records.each do |record|
bounce_record = BouncedMailAddress.new(email: record['emailAddress'], response_json: record)
bounce_record.save
end
end
end