Sha256: ad9e6f06799e5e9c9d85b832848d6227271ad44cfd78f5c998ad42d5c5256dd4

Contents?: true

Size: 779 Bytes

Versions: 13

Compression:

Stored size: 779 Bytes

Contents

# frozen_string_literal: true

module Mihari
  module Notifiers
    class Slack < Base
      SLACK_WEBHOOK_URL_KEY = "SLACK_WEBHOOK_URL"
      SLACK_CHANNEL_KEY = "SLACK_CHANNEL"
      DEFAULT_USERNAME = "mihari"

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

      def slack_webhook_url
        ENV.fetch SLACK_WEBHOOK_URL_KEY
      end

      def slack_webhook_url?
        ENV.key? SLACK_WEBHOOK_URL_KEY
      end

      def valid?
        slack_webhook_url?
      end

      def notify(text:, attachments: [], mrkdwn: true)
        notifier = ::Slack::Notifier.new(slack_webhook_url, channel: slack_channel, username: DEFAULT_USERNAME)
        notifier.post(text: text, attachments: attachments, mrkdwn: true)
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
mihari-0.17.5 lib/mihari/notifiers/slack.rb
mihari-0.17.4 lib/mihari/notifiers/slack.rb
mihari-0.17.3 lib/mihari/notifiers/slack.rb
mihari-0.17.2 lib/mihari/notifiers/slack.rb
mihari-0.17.1 lib/mihari/notifiers/slack.rb
mihari-0.17.0 lib/mihari/notifiers/slack.rb
mihari-0.16.0 lib/mihari/notifiers/slack.rb
mihari-0.15.0 lib/mihari/notifiers/slack.rb
mihari-0.14.0 lib/mihari/notifiers/slack.rb
mihari-0.13.2 lib/mihari/notifiers/slack.rb
mihari-0.13.1 lib/mihari/notifiers/slack.rb
mihari-0.13.0 lib/mihari/notifiers/slack.rb
mihari-0.12.0 lib/mihari/notifiers/slack.rb