module Tikkie::Notification

Parses the payload for a Notification.

Public Instance Methods

parse(body) click to toggle source
# 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