class ExceptionNotifier::PushoverNotifier

Attributes

api_token[RW]
default_options[RW]
logger[RW]
url[RW]

Public Class Methods

new(options) click to toggle source
# File lib/exception_notifier/pushover_notifier.rb, line 9
def initialize(options)
  @api_token = options.delete(:api_token)
  @url = options.delete(:url)
  @logger = options.delete(:logger)
  @default_options = options
end

Public Instance Methods

call(exception, options={}) click to toggle source
# File lib/exception_notifier/pushover_notifier.rb, line 16
def call(exception, options={})
  return if !is_active?
  server = ::Socket.gethostname
  options = options.merge(@default_options)
  message = "#{server}: A new exception occured: #{exception.message} on #{exception.backtrace.first}"
  options[:users].each do |user_token|
    response = send(user_token, message)
    if response.code == 200 && response.parsed_response[:status]
      @logger.error("Can't send notification to user with token #{user_token}") if defined?(@logger)
    end
  end
end

Private Instance Methods

is_active?() click to toggle source
# File lib/exception_notifier/pushover_notifier.rb, line 35
def is_active?
  !@api_token.empty? && !@url.empty?
end
send(user_token, message) click to toggle source
# File lib/exception_notifier/pushover_notifier.rb, line 30
def send(user_token, message)
  options = { :body => { :token => @api_token, :user => user_token, :message => message } }
  ::HTTParty.post(@url, options)
end