Class: Integral::SlackBot

Inherits:
Object
  • Object
show all
Defined in:
lib/integral/slack_bot.rb

Overview

Interacts with Slack web hook

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(web_hook_url) ⇒ SlackBot

Returns a new instance of SlackBot.

Parameters:

  • web_hook_url (String)

    Slack web hook URL to ping



13
14
15
# File 'lib/integral/slack_bot.rb', line 13

def initialize(web_hook_url)
  @bot = Slack::Notifier.new(web_hook_url)
end

Class Method Details

.ping(opts) ⇒ Object

Parameters:

  • opts (Hash)

    web hook options



5
6
7
8
9
10
# File 'lib/integral/slack_bot.rb', line 5

def self.ping(opts)
  return if Integral.slack_web_hook_url.blank?

  slackbot = SlackBot.new(Integral.slack_web_hook_url)
  slackbot.ping(opts)
end

Instance Method Details

#ping(message_options) ⇒ Object

Parameters:

  • message_options (Hash)

    containing slack message options



18
19
20
21
22
23
24
25
# File 'lib/integral/slack_bot.rb', line 18

def ping(message_options)
  ping_opts = {}
  slack_message = message(message_options[:message])

  response = @bot.ping(slack_message.deep_stringify_keys, ping_opts)

  log_error_message(response) if response != '200'
end