lib/tasks/default.rake
# Request uri, reply true if fetchable. Follow redirects 'limit' times.
# See: https://docs.ruby-lang.org/en/2.0.0/Net/HTTP.html
# rubocop:disable Metrics/MethodLength
Request uri, reply true if fetchable. Follow redirects 'limit' times.
Request uri reply true if fetchable . Follow redirects ' limit ' times .
def fetchable?(uri_str, limit = 10)
  return false if limit <= 0
  response = Net::HTTP.get_response(URI.parse(uri_str))
  case response
  when Net::HTTPSuccess then
    return true
  when Net::HTTPRedirection then
    location = response['location']
    warn "    redirected to <#{location}>"
    return fetchable?(location, limit - 1)
  else
    return false
  end
end
def fetchable? ( uri_str , limit = 10 ) return false if limit <= 0 response = Net :: HTTP . get_response ( URI . parse ( uri_str ) ) case response when Net :: HTTPSuccess then return true when Net :: HTTPRedirection then location = response [ 'location' ] warn "    redirected to <#{location}>" return fetchable? ( location , limit - 1 ) else return false end end
Request uri, reply true if fetchable.
Request uri reply true if fetchable .
# Use GET, not HEAD. Some websites will say a page doesn't exist when given # a HEAD request, yet will redirect correctly on a GET request. Ugh. # Recurse, because redirection might be to a different site
uri_str
<not_specific>
limit
<not_specific>