mirror of
https://github.com/internetee/registry.git
synced 2025-08-06 09:45:11 +02:00
Reflect new bounced mail structure
This commit is contained in:
parent
659cb7f4e6
commit
98674ab381
2 changed files with 26 additions and 28 deletions
|
@ -1,6 +1,5 @@
|
|||
class BouncedMailAddress < ApplicationRecord
|
||||
validates :email, presence: true
|
||||
validates :bounce_reason, :recipient_json, :response_json, presence: true
|
||||
validates :email, :message_id, :bounce_type, :bounce_subtype, :action, :status, presence: true
|
||||
before_validation :assign_bounce_reason
|
||||
|
||||
def assign_bounce_reason
|
||||
|
@ -9,31 +8,24 @@ class BouncedMailAddress < ApplicationRecord
|
|||
self.bounce_reason = "#{action} (#{status} #{diagnostic})"
|
||||
end
|
||||
|
||||
def diagnostic
|
||||
return unless recipient_json
|
||||
|
||||
recipient_json['diagnosticCode']
|
||||
end
|
||||
|
||||
def action
|
||||
return unless recipient_json
|
||||
|
||||
recipient_json['action']
|
||||
end
|
||||
|
||||
def status
|
||||
return unless recipient_json
|
||||
|
||||
recipient_json['status']
|
||||
end
|
||||
|
||||
def self.record(json)
|
||||
bounced_records = json['bounce']['bouncedRecipients']
|
||||
bounced_records.each do |record|
|
||||
bounce_record = BouncedMailAddress.new(email: record['emailAddress'], recipient_json: record,
|
||||
response_json: json)
|
||||
bounce_record = BouncedMailAddress.new(params_from_json(json, record))
|
||||
|
||||
bounce_record.save
|
||||
end
|
||||
end
|
||||
|
||||
def params_from_json(json, bounced_record)
|
||||
{
|
||||
email: bounced_record['emailAddress'],
|
||||
message_id: json['mail']['messageId'],
|
||||
bounce_type: json['bounce']['bounceType'],
|
||||
bounce_subtype: json['bounce']['bounceSubType'],
|
||||
action: bounced_record['action'],
|
||||
status: bounced_record['status'],
|
||||
diagnostic: bounced_record['diagnosticCode'],
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue