Skip to content

Commit

Permalink
Merge pull request #23 from cthomaspdx/new_master
Browse files Browse the repository at this point in the history
Fix for issue #9
  • Loading branch information
Justin McNally committed Oct 20, 2014
2 parents 3ec61b0 + 2f68270 commit d806534
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lib/capistrano/slack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,24 @@ module Slack
def payload(announcement)
{
'channel' => fetch(:slack_room),
'username' => fetch(:slack_username),
'username' => fetch(:slack_username, ''),
'text' => announcement,
'icon_emoji' => fetch(:slack_emoji)
'icon_emoji' => fetch(:slack_emoji, '')
}.to_json
end

def slack_connect(message)
uri = URI.parse("https://#{fetch(:slack_subdomain)}.slack.com/services/hooks/incoming-webhook?token=#{fetch(:slack_token)}")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
request = Net::HTTP::Post.new(uri.request_uri)
request.set_form_data(:payload => payload(message))
http.request(request)
begin
uri = URI.parse("https://#{fetch(:slack_subdomain)}.slack.com/services/hooks/incoming-webhook?token=#{fetch(:slack_token)}")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
request = Net::HTTP::Post.new(uri.request_uri)
request.set_form_data(:payload => payload(message))
http.request(request)
rescue SocketError => e
puts "#{e.message} or slack may be down"
end
end
def slack_defaults
if fetch(:slack_deploy_defaults, true) == true
Expand Down

0 comments on commit d806534

Please sign in to comment.