class Backup::Notifier::Hipchat

Attributes

api_version[RW]

The Hipchat API version Either ‘v1’ or ‘v2’ (default is ‘v1’)

failure_color[RW]

The background color of an error message. One of :yellow, :red, :green, :purple, or :random. (default: yellow)

from[RW]

Who the notification should appear from

notify_users[RW]

Notify users in the room

rooms_notified[RW]

The rooms that should be notified

server_url[RW]

Custom server URL

success_color[RW]

The background color of a success message. One of :yellow, :red, :green, :purple, or :random. (default: yellow)

token[RW]

The Hipchat API token

warning_color[RW]

The background color of a warning message. One of :yellow, :red, :green, :purple, or :random. (default: yellow)

Public Class Methods

new(model, &block) click to toggle source
Calls superclass method Backup::Notifier::Base::new
# File lib/backup/notifier/hipchat.rb, line 46
def initialize(model, &block)
  super
  instance_eval(&block) if block_given?

  @notify_users   ||= false
  @rooms_notified ||= []
  @success_color  ||= "yellow"
  @warning_color  ||= "yellow"
  @failure_color  ||= "yellow"
  @api_version    ||= "v1"
end

Private Instance Methods

client_options() click to toggle source
# File lib/backup/notifier/hipchat.rb, line 83
def client_options
  { api_version: @api_version }.tap do |h|
    h[:server_url] = server_url if server_url
  end
end
notify!(status) click to toggle source

Notify the user of the backup operation results.

‘status` indicates one of the following:

‘:success` : The backup completed successfully. : Notification will be sent if `on_success` is `true`.

‘:warning` : The backup completed successfully, but warnings were logged. : Notification will be sent if `on_warning` or `on_success` is `true`.

‘:failure` : The backup operation failed. : Notification will be sent if `on_warning` or `on_success` is `true`.

# File lib/backup/notifier/hipchat.rb, line 77
def notify!(status)
  status_data = status_data_for(status)
  msg = message.call(model, status: status_data)
  send_message(msg, status_data[:color])
end
rooms_to_notify() click to toggle source
# File lib/backup/notifier/hipchat.rb, line 97
def rooms_to_notify
  Array(rooms_notified).map { |r| r.split(",").map(&:strip) }.flatten
end
send_message(msg, color) click to toggle source

Hipchat::Client will raise an error if unsuccessful.

# File lib/backup/notifier/hipchat.rb, line 90
def send_message(msg, color)
  client = HipChat::Client.new(token, client_options)
  rooms_to_notify.each do |room|
    client[room].send(from, msg, color: color, notify: notify_users)
  end
end
status_color_for(status) click to toggle source
# File lib/backup/notifier/hipchat.rb, line 107
def status_color_for(status)
  {
    success: success_color,
    warning: warning_color,
    failure: failure_color
  }[status]
end
status_data_for(status) click to toggle source
Calls superclass method Backup::Notifier::Base#status_data_for
# File lib/backup/notifier/hipchat.rb, line 101
def status_data_for(status)
  data = super(status)
  data[:color] = status_color_for(status)
  data
end