class Argosnap::Notifications
This class handles the available notifications
Public Instance Methods
notify()
click to toggle source
When tarsnap balance is bellow threshold notify me Method is chosen based on threshold
# 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()
click to toggle source
# 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()
click to toggle source
# 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.expand_path("../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()
click to toggle source
Manually send notification to osx notifications (desktop)
# 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.expand_path("../notifications/osxnotifications", __FILE__) message = "Your picoUSD amount is: #{Fetch.new.balance}" title = 'argosnap' subtitle = 'running out of picoUSD!' OSXnotify.send(message, 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()
click to toggle source
# File lib/argosnap/notifications.rb, line 36 def send_pushover_notification if config.data[:notifications_pushover] require "net/https" require_relative File.expand_path("../notifications/pushover", __FILE__) key = config.data[:pushover][:key] token = config.data[:pushover][:token] amount = Fetch.new.balance message = "Your current tarsnap amount is #{amount} picoUSD!" Pushover.send(token, key, message, config.logger, amount) end end
Private Instance Methods
config()
click to toggle source
load configuration files
# File lib/argosnap/notifications.rb, line 73 def config Configuration.new end