Skip to content

Instantly share code, notes, and snippets.

@kovacshuni
Created July 22, 2013 08:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kovacshuni/6052151 to your computer and use it in GitHub Desktop.
Save kovacshuni/6052151 to your computer and use it in GitHub Desktop.
Sanity check of video.ft.com
require 'net/http'
def fetch(uri_str, limit = 10)
raise ArgumentError, 'too many HTTP redirects' if limit == 0
response = Net::HTTP.get_response(URI(uri_str))
case response
when Net::HTTPSuccess then
response.body()[/<span class="video\-length">\s*(\d+:\d+ min)\s*<\/span>/]
when Net::HTTPRedirection then
location = response['location']
warn "redirected to #{location}"
fetch(location, limit - 1)
else
response.value
end
end
print fetch('http://video.ft.com')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment