class URLVoid::CLI

Constants

CONFIG_FILE

Default path to the config file

@return [String] Default path to the config file

Public Instance Methods

create_config(file = CONFIG_FILE) click to toggle source
# File lib/rb-urlvoid/cli.rb, line 43
def create_config(file = CONFIG_FILE)
  path = File.expand_path(file)
  if File.exist?(path)
    puts "[!] #{path} is already exists. Please delete it if you want to re-create it."
  else
    h = { api_key: "INSERT YOUR API KEY", identifier: "api1000" }
    YAML.dump h, File.open(path, "w+")
    puts "[*] An empty #{path} has been created. Please edit and fill the correct values."
  end
end
info(host_name) click to toggle source
# File lib/rb-urlvoid/cli.rb, line 13
def info(host_name)
  with_load_config { puts JSON.pretty_generate(Host.info(host_name)) }
end
load_config(file = CONFIG_FILE) click to toggle source

Load a config file

@note Configuration params are set as configatron attributes @param file [String] Path to the config file

# File lib/rb-urlvoid/cli.rb, line 59
def load_config(file = CONFIG_FILE)
  path = File.expand_path(file)
  if File.exist?(path)
    h = YAML.load_file(path)
  elsif ENV["URLVOID_API_KEY"]
    h = { api_key: ENV["URLVOID_API_KEY"], identifier: ENV["URLVOID_IDENTIFIER"] || "api1000" }
  else
    raise URLVoidError, "[!] Missing API key: Create a config file or specify it via ENV variable"
  end
  configatron.configure_from_hash h
end
new_scan(host_name) click to toggle source
# File lib/rb-urlvoid/cli.rb, line 29
def new_scan(host_name)
  with_load_config { puts JSON.pretty_generate(Host.new_scan(host_name)) }
end
rescan(host_name) click to toggle source
# File lib/rb-urlvoid/cli.rb, line 21
def rescan(host_name)
  with_load_config { puts JSON.pretty_generate(Host.rescan(host_name)) }
end
stats() click to toggle source
# File lib/rb-urlvoid/cli.rb, line 35
def stats
  with_load_config { puts "Remained queries: #{Stats.remained_queries}" }
end
with_load_config() { || ... } click to toggle source

Handling a method which needs config parameters

@yield Give a block that pre-loaded a config file

# File lib/rb-urlvoid/cli.rb, line 74
def with_load_config
  load_config
  yield
rescue URLVoidError => e
  puts e
end