Class: EMN::Notifier::Pushover

Inherits:
Object
  • Object
show all
Defined in:
lib/emn/notifier/pushover.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, debug = false) ⇒ Pushover

Returns a new instance of Pushover.



8
9
10
11
12
# File 'lib/emn/notifier/pushover.rb', line 8

def initialize(config, debug=false)
  @config = config
  @logger = config.logger
  @debug = debug
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



6
7
8
# File 'lib/emn/notifier/pushover.rb', line 6

def config
  @config
end

#debugObject (readonly)

Returns the value of attribute debug.



6
7
8
# File 'lib/emn/notifier/pushover.rb', line 6

def debug
  @debug
end

#loggerObject (readonly)

Returns the value of attribute logger.



6
7
8
# File 'lib/emn/notifier/pushover.rb', line 6

def logger
  @logger
end

Instance Method Details

#apiObject



14
15
16
17
18
# File 'lib/emn/notifier/pushover.rb', line 14

def api
  ::Pushover.user = config[:pushover][:user_token]
  ::Pushover.token = config[:pushover][:app_token]
  ::Pushover
end

#publish(message, subject) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/emn/notifier/pushover.rb', line 20

def publish(message, subject)
  if debug
    logger.debug("Would have published the message: ")
    puts message
    return true
  else
    responce = api.notification(:html => 1, :title => subject, :message => message)

    if responce.code == 200
      return true
    else
      STDERR.puts("Failed to notify pushover: %s" % responce.inspect)
      return false
    end
  end
end