Module: Tikkie::Notification

Defined in:
lib/tikkie/notification.rb

Overview

Parses the payload for a Notification.

Class Method Summary collapse

Class Method Details

.parse(body) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/tikkie/notification.rb', line 12

def parse(body)
  notification = JSON.parse(body, symbolize_names: true)
  notification_type = notification[:notificationType]&.capitalize
  return nil if notification_type.nil? || notification_type !~ /[a-z]+/i

  klass = Object.const_get("Tikkie::Notifications::#{notification_type}Notification")
  klass.new(notification)
rescue JSON::ParserError, NameError
  nil
end