Sha256: 25242175602437740afc40c21999972861b28d402805cab5554694f240d74081

Contents?: true

Size: 876 Bytes

Versions: 9

Compression:

Stored size: 876 Bytes

Contents

# frozen_string_literal: true

module Boppers
  module Notifier
    class Slack
      COLORS = {
        green: "good",
        red: "danger"
      }.freeze

      attr_reader :api_token, :channel, :subscribe

      def initialize(api_token:, channel:, subscribe: nil)
        @api_token = api_token
        @channel = channel
        @subscribe = subscribe
      end

      def call(subject, message, options)
        params = {
          token: api_token,
          text: "",
          channel: channel,
          attachments: JSON.dump(
            [
              {
                fallback: message,
                title: subject,
                text: message,
                color: COLORS.fetch(options[:color])
              }
            ]
          )
        }

        HttpClient.post("https://slack.com/api/chat.postMessage", params)
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
boppers-0.0.11 lib/boppers/notifier/slack.rb
boppers-0.0.10 lib/boppers/notifier/slack.rb
boppers-0.0.9 lib/boppers/notifier/slack.rb
boppers-0.0.8 lib/boppers/notifier/slack.rb
boppers-0.0.7 lib/boppers/notifier/slack.rb
boppers-0.0.6 lib/boppers/notifier/slack.rb
boppers-0.0.5 lib/boppers/notifier/slack.rb
boppers-0.0.4 lib/boppers/notifier/slack.rb
boppers-0.0.3 lib/boppers/notifier/slack.rb