class Backup::Notifier::Pushover

Attributes

device[RW]

The user’s device identifier to sent the message directly to, rather than all of the user’s devices

priority[RW]

The priority of the notification

title[RW]

The message title

token[RW]

The API Application Token

user[RW]

The API User Token

Public Class Methods

new(model, &block) click to toggle source
Calls superclass method Backup::Notifier::Base::new
# File lib/backup/notifier/pushover.rb, line 27
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/pushover.rb, line 51
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/pushover.rb, line 55
def send_message(message)
  uri = "https://api.pushover.net/1/messages.json"
  data = { user: user, token: token, message: message }
  [:device, :title, :priority].each do |param|
    val = send(param)
    data.merge!(param => val) if val
  end
  options = {
    headers: { "Content-Type" => "application/x-www-form-urlencoded" },
    body: URI.encode_www_form(data)
  }
  options[:expects] = 200 # raise error if unsuccessful
  Excon.post(uri, options)
end