Class: URLhausMonitor::Notifier

Inherits:
Object
  • Object
show all
Defined in:
lib/urlhaus_monitor/notifier.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.notify(title, attachments) ⇒ Object



30
31
32
# File 'lib/urlhaus_monitor/notifier.rb', line 30

def self.notify(title, attachments)
  new.notifiy(title, attachments)
end

Instance Method Details

#notifiy(title, attachments = []) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/urlhaus_monitor/notifier.rb', line 7

def notifiy(title, attachments = [])
  attachments << { title: "N/A" } if attachments.empty?

  if slack_webhook_url?
    slack = Slack::Incoming::Webhooks.new(slack_webhook_url, channel: slack_channel)
    slack.post title, attachments: attachments
  else
    puts title
  end
end

#slack_channelObject



22
23
24
# File 'lib/urlhaus_monitor/notifier.rb', line 22

def slack_channel
  ENV.fetch "SLACK_CHANNEL", "#general"
end

#slack_webhook_urlObject



18
19
20
# File 'lib/urlhaus_monitor/notifier.rb', line 18

def slack_webhook_url
  ENV.fetch "SLACK_WEBHOOK_URL"
end

#slack_webhook_url?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/urlhaus_monitor/notifier.rb', line 26

def slack_webhook_url?
  ENV.key? "SLACK_WEBHOOK_URL"
end