Sha256: c1a3d7e8c105a70d3614aedec89d15e4e278f4fd22557909ab72f651c5fee0c6

Contents?: true

Size: 853 Bytes

Versions: 1

Compression:

Stored size: 853 Bytes

Contents

class EmailEvents::Service::HandleEvent < EmailEvents::Service
  def initialize(raw_response)
    @raw_response = raw_response
  end

  def call
    sent_emails = EmailEvents::Service::RetrieveDataFromHeader.call(event_data: event_data)
    return if sent_emails.blank?

    # in occasional cases (when there's no UUID), there will be multiple sent_emails that match the event: we
    # apply the event handling to each one
    sent_emails.each do |email_data|
      begin
        mailer = email_data.mailer_class.constantize.send :new
        mailer.send :__handle_event, event_data, email_data
      end
    end

    # no data to output back to Rack
    nil
  end

  private
  def event_data
    @event_data ||= event_data_adapter_class.new(@raw_response)
  end

  def event_data_adapter_class
    EmailEvents.adapter.const_get('EventData')
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
email_events-1.0 lib/email_events/services/handle_event.rb