Sha256: 9dbe24d0b35e8ee453475c4278d1288bf0fce783cc3181697ef7a52a88b05912

Contents?: true

Size: 1006 Bytes

Versions: 6

Compression:

Stored size: 1006 Bytes

Contents

# frozen_string_literal: true

module Emailbutler
  module Webhooks
    module Mappers
      class Smtp2Go
        DELIVERABILITY_MAPPER = {
          'processed' => 'processed',
          'delivered' => 'delivered',
          'open' => 'delivered',
          'click' => 'delivered',
          'bounce' => 'failed',
          'reject' => 'failed',
          'spam' => 'failed'
        }.freeze

        def self.call(...)
          new.call(...)
        end

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

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
emailbutler-0.7.6 lib/emailbutler/webhooks/mappers/smtp2go.rb
emailbutler-0.7.5 lib/emailbutler/webhooks/mappers/smtp2go.rb
emailbutler-0.7.4 lib/emailbutler/webhooks/mappers/smtp2go.rb
emailbutler-0.7.3 lib/emailbutler/webhooks/mappers/smtp2go.rb
emailbutler-0.7.2 lib/emailbutler/webhooks/mappers/smtp2go.rb
emailbutler-0.7.1 lib/emailbutler/webhooks/mappers/smtp2go.rb