Method: Eye::Notify.notify

Defined in:
lib/eye/notify.rb

.notify(contact, message_h) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/eye/notify.rb', line 27

def self.notify(contact, message_h)
  contact = contact.to_s
  settings = Eye::Control.settings
  needed_hash = (settings[:contacts] || {})[contact]

  if needed_hash.blank?
    error "contact #{contact} not found; check your configuration"
    return
  end

  create_proc = lambda do |nh|
    type = nh[:type]
    config = (settings[type] || {}).merge(nh[:opts] || {}).merge(contact: nh[:contact])
    klass = get_class(type)
    notify = klass.new(config, message_h)
    notify.async_notify if notify
  end

  if needed_hash.is_a?(Array)
    needed_hash.each { |nh| create_proc[nh] }
  else
    create_proc[needed_hash]
  end
rescue Object => ex
  log_ex(ex)
end