class RakeNotifier::Slack::Client

Attributes

channel[RW]
icon[RW]
token[RW]
username[RW]

Public Class Methods

new(token, channel: ' click to toggle source
# 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

Public Instance Methods

args_to_post(msg) click to toggle source
# 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) click to toggle source
# File lib/rake_notifier/slack.rb, line 61
def ping(msg)
  Breacan.chat_post_message(args_to_post(msg))
end

Private Instance Methods

icon_key(icon_info) click to toggle source
# File lib/rake_notifier/slack.rb, line 66
def icon_key(icon_info)
  case icon_info
  when /^https?:\/\//
    :icon_url
  when /^:.+:$/
    :icon_emoji
  else
    raise "May be invalid icon format: #{icon_info}"
  end
end