class URI::HTTP

Public Instance Methods

error?() click to toggle source
# File lib/socializer/scraper/extensions.rb, line 72
def error?
  return :unknown unless url?
  puts "Testing URL: #{self}"
  req = Net::HTTP.new(host, port)
  req.use_ssl = is_a?(URI::HTTPS)
  res = req.request_head(path.empty? ? "/" : path)
  if res.kind_of?(Net::HTTPRedirection)
    URI.parse(res["location"]).absolute(host, scheme).error?
  else
    case
    when res.code == "401" || res.code == "407" then :unauthorized
    when res.code == "403" then :forbidden
    when res.code == "404" then :not_found
    when res.code[0] == "4" then :client_error
    when res.code == "503" then :temporary_server_error
    when res.code[0] == "5" then :server_error
    end
  end
rescue ::Errno::ENOENT, ::SocketError
  :no_such_server
end