Module: Slackistrano
- Defined in:
- lib/slackistrano.rb,
lib/slackistrano/version.rb
Constant Summary collapse
- VERSION =
'0.1.5'
Class Method Summary collapse
- .post(team: nil, token: nil, webhook: nil, via_slackbot: false, payload: {}) ⇒ Object
- .post_as_slackbot(team: nil, token: nil, webhook: nil, payload: {}) ⇒ Object
- .post_as_webhook(team: nil, token: nil, webhook: nil, payload: {}) ⇒ Object
Class Method Details
.post(team: nil, token: nil, webhook: nil, via_slackbot: false, payload: {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/slackistrano.rb', line 12 def self.post(team: nil, token: nil, webhook: nil, via_slackbot: false, payload: {}) if via_slackbot post_as_slackbot(team: team, token: token, webhook: webhook, payload: payload) else post_as_webhook(team: team, token: token, webhook: webhook, payload: payload) end rescue => e puts "There was an error notifying Slack." puts e.inspect end |
.post_as_slackbot(team: nil, token: nil, webhook: nil, payload: {}) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/slackistrano.rb', line 26 def self.post_as_slackbot(team: nil, token: nil, webhook: nil, payload: {}) 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| http.request_post uri.request_uri, payload[:text] end end |
.post_as_webhook(team: nil, token: nil, webhook: nil, payload: {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/slackistrano.rb', line 37 def self.post_as_webhook(team: nil, token: nil, webhook: nil, payload: {}) params = {'payload' => payload.to_json} if webhook.nil? webhook = "https://#{team}.slack.com/services/hooks/incoming-webhook" params.merge!('token' => token) end uri = URI(webhook) Net::HTTP.post_form(uri, params) end |