Sha256: a5cf829ea6aee370a84003f538e86a618a36008467ecfbc6c3e406dbb6f6101d

Contents?: true

Size: 790 Bytes

Versions: 2

Compression:

Stored size: 790 Bytes

Contents

require 'slackistrano/version'
require 'net/http'
require 'json'

load File.expand_path("../slackistrano/tasks/slack.rake", __FILE__)

module Slackistrano
  def self.post(team: nil, token: nil, via_slackbot: false, payload: {})
    if via_slackbot
      uri = URI(URI.encode("https://#{team}.slack.com/services/hooks/slackbot?token=#{token}&channel=#{payload[:channel]}"))

      Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
        response = http.request_post uri.request_uri, payload[:text]
      end
    else
      uri = URI("https://#{team}.slack.com/services/hooks/incoming-webhook")
      res = Net::HTTP.post_form(uri, 'token' => token, 'payload' => payload.to_json)
    end
  rescue => e
    puts "There was an error notifying Slack."
    puts e.inspect
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
slackistrano-0.1.1 lib/slackistrano.rb
slackistrano-0.1.0 lib/slackistrano.rb