Sha256: 621e8e2d6e0ac5100e4868fee2d539b714fd06e8c522ee9c6e1885710d67f620

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

module EmailEvents::Adapters
  module Ses
    class EventData < Abstract::EventData
      def initialize(raw_data)
        @sns_data = JSON.parse raw_data['Message']

        raise "Unrecognized SES event type" if event_type.nil?
      end

      def event_type
        case @sns_data['notificationType']
        when 'Bounce'
          :bounce
        when 'Complaint'
          :spamreport
        when 'Delivery'
          :delivered
        else
          nil
        end
      end

      def event_timestamp
        Time.parse @sns_data['mail']['timestamp']
      end

      def recipients
        @sns_data['mail']['destination']
      end

      def smtp_status_code
        # only supported for bounce events
        return nil unless event_type == :bounce

        status_code_str = @sns_data['bounce']['bouncedRecipients'].last['status']
        return nil if status_code_str.nil?

        status_code_str.gsub(/\./,'').to_i
      end

      def reason
        # only supported for bounce events
        return nil unless event_type == :bounce

        @sns_data['bounce']['bounceSubType']
      end

      def smtp_message_id
        # not supported by SNS
        nil
      end

      def provider_message_id
        @sns_data['mail']['messageId']
      end

      def raw_data
        @sns_data
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
email_events-1.0 lib/email_events/adapters/ses/event_data.rb