Created
January 22, 2015 22:06
-
-
Save bonpixel/bb9333701318ed3c3a51 to your computer and use it in GitHub Desktop.
A little challenge...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'net/http' | |
require 'json' | |
def http_get_request(url) | |
puts "http_get: #{url}" | |
response = Net::HTTP.get(URI(url)) | |
if response['You should try JSON'] | |
http_get_request(url.sub 'challenge?id', 'challenge.json?id') | |
elsif response =~ /id=\d+/ | |
http_get_request(JSON.parse(response).fetch('follow').sub 'challenge?id', 'challenge.json?id') | |
else | |
puts response | |
end | |
return nil | |
end | |
http_get_request(ARGV.shift) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment