Sha256: 1c53ce7726fbed77d253e9baf80e6d6b613b3d01664ed49ccecc0929ae443a84

Contents?: true

Size: 689 Bytes

Versions: 11

Compression:

Stored size: 689 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"

      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: [])
        notifier = ::Slack::Notifier.new(slack_webhook_url, channel: slack_channel)
        notifier.post(text: text, attachments: attachments)
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
mihari-0.11.0 lib/mihari/notifiers/slack.rb
mihari-0.10.0 lib/mihari/notifiers/slack.rb
mihari-0.9.1 lib/mihari/notifiers/slack.rb
mihari-0.9.0 lib/mihari/notifiers/slack.rb
mihari-0.8.2 lib/mihari/notifiers/slack.rb
mihari-0.8.1 lib/mihari/notifiers/slack.rb
mihari-0.8.0 lib/mihari/notifiers/slack.rb
mihari-0.7.0 lib/mihari/notifiers/slack.rb
mihari-0.6.0 lib/mihari/notifiers/slack.rb
mihari-0.5.2 lib/mihari/notifiers/slack.rb
mihari-0.5.1 lib/mihari/notifiers/slack.rb