Class: RakeNotifier::Slack::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token, channel: '#test', icon: nil, username: nil) ⇒ Client

Returns a new instance of Client.



42
43
44
45
46
47
# File 'lib/rake_notifier/slack.rb', line 42

def initialize(token, channel: '#test', icon: nil, username: nil)
  Breacan.access_token = @token = token
  @channel = channel
  @icon = icon
  @username = username
end

Instance Attribute Details

#channelObject

Returns the value of attribute channel.



48
49
50
# File 'lib/rake_notifier/slack.rb', line 48

def channel
  @channel
end

#iconObject

Returns the value of attribute icon.



48
49
50
# File 'lib/rake_notifier/slack.rb', line 48

def icon
  @icon
end

#tokenObject

Returns the value of attribute token.



48
49
50
# File 'lib/rake_notifier/slack.rb', line 48

def token
  @token
end

#usernameObject

Returns the value of attribute username.



48
49
50
# File 'lib/rake_notifier/slack.rb', line 48

def username
  @username
end

Instance Method Details

#args_to_post(msg) ⇒ Object



50
51
52
53
54
55
56
57
58
59
# File 'lib/rake_notifier/slack.rb', line 50

def args_to_post(msg)
  arg = {
    channel: channel,
    text: msg,
    as_user: false,
  }
  arg[icon_key(icon)] = icon if icon
  arg[:username] = username if username
  arg
end

#ping(msg) ⇒ Object



61
62
63
# File 'lib/rake_notifier/slack.rb', line 61

def ping(msg)
  Breacan.chat_post_message(args_to_post(msg))
end