class Backup::Notifier::Hipchat
Attributes
The Hipchat
API version Either ‘v1’ or ‘v2’ (default is ‘v1’)
The background color of an error message. One of :yellow, :red, :green, :purple, or :random. (default: yellow)
Who the notification should appear from
Notify users in the room
The rooms that should be notified
Custom server URL
The background color of a success message. One of :yellow, :red, :green, :purple, or :random. (default: yellow)
The Hipchat
API token
The background color of a warning message. One of :yellow, :red, :green, :purple, or :random. (default: yellow)
Public Class Methods
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
# 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 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
# File lib/backup/notifier/hipchat.rb, line 97 def rooms_to_notify Array(rooms_notified).map { |r| r.split(",").map(&:strip) }.flatten end
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
# File lib/backup/notifier/hipchat.rb, line 107 def status_color_for(status) { success: success_color, warning: warning_color, failure: failure_color }[status] end
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