class Fushin::Notifier

Public Class Methods

notify(title, text) click to toggle source
# File lib/fushin/notifier.rb, line 31
def self.notify(title, text)
  new.notify(title, text)
end

Public Instance Methods

notify(title, attachments = []) click to toggle source
# File lib/fushin/notifier.rb, line 7
def notify(title, attachments = [])
  if slack_webhook_url?
    slack = Slack::Incoming::Webhooks.new(slack_webhook_url, channel: slack_channel)
    slack.post title, attachments: attachments
  else
    puts title
    attachments.each do |attachment|
      puts "#{attachment.dig(:title)} (#{attachment.dig(:title_link)})"
    end
  end
end
slack_channel() click to toggle source
# File lib/fushin/notifier.rb, line 23
def slack_channel
  ENV.fetch "SLACK_CHANNEL", "#general"
end
slack_webhook_url() click to toggle source
# File lib/fushin/notifier.rb, line 19
def slack_webhook_url
  ENV.fetch "SLACK_WEBHOOK_URL"
end
slack_webhook_url?() click to toggle source
# File lib/fushin/notifier.rb, line 27
def slack_webhook_url?
  ENV.key? "SLACK_WEBHOOK_URL"
end