Class: SesDashboard::WebhookProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/ses_dashboard/webhook_processor.rb

Overview

Parses a raw SNS HTTP POST body and returns a normalized Result.

Usage:

result = WebhookProcessor.new(request.body.read).process
case result.action
when :confirm_subscription
  Net::HTTP.get(URI(result.subscribe_url))
when :process_event
  WebhookEventPersistor.new(project, result).persist
end

Defined Under Namespace

Classes: Result

Instance Method Summary collapse

Constructor Details

#initialize(raw_body) ⇒ WebhookProcessor

Returns a new instance of WebhookProcessor.



31
32
33
# File 'lib/ses_dashboard/webhook_processor.rb', line 31

def initialize(raw_body)
  @raw_body = raw_body
end

Instance Method Details

#processObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ses_dashboard/webhook_processor.rb', line 35

def process
  sns = parse_json(@raw_body)
  return unknown_result unless sns

  case sns["Type"]
  when "SubscriptionConfirmation"
    Result.new(action: :confirm_subscription, subscribe_url: sns["SubscribeURL"])
  when "Notification"
    process_notification(sns)
  else
    # SNS raw message delivery — the body is the SES event payload directly,
    # with no SNS envelope. Treat it as a notification message directly.
    process_raw_ses_event(sns)
  end
rescue => e
  Rails.logger.error("[SesDashboard] WebhookProcessor error: #{e.message}") if defined?(Rails)
  unknown_result
end