Sha256: 7d1f3772ce49ae2c978bbceb0ac1f01fd357eb748a38cf606b7888fb091ccf9d

Contents?: true

Size: 781 Bytes

Versions: 11

Compression:

Stored size: 781 Bytes

Contents

# frozen_string_literal: true

require "slack/incoming/webhooks"

module Fushin
  class Notifier
    def notify(title, attachments = [])
      if slack_webhook_url?
        slack = Slack::Incoming::Webhooks.new(slack_webhook_url, channel: slack_channel)
        slack.post title, attachments: attachments
      else
        puts title
        attachments.each do |attachment|
          puts "#{attachment.dig(:title)} (#{attachment.dig(:title_link)})"
        end
      end
    end

    def slack_webhook_url
      ENV.fetch "SLACK_WEBHOOK_URL"
    end

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

    def slack_webhook_url?
      ENV.key? "SLACK_WEBHOOK_URL"
    end

    def self.notify(title, text)
      new.notify(title, text)
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
fushin-0.4.2 lib/fushin/notifier.rb
fushin-0.4.1 lib/fushin/notifier.rb
fushin-0.4.0 lib/fushin/notifier.rb
fushin-0.3.4 lib/fushin/notifier.rb
fushin-0.3.3 lib/fushin/notifier.rb
fushin-0.3.2 lib/fushin/notifier.rb
fushin-0.3.1 lib/fushin/notifier.rb
fushin-0.3.0 lib/fushin/notifier.rb
fushin-0.2.0 lib/fushin/notifier.rb
fushin-0.1.1 lib/fushin/notifier.rb
fushin-0.1.0 lib/fushin/notifier.rb