Class: Emailbutler::Webhooks::Mappers::Mandrill

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

Constant Summary collapse

DELIVERABILITY_MAPPER =
{
  'send' => 'processed',
  '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/mandrill.rb', line 13

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

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