Class: EmailLogsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/email_logs_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#dashboard, #keyboard_tools, #upload

Instance Method Details

#logObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/email_logs_controller.rb', line 7

def log
  message_type = request.headers['X-Amz-SNS-Message-Type']
  if ['SubscriptionConfirmation', 'Notification'].include? message_type
    verifier = Aws::SNS::MessageVerifier.new
    body = request.body.read
    if verifier.authentic? body
      aws_data = JSON.parse body
      if message_type == 'SubscriptionConfirmation'
        EmailLog.create(log_type: 'SubscriptionConfirmation', data: aws_data)
      else
        message_data = JSON.parse aws_data['Message']
        log_type = message_data['notificationType']
        destination = message_data['mail']['destination'].join(', ')
        EmailLog.create(log_type: log_type, destination: destination, data: aws_data['Message'])
      end
      render plain: 'OK'
    else
      render plain: "You're not AWS. Go away.", status: 401
    end
  end
end