Sha256: 715963b436c167b5c6d70e30d85bff45d67c8dfe1efd9c37404877b13bd4aa51

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

require 'pushpop'
require 'slack-notifier'

WEBHOOK_URL = ENV['SLACK_WEBHOOK_URL']

module Pushpop

  class Slack < Step

    PLUGIN_NAME = 'slack'

    Pushpop::Job.register_plugin(PLUGIN_NAME, self)

    attr_accessor :_channel
    attr_accessor :_username
    attr_accessor :_message

    def run(last_response=nil, step_responses=nil)

      configure(last_response, step_responses)

      unless _message
       raise 'Please set the message to send to Slack'
      end

      send_message
    
    end

    def send_message
      notifier = ::Slack::Notifier.new WEBHOOK_URL

      notifier.ping _message, options
    end

    def options
      opts = {}

      if _channel
        if _channel[0] == '#'
          opts['channel'] = _channel
        else
          opts['channel'] = "##{_channel}"
        end
      end

      if _username
        opts['username'] = _username
      end

      return opts
    end

    def channel(channel)
      self._channel = channel
    end

    def username(username)
      self._username = username
    end

    def message(message)
      self._message = message
    end

    def configure(last_response=nil, step_responses=nil)
      self.instance_exec(last_response, step_responses, &block)
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pushpop-slack-0.1.0 lib/pushpop-slack.rb