Class: SlackNotify::Client
- Inherits:
-
Object
- Object
- SlackNotify::Client
- Defined in:
- lib/slack-notify.rb
Instance Method Summary collapse
-
#initialize(team, token, options = {}) ⇒ Client
constructor
A new instance of Client.
- #notify(text, channel = nil) ⇒ Object
- #test ⇒ Object
Constructor Details
#initialize(team, token, options = {}) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/slack-notify.rb', line 9 def initialize(team, token, = {}) @team = team @token = token @username = [:username] || "webhookbot" @channel = [:channel] || "#general" raise ArgumentError, "Team name required" if @team.nil? raise ArgumentError, "Token required" if @token.nil? raise ArgumentError, "Invalid team name" unless valid_team_name? end |
Instance Method Details
#notify(text, channel = nil) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/slack-notify.rb', line 24 def notify(text, channel = nil) channels = [channel || @channel].flatten.compact.uniq channels.each do |chan| chan.prepend("#") if chan[0] != "#" send_payload(text: text, username: @username, channel: chan) end true end |
#test ⇒ Object
20 21 22 |
# File 'lib/slack-notify.rb', line 20 def test notify("This is a test message!") end |