Class: UrlStatus::App
- Inherits:
-
Object
- Object
- UrlStatus::App
- Defined in:
- lib/url_status.rb
Instance Method Summary collapse
Instance Method Details
#get_response(url) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/url_status.rb', line 51 def get_response(url) url = 'http://' + url unless url.start_with? 'http' begin return RestClient.get(url) rescue RestClient::ExceptionWithResponse => e return e.response end end |
#main ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/url_status.rb', line 16 def main url_list.each do |url| begin response = get_response(url) code = response.ok? ? response.code.to_s.green : response.code.to_s.red final_url = response.request.url text = "[#{code}] #{final_url}" text += " (requested #{url})".yellow unless final_url.include?(url) puts text rescue StandardError => e puts "[#{"---".red}] #{url} (#{e.to_s.red})" end end end |
#url_list ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/url_status.rb', line 31 def url_list opts = Trollop:: do version "url-status (c) 2016 @reednj ([email protected])" opt :config, "YAML config file containing array of urls", :type => :string end if ARGV.empty? begin data_file_name = opts[:config] || "#{ENV['HOME']}/sites.yaml" YAML.load_file(data_file_name) rescue => e puts "Could not open '#{data_file_name}' (#{e})" exit(false) end else ARGV.clone end end |