Skip to content

Instantly share code, notes, and snippets.

@ramigb
Forked from valchonedelchev/gist:a48da9b6050983d56625
Last active August 29, 2015 14:14
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 ramigb/51fe1df3d0eb685abab1 to your computer and use it in GitHub Desktop.
Save ramigb/51fe1df3d0eb685abab1 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'net/http'
require 'json'
def http_get(url)
puts "http_get: #{url}"
return Net::HTTP.get(URI(url))
end
def handle_http(response, url)
if response['You should try JSON']
return url.sub 'challenge?id', 'challenge.json?id'
elsif response =~ /^{"follow":"http:\/\/[\w\.\/]+\?id=\d+"}$/
return JSON.parse(response).fetch('follow').sub 'challenge?id', 'challenge.json?id'
else
puts response
end
return nil
end
def play_with(url)
begin
response = http_get(url)
url = handle_http(response, url)
end while not url.nil?
end
play_with(ARGV.shift)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment