Class: SlackMessaging::NotifyDiscord

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ NotifyDiscord

Returns a new instance of NotifyDiscord.



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

def initialize(text)
  self.avatar_url = SlackMessaging::Config.discord[:avatar_url] || 'https://i.imgur.com/9ZTbiSF.jpg'
  self.text = text
  self.username = SlackMessaging::Config.discord[:username] || 'Slack Messaging'
  self.webhook_url = SlackMessaging::Config.discord[:webhook_url]
end

Instance Attribute Details

#avatar_urlObject

Returns the value of attribute avatar_url.



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

def avatar_url
  @avatar_url
end

#textObject

Returns the value of attribute text.



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

def text
  @text
end

#usernameObject

Returns the value of attribute username.



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

def username
  @username
end

#webhook_urlObject

Returns the value of attribute webhook_url.



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

def webhook_url
  @webhook_url
end

Instance Method Details

#performObject



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

def perform
  options = {
    avatar_url: avatar_url,
    content: text,
    username: username
  }

  `curl -s -H "Content-Type: application/json" -d '#{options.to_json.gsub("'", "'\\\\''")}' '#{webhook_url}'`
end