Sha256: 8bf59f14fdbefdad5da530b773b7af2f5967f417efdf489f8148b02758f5eaab

Contents?: true

Size: 746 Bytes

Versions: 1

Compression:

Stored size: 746 Bytes

Contents

# frozen_string_literal: true

require 'emailbutler/webhooks/mappers/sendgrid'

module Emailbutler
  module Webhooks
    class Receiver
      SENDGRID_USER_AGENT = 'SendGrid Event API'

      def self.call(args={})
        new.call(**args)
      end

      def call(user_agent:, payload:)
        select_mapper(user_agent)
          .call(payload: payload)
          .each { |event|
            message = Emailbutler.find_message_by(uuid: event.delete(:message_uuid))
            Emailbutler.create_message_event(message, event)
          }
      end

      private

      def select_mapper(user_agent)
        case user_agent
        when SENDGRID_USER_AGENT then Emailbutler::Webhooks::Mappers::Sendgrid
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
emailbutler-0.2.2 lib/emailbutler/webhooks/receiver.rb