class Updown::CLI
Constants
- CONFIG_FILE
Public Instance Methods
add(url, period=60)
click to toggle source
# File lib/updown/cli.rb, line 40 def add(url, period=60) configure_api_key check = Updown::Check.create url, period: period system "open https://updown.io/#{check.token}" rescue Updown::Error => e puts "Error: #{e}" end
configure(api_key)
click to toggle source
# File lib/updown/cli.rb, line 50 def configure(api_key) config = read_config config['api_key'] = api_key write_config config end
open(token)
click to toggle source
# File lib/updown/cli.rb, line 34 def open(token) configure_api_key system "open https://updown.io/#{token}" end
status()
click to toggle source
# File lib/updown/cli.rb, line 9 def status configure_api_key Updown::Check.all.each do |check| status = if !check.enabled ' ---- '.colorize(:light_black) elsif check.down '[DOWN]'.colorize(:light_red) else ' [up] '.colorize(:light_green) end url = if check.ssl_valid == true check.url.sub('https', 'https'.colorize(:light_green)) elsif check.ssl_valid == false check.url.sub('https', 'https'.colorize(:light_red)) else check.url end puts "#{status} #{check.token.colorize(:light_magenta)} #{"—".colorize(:light_black)} #{url}" end rescue Updown::Error => e puts "Error: #{e}" end
Private Instance Methods
configure_api_key()
click to toggle source
# File lib/updown/cli.rb, line 73 def configure_api_key if api_key = read_config['api_key'] Updown.configuration.api_key = api_key else abort "no api key configured!\nrun `updown configure API_KEY`" end end
read_config()
click to toggle source
# File lib/updown/cli.rb, line 61 def read_config if File.exist? CONFIG_FILE YAML.load File.read(CONFIG_FILE) else {} end end
write_config(config)
click to toggle source
# File lib/updown/cli.rb, line 69 def write_config(config) File.write CONFIG_FILE, config.to_yaml end