class Sensor::OutputDistribution::Slack

Public Class Methods

new(payload) click to toggle source
# File lib/sensor/output_distribution/slack.rb, line 6
def initialize(payload)
  @payload = payload
end

Public Instance Methods

distribute() click to toggle source
# File lib/sensor/output_distribution/slack.rb, line 10
def distribute
  notifier.ping(content)
end

Protected Instance Methods

content() click to toggle source
# File lib/sensor/output_distribution/slack.rb, line 15
def content
  @payload.data.inject("") do |str, key_value|
    str += "*#{key_value[0]}*\r\n"

    key_value[1].each do |attribute, value|
      str += "  - *#{attribute}*: #{value}\r\n"
    end
    str
  end
end
notifier() click to toggle source
# File lib/sensor/output_distribution/slack.rb, line 26
def notifier
  @notifier ||= ::Slack::Notifier.new(
    ENV['SLACK_WEBHOOK_URL'],
    {
      channel: ENV['SLACK_CHANNEL']
    }
  )
end