Class: Emailbutler::Webhooks::Mappers::Mailtrap

Inherits:
Object
  • Object
show all
Defined in:
lib/emailbutler/webhooks/mappers/mailtrap.rb

Constant Summary collapse

DELIVERABILITY_MAPPER =
{
  'delivery' => 'delivered',
  'open' => 'delivered',
  'click' => 'delivered'
}.freeze

Instance Method Summary collapse

Instance Method Details

#call(payload:) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/emailbutler/webhooks/mappers/mailtrap.rb', line 13

def call(payload:)
  payload['events'].filter_map { |message|
    message.stringify_keys!
    message_uuid = message['message_id']
    status = DELIVERABILITY_MAPPER[message['event']] || Emailbutler::Message::FAILED
    next if message_uuid.nil?

    {
      message_uuid: message_uuid,
      status: status,
      timestamp: message['timestamp'] ? Time.at(message['timestamp']).utc.to_datetime : nil
    }
  }
end