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' => 'opened',
  'click' => 'opened'
}.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']
    message_uuid = message_uuid[1..-2] if message_uuid.starts_with?('<') && message_uuid.ends_with?('>')
    next if message_uuid.nil?

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