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.



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

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.



3
4
5
# File 'lib/slack_messaging/notify_slack.rb', line 3

def channel
  @channel
end

#icon_emojiObject

Returns the value of attribute icon_emoji.



3
4
5
# File 'lib/slack_messaging/notify_slack.rb', line 3

def icon_emoji
  @icon_emoji
end

#icon_urlObject

Returns the value of attribute icon_url.



3
4
5
# File 'lib/slack_messaging/notify_slack.rb', line 3

def icon_url
  @icon_url
end

#textObject

Returns the value of attribute text.



3
4
5
# File 'lib/slack_messaging/notify_slack.rb', line 3

def text
  @text
end

#usernameObject

Returns the value of attribute username.



3
4
5
# File 'lib/slack_messaging/notify_slack.rb', line 3

def username
  @username
end

#webhook_urlObject

Returns the value of attribute webhook_url.



3
4
5
# File 'lib/slack_messaging/notify_slack.rb', line 3

def webhook_url
  @webhook_url
end

Instance Method Details

#performObject



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

def perform
  options = {
    channel: channel,
    username: username,
    icon_emoji: icon_emoji,
    text: text
  }

  HTTParty.post(webhook_url, body: options.to_json)
end