class Octobot::SlackAgent::Notifier
Attributes
icon_emoji[RW]
username[RW]
webhook_url[RW]
Public Class Methods
new(webhook_url, username='octobot', icon_emoji=nil)
click to toggle source
# File lib/octobot/slack_agent/notifier.rb, line 14 def initialize(webhook_url, username='octobot', icon_emoji=nil) @webhook_url = webhook_url @username = username @icon_emoji = icon_emoji end
Public Instance Methods
error(params)
click to toggle source
# File lib/octobot/slack_agent/notifier.rb, line 28 def error(params) send_attachments [ attachment(params, DANGER) ] end
send(params)
click to toggle source
# File lib/octobot/slack_agent/notifier.rb, line 36 def send(params) send_request(base_params.merge(params)) end
send_attachments(attachments)
click to toggle source
# File lib/octobot/slack_agent/notifier.rb, line 32 def send_attachments(attachments) send attachments: attachments end
success(params)
click to toggle source
# File lib/octobot/slack_agent/notifier.rb, line 20 def success(params) send_attachments [ attachment(params, GOOD) ] end
warn(params)
click to toggle source
# File lib/octobot/slack_agent/notifier.rb, line 24 def warn(params) send_attachments [ attachment(params, WARNING) ] end
Private Instance Methods
attachment(params, color=nil)
click to toggle source
# File lib/octobot/slack_agent/notifier.rb, line 53 def attachment(params, color=nil) base_attachment = { fallback: "#{params[:title]}\n\n#{params[:text]}", } base_attachment[:color] = color if color base_attachment.merge(params) end
base_params()
click to toggle source
# File lib/octobot/slack_agent/notifier.rb, line 45 def base_params bp = {} bp[:username] = username if username bp[:octobot] = username if icon_emoji bp end
send_request(data)
click to toggle source
# File lib/octobot/slack_agent/notifier.rb, line 41 def send_request(data) RestClient.post webhook_url, data.to_json end