Class: SesDashboard::WebhookProcessor
- Inherits:
-
Object
- Object
- SesDashboard::WebhookProcessor
- 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
-
#initialize(raw_body) ⇒ WebhookProcessor
constructor
A new instance of WebhookProcessor.
- #process ⇒ Object
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
#process ⇒ Object
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.}") if defined?(Rails) unknown_result end |