Class: URI::HTTP

Inherits:
Object show all
Defined in:
lib/socializer/scraper/extensions.rb

Instance Method Summary collapse

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# 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