class UniformNotifier::Slack

Constants

POSSIBLE_OPTIONS

Public Class Methods

active?() click to toggle source
# File lib/uniform_notifier/slack.rb, line 8
def active?
  @slack
end
setup_connection(config={}) click to toggle source
# File lib/uniform_notifier/slack.rb, line 12
def setup_connection(config={})
  webhook_url, options = parse_config(config)
  fail_connection('webhook_url required for Slack notification') unless webhook_url

  require 'slack-notifier'
  @slack = ::Slack::Notifier.new webhook_url, options
rescue LoadError
  fail_connection 'You must install the slack-notifier gem to use Slack notification: '\
                  '`gem install slack-notifier`'
end

Protected Class Methods

_out_of_channel_notify(data) click to toggle source
# File lib/uniform_notifier/slack.rb, line 25
def _out_of_channel_notify(data)
  message = data.values.compact.join("\n")
  notify(message)
end

Private Class Methods

fail_connection(message) click to toggle source
# File lib/uniform_notifier/slack.rb, line 32
def fail_connection(message)
  @slack = nil
  raise NotificationError.new(message)
end
notify(message) click to toggle source
# File lib/uniform_notifier/slack.rb, line 37
def notify(message)
  @slack.ping message
end
parse_config(config) click to toggle source
# File lib/uniform_notifier/slack.rb, line 41
def parse_config(config)
  options = config.select do |name, value|
    POSSIBLE_OPTIONS.include?(name) && !value.nil?
  end

  return config[:webhook_url], options
end