Class: SlackNotify::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/slack-notify.rb

Instance Method Summary collapse

Constructor Details

#initialize(team, token, options = {}) ⇒ Client

Returns a new instance of Client.

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
16
17
18
# File 'lib/slack-notify.rb', line 9

def initialize(team, token, options = {})
  @team     = team
  @token    = token
  @username = options[:username] || "webhookbot"
  @channel  = options[: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

#testObject



20
21
22
# File 'lib/slack-notify.rb', line 20

def test
  notify("This is a test message!")
end