Class: SlackMessaging::NotifySlack

Inherits:
Object
  • Object
show all
Defined in:
lib/slack_messaging/notify_slack.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ NotifySlack

Returns a new instance of NotifySlack.



7
8
9
10
11
12
13
# File 'lib/slack_messaging/notify_slack.rb', line 7

def initialize(text)
  self.text = text
  self.channel = SlackMessaging::Config.slack[:channel]
  self.webhook_url = SlackMessaging::Config.slack[:webhook_url]
  self.username = SlackMessaging::Config.slack[:username] || "MessageMe"
  self.icon_emoji = SlackMessaging::Config.slack[:icon_emoji] || ":mailbox_with_mail"
end

Instance Attribute Details

#channelObject

Returns the value of attribute channel.



5
6
7
# File 'lib/slack_messaging/notify_slack.rb', line 5

def channel
  @channel
end

#icon_emojiObject

Returns the value of attribute icon_emoji.



5
6
7
# File 'lib/slack_messaging/notify_slack.rb', line 5

def icon_emoji
  @icon_emoji
end

#icon_urlObject

Returns the value of attribute icon_url.



5
6
7
# File 'lib/slack_messaging/notify_slack.rb', line 5

def icon_url
  @icon_url
end

#textObject

Returns the value of attribute text.



5
6
7
# File 'lib/slack_messaging/notify_slack.rb', line 5

def text
  @text
end

#usernameObject

Returns the value of attribute username.



5
6
7
# File 'lib/slack_messaging/notify_slack.rb', line 5

def username
  @username
end

#webhook_urlObject

Returns the value of attribute webhook_url.



5
6
7
# File 'lib/slack_messaging/notify_slack.rb', line 5

def webhook_url
  @webhook_url
end

Instance Method Details

#performObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/slack_messaging/notify_slack.rb', line 15

def perform
  options = {
    webhook_url: webhook_url,
    channel: channel,
    username: username,
    icon_emoji: icon_emoji,
    http_options: { open_timeout: 10 }
  }
  ::Slack::Notifier.new(webhook_url, options).ping(text)
end