Skip to content

Instantly share code, notes, and snippets.

@bonpixel
Created January 22, 2015 22:06
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 bonpixel/bb9333701318ed3c3a51 to your computer and use it in GitHub Desktop.
Save bonpixel/bb9333701318ed3c3a51 to your computer and use it in GitHub Desktop.
A little challenge...
#!/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