class Smyte::Notification

Attributes

options[R]
response[R]

Public Class Methods

new(response, options = {}) click to toggle source
# File lib/smyte/notification.rb, line 12
def initialize(response, options = {})
  @response = response
  @options = options || {}
end
parse(webhook_secret, response, options = {}) click to toggle source
# File lib/smyte/notification.rb, line 3
def self.parse(webhook_secret, response, options = {})
  if webhook_secret != Smyte.webhook_secret
    raise "invalid webhook_secret: #{webhook_secret}"
  end
  Smyte::Notification.new(response, options)
end

Public Instance Methods

items() click to toggle source
# File lib/smyte/notification.rb, line 17
def items
  @items ||= parse_items
end

Protected Instance Methods

parse_items() click to toggle source
# File lib/smyte/notification.rb, line 23
def parse_items
  out = {}
  items = response["items"] || []
  items.each do |hash|
    key = hash["item"]
    next unless key
    name = hash['labelName']
    next unless name
    next unless ::Smyte::Util.label_interesting?(name, options)

    if out[key]
      out[key].send(:add_response, hash)
    else
      out[key] = Smyte::Notification::Item.new(hash)
    end
  end

  out.values
end