Sha256: bcb470681b2ccc691e1954e3d36299e300335ee336b5b1da5dc774740d225796
Contents?: true
Size: 1.1 KB
Versions: 2
Compression:
Stored size: 1.1 KB
Contents
require 'slackit/version' require 'httparty' # # To follow # class Slackit def initialize(options = {}) @webhook_url = options[:webhook_url] @username = options[:username] @channel = options[:channel] @icon_emoji = options[:icon_emoji] raise ArgumentError.new('Webhook URL required') if @webhook_url.nil? end # sends a notification # returns true after a successfull pust 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 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 end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
slackit-1.1.4 | lib/slackit.rb |
slackit-1.1.3 | lib/slackit.rb |