Class: Argosnap::Notifications
- Inherits:
-
Object
- Object
- Argosnap::Notifications
- Defined in:
- lib/argosnap/notifications.rb
Overview
This class handles the available notifications
Instance Method Summary collapse
-
#notify ⇒ Object
When tarsnap balance is bellow threshold notify me Method is chosen based on threshold.
- #osx_check_and_notify ⇒ Object
- #send_mail ⇒ Object
-
#send_osx_notification ⇒ Object
Manually send notification to osx notifications (desktop).
- #send_pushover_notification ⇒ Object
Instance Method Details
#notify ⇒ Object
When tarsnap balance is bellow threshold notify me Method is chosen based on threshold
9 10 11 12 13 14 15 |
# File 'lib/argosnap/notifications.rb', line 9 def notify if config.data[:threshold] >= Fetch.new.balance send_mail send_pushover send_osx_notification end end |
#osx_check_and_notify ⇒ Object
17 18 19 20 21 |
# File 'lib/argosnap/notifications.rb', line 17 def osx_check_and_notify if config.data[:threshold] >= Fetch.new.balance send_osx_notification end end |
#send_mail ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/argosnap/notifications.rb', line 23 def send_mail if config.data[:notifications_email] if config.gem_available?('mail') require 'mail' require 'socket' require_relative File.("../notifications/mailer", __FILE__) Mailer.new(config.data, config.logger).send_mail else config.log_and_abort("Please install 'mail' gem by executing: '$ gem install mail'.") end end end |
#send_osx_notification ⇒ Object
Manually send notification to osx notifications (desktop)
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/argosnap/notifications.rb', line 49 def send_osx_notification if config.data[:notifications_osx] if Gem::Platform.local.os == 'darwin' # load 'terminal-notifier' if config.gem_available?('terminal-notifier') require 'terminal-notifier' require_relative File.("../notifications/osxnotifications", __FILE__) = "Your picoUSD amount is: #{Fetch.new.balance}" title = 'argosnap' subtitle = 'running out of picoUSD!' OSXnotify.send(, title, subtitle) else config.log_and_abort("You need to install 'terminal-notifier' gem!") end else config.log_and_abort("OSX notifications are available only under OSX > 10.8.x") end end end |
#send_pushover_notification ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/argosnap/notifications.rb', line 36 def send_pushover_notification if config.data[:notifications_pushover] require "net/https" require_relative File.("../notifications/pushover", __FILE__) key = config.data[:pushover][:key] token = config.data[:pushover][:token] amount = Fetch.new.balance = "Your current tarsnap amount is #{amount} picoUSD!" Pushover.send(token, key, , config.logger, amount) end end |