lib/url_status.rb in url-status-1.0.2 vs lib/url_status.rb in url-status-1.0.5

- old
+ new

@@ -12,22 +12,37 @@ module UrlStatus class App def main + # we want to disable the text coloring if we are printing to a + # file, or on a platform (like windows) that likely doesn't support + # the colors + String.disable_colorization = !$stdout.isatty + + success = true url_list.each do |url| begin response = get_response(url) + success = success && response.ok? 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 + puts text rescue StandardError => e + success = false puts "[#{"---".red}] #{url} (#{e.to_s.red})" end + + $stdout.flush end + + # unless *every* request completed properly, return an error code + #, then we can do something else, like send an email + exit(false) unless success end def url_list opts = Trollop::options do version "url-status (c) 2016 @reednj (reednj@gmail.com)" @@ -52,9 +67,10 @@ url = 'http://' + url unless url.start_with? 'http' begin return RestClient.get(url) rescue RestClient::ExceptionWithResponse => e + raise e if e.response.nil? return e.response end end end