Class: Slackit
- Inherits:
-
Object
- Object
- Slackit
- Defined in:
- lib/slackit.rb,
lib/slackit/version.rb
Overview
To follow
Constant Summary collapse
- VERSION =
'1.0.0'.freeze
Instance Method Summary collapse
-
#initialize(webhook_url, channel = false, username = 'SlackIT', icon_emoji = ':wolf:') ⇒ Slackit
constructor
A new instance of Slackit.
-
#send(text) ⇒ Object
sends a notification returns true after a successfull pust.
Constructor Details
#initialize(webhook_url, channel = false, username = 'SlackIT', icon_emoji = ':wolf:') ⇒ Slackit
Returns a new instance of Slackit.
8 9 10 11 12 13 |
# File 'lib/slackit.rb', line 8 def initialize(webhook_url, channel = false, username = 'SlackIT', icon_emoji = ':wolf:') @webhook_url = webhook_url @channel = channel @username = username @icon_emoji = icon_emoji end |
Instance Method Details
#send(text) ⇒ Object
sends a notification returns true after a successfull pust
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/slackit.rb', line 17 def send(text) # send as json headers = { 'Content-Type' => 'application/json' } # payload body = { 'text': text, 'icon_emoji': @icon_emoji, username: @username } # add the channel if there is one otherwise the default channel body['channel'] = @channel if @channel begin response = HTTParty.post(@webhook_url, body: body.to_json, headers: headers) return true if response.code == 200 return false rescue HTTParty::Error, SocketError => _e return false end end |