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.



36
37
38
39
40
41
# File 'lib/rake_notifier/slack.rb', line 36

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.



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

def channel
  @channel
end

#iconObject

Returns the value of attribute icon.



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

def icon
  @icon
end

#tokenObject

Returns the value of attribute token.



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

def token
  @token
end

#usernameObject

Returns the value of attribute username.



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

def username
  @username
end

Instance Method Details

#args_to_post(msg) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/rake_notifier/slack.rb', line 44

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



55
56
57
# File 'lib/rake_notifier/slack.rb', line 55

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