Class: Updown::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/updown/cli.rb

Instance Method Summary collapse

Instance Method Details

#add(url, period = 60) ⇒ Object



40
41
42
43
44
45
46
47
# 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) ⇒ Object



50
51
52
53
54
55
# 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) ⇒ Object



34
35
36
37
# File 'lib/updown/cli.rb', line 34

def open(token)
  configure_api_key
  system "open https://updown.io/#{token}"
end

#statusObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 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