Class: CollinsNotify::HipchatAdapter

Inherits:
Notifier
  • Object
show all
Defined in:
lib/collins_notify/adapter/hipchat.rb

Defined Under Namespace

Modules: HipchatStatus

Instance Method Summary collapse

Methods inherited from Notifier

adapter_name, adapters, get_adapter, #initialize, mimetypes, register_name, require_config, required_config_keys, requires_config?, #supports_html?, supports_mimetype, #supports_text?

Constructor Details

This class inherits a constructor from CollinsNotify::Notifier

Instance Method Details

#configure!Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/collins_notify/adapter/hipchat.rb', line 19

def configure!
  @client = HipChat::Client.new api_token
  cfg_colors = hipchat_options.fetch(:colors, {})
  @colors = {
    :success => cfg_colors.fetch(:success, HipchatStatus::SUCCESS),
    :warning => cfg_colors.fetch(:warning, HipchatStatus::WARNING),
    :error   => cfg_colors.fetch(:error, HipchatStatus::ERROR),
    :status  => cfg_colors.fetch(:status, HipchatStatus::STATUS),
    :random  => cfg_colors.fetch(:random, HipchatStatus::RANDOM)
  }
  logger.info "Configured Hipchat client"
end

#notify!(message_obj = OpenStruct.new, to = nil) ⇒ Object

Bindings available

room_name - hipchat room
username - user message being sent as
at - If we are at'ing a person


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/collins_notify/adapter/hipchat.rb', line 36

def notify! message_obj = OpenStruct.new, to = nil
  room_name = get_room message_obj
  username = get_from_username message_obj
  if room_name.nil? then
    raise CollinsNotify::CollinsNotifyException.new "No obj.room or hipchat.room specified"
  end
  message = get_message_body(binding).strip.gsub(/[\n\r]/, ' ')
  message = "@#{to} #{message}" unless to.nil?
  logger.info "Notifying #{room_name} from #{username} with message #{message}"
  if config.test? then
    logger.info "Not sending hipchat message in test mode"
    return true
  end
  opts = client_options(message_obj)
  logger.debug "Using hipchat options #{opts.inspect}"
  client[room_name].send(username, message, client_options(message_obj))
end