Class: Slackit
- Inherits:
-
Object
- Object
- Slackit
- Defined in:
- lib/slackit.rb,
lib/slackit/version.rb
Overview
To follow
Constant Summary collapse
- VERSION =
'1.1.6'
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.
10 11 12 13 14 15 16 17 |
# File 'lib/slackit.rb', line 10 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
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/slackit.rb', line 21 def send(text) # send as json headers = { 'Content-Type' => 'application/json' } # payload text = text.gsub('\\n', "\n") # ensure newlines are not escaped body = { 'text' => text, 'icon_emoji' => @icon_emoji, 'username' => @username } # add the channel if there is one body['channel'] ||= @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 |