class Backup::Notifier::Campfire

Attributes

api_token[RW]

Campfire api authentication token

room_id[RW]

Campfire account's room id

subdomain[RW]

Campfire account's subdomain

Public Class Methods

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

Private Instance Methods

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/campfire.rb, line 43
def notify!(status)
  send_message(message.call(model, :status => status_data_for(status)))
end
send_message(message) click to toggle source
# File lib/backup/notifier/campfire.rb, line 47
def send_message(message)
  uri = "https://#{ subdomain }.campfirenow.com/room/#{ room_id }/speak.json"
  options = {
    :headers  => { 'Content-Type' => 'application/json' },
    :body     => JSON.dump(
      { :message => { :body => message, :type => 'Textmessage' } }
    )
  }
  options.merge!(:user => api_token, :password => 'x') # Basic Auth
  options.merge!(:expects => 201) # raise error if unsuccessful
  Excon.post(uri, options)
end