Class: Slackit
- Inherits:
-
Object
- Object
- Slackit
- Defined in:
- lib/slackit.rb,
lib/slackit/version.rb
Overview
To follow
Constant Summary collapse
- VERSION =
'1.1.1'.freeze
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Slackit
constructor
A new instance of Slackit.
-
#send(text) ⇒ Object
sends a notification returns true after a successfull pust.
Constructor Details
#initialize(options = {}) ⇒ Slackit
Returns a new instance of Slackit.
8 9 10 11 12 13 14 15 |
# File 'lib/slackit.rb', line 8 def initialize( = {}) @webhook_url = [:webhook_url] @username = [:username] @channel = [:channel] @icon_emoji = [:icon_emoji] raise ArgumentError.new('Webhook URL required') if @webhook_url.nil? end |
Instance Method Details
#send(text) ⇒ Object
sends a notification returns true after a successfull pust
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/slackit.rb', line 19 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 || '#general' 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 |