Class: SesBlacklistRails::Api::NotificationController

Inherits:
SesBlacklistRails::ApplicationController show all
Defined in:
app/controllers/ses_blacklist_rails/api/notification_controller.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#indexObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/ses_blacklist_rails/api/notification_controller.rb', line 9

def index
  if @params[:Type] == 'SubscriptionConfirmation'
    create_notification('', :other)
    begin
      uri = URI.parse @params[:SubscribeURL]
      res = Net::HTTP.get_response uri
      return render plain: '', status: 500 if res.code.to_i != 200
    rescue StandardError
      return render plain: '', status: 500
    end

  elsif @params[:Type] == 'Notification'
    message = parse_json @params[:Message]
    case message[:notificationType]
    when 'Bounce'
      message[:bounce][:bouncedRecipients].each do |r|
        create_notification(r, :bounce)
      end
    when 'Complaint'
      message[:complaint][:complainedRecipients].each do |r|
        create_notification(r, :complaint)
      end
    when 'Delivery'
      message[:delivery][:recipients].each do |r|
        create_notification(r, :delivery)
      end
    end
  else
    create_notification('', :other)
    render plain: '', status: 403
  end
end