Sha256: 07a9fb9352711dff616823d78b6af8b0d51e925eab346b7a79d2aa5e0f06442c

Contents?: true

Size: 918 Bytes

Versions: 2

Compression:

Stored size: 918 Bytes

Contents

# frozen_string_literal: true

module Emailbutler
  module Webhooks
    module Mappers
      class Mailjet
        DELIVERABILITY_MAPPER = {
          'sent' => 'processed',
          'open' => 'delivered',
          'click' => 'delivered',
          'unsub' => 'failed',
          'blocked' => 'failed',
          'bounce' => 'failed',
          'spam' => 'failed'
        }.freeze

        def call(payload:)
          payload.stringify_keys!
          # message-id contains data like <uuid>
          message_uuid = payload['Message_GUID']
          status = DELIVERABILITY_MAPPER[payload['event']]
          return [] if message_uuid.nil? || status.nil?

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
emailbutler-0.8.4 lib/emailbutler/webhooks/mappers/mailjet.rb
emailbutler-0.8.3 lib/emailbutler/webhooks/mappers/mailjet.rb