Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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