Module: Esendex::PushNotificationHandler
- Included in:
- InboundMessagesController, MessageDeliveredEventsController, MessageFailedEventsController
- Defined in:
- app/controllers/esendex/push_notification_handler.rb
Instance Method Summary collapse
-
#process_notification(type, source) ⇒ Object
Used by controllers to handle incoming push notification.
- #render_error(error) ⇒ Object
Instance Method Details
#process_notification(type, source) ⇒ Object
Used by controllers to handle incoming push notification
type - Symbol indicating type source - String request body of the notification
Returns nothing
12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/controllers/esendex/push_notification_handler.rb', line 12 def process_notification(type, source) if handler = Esendex.send("#{type}_handler") notification_class = Esendex.const_get(type.to_s.camelize) notification = notification_class.from_xml source handler.call notification else logger.info "Received #{type} push notification but no handler configured" if defined?(logger) end end |
#render_error(error) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/controllers/esendex/push_notification_handler.rb', line 24 def render_error(error) lines = [] lines << "Path: #{request.path}" request.body.rewind lines << "Notification XML:\r\n#{request.body.read}" lines << "Error: #{error.class.name} #{error.}" if Esendex.suppress_error_backtrace lines << "[backtrace suppressed]" else lines << error.backtrace.join("\r\n") end lines << "---" lines << "Ruby #{RUBY_VERSION}" lines << "Rails #{Rails::VERSION::STRING}" lines << Esendex.user_agent render text: lines.join("\r\n"), status: 500 end |