Class: Cpaas::Notification
- Inherits:
-
Object
- Object
- Cpaas::Notification
- Defined in:
- lib/cpaas/resources/notification.rb
Overview
CPaaS notification helper methods
Class Method Summary collapse
-
.parse(notification) ⇒ Object
Parse inbound sms notification received in webhook.
Class Method Details
.parse(notification) ⇒ Object
Parse inbound sms notification received in webhook. It parses the notification and returns simplified version of the response.
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 41 42 43 44 45 46 47 48 49 |
# File 'lib/cpaas/resources/notification.rb', line 14 def self.parse(notification) parsed_notification = convert_hash_keys(notification) top_level_key = parsed_notification.keys.first notification_obj = parsed_notification[top_level_key] case top_level_key when :outbound_sms_message_notification, :inbound_sms_message_notification = notification_obj.dig(:outbound_sms_message).nil? ? notification_obj.dig(:inbound_sms_message) : notification_obj.dig(:outbound_sms_message) { notification_id: notification_obj.dig(:id), notification_date_time: notification_obj.dig(:date_time), type: types[top_level_key] }.merge() when :sms_subscription_cancellation_notification { subscription_id: id_from(notification_obj.dig(:link, 0, :href)), notification_id: notification_obj.dig(:id), notification_date_time: notification_obj.dig(:date_time), type: types[top_level_key] } when :sms_event_notification { notification_id: notification_obj.dig(:id), notification_date_time: notification_obj.dig(:date_time), message_id: id_from(notification_obj.dig(:link, 0, :href)), type: types[top_level_key], event_details: { description: notification_obj.dig(:event_description), type: notification_obj.dig(:event_type) } } else notification_obj end end |