class Juden::Notifier
Public Class Methods
run()
click to toggle source
# File lib/juden.rb, line 11 def run new.run end
Public Instance Methods
run()
click to toggle source
# File lib/juden.rb, line 16 def run loop do if send_reminder? post_to_webhook else puts %(Don't have to send remainder) end sleep config.interval_seconds end end
Private Instance Methods
battery()
click to toggle source
@return [Battery]
# File lib/juden.rb, line 35 def battery @battery ||= Battery.new end
config()
click to toggle source
@return [Config]
# File lib/juden.rb, line 30 def config Config.instance end
create_lock()
click to toggle source
# File lib/juden.rb, line 44 def create_lock system("mkdir /tmp/juden_lock_#{Date.today.iso8601}") end
curl_command()
click to toggle source
# File lib/juden.rb, line 62 def curl_command %(curl -i -X POST \ -H "Content-Type:application/json" \ -d \ '{ "value1" : "#{config.device_name}", "value2" : "#{battery.state}, #{battery.percentage}", "value3" : "" }' \ #{config.webhook_url}) end
delete_lock()
click to toggle source
# File lib/juden.rb, line 48 def delete_lock system("rm -d /tmp/juden_lock_#{Date.today.iso8601}") end
post_to_webhook()
click to toggle source
# File lib/juden.rb, line 52 def post_to_webhook # puts curl_command.to_s if system(curl_command) puts "\nsuccess" else puts "\nfailed" delete_lock end end
send_reminder?()
click to toggle source
@return [Boolean]
# File lib/juden.rb, line 40 def send_reminder? battery.discharging? && battery.low_battery? && create_lock end