Skip to content

Instantly share code, notes, and snippets.

@iwagaki
Created February 18, 2015 17:21
Show Gist options
  • Save iwagaki/2b5e612d1c93b6d88d51 to your computer and use it in GitHub Desktop.
Save iwagaki/2b5e612d1c93b6d88d51 to your computer and use it in GitHub Desktop.
Expand a shorten URI
require 'net/http'
require 'uri'
require 'pp'
def expandShortenURI(s)
uri = URI(s)
Net::HTTP.start(uri.host, uri.port) {|http|
response = http.head(uri.request_uri)
case response
when Net::HTTPRedirection
expandShortenURI(response['location'])
else
return s
end
}
end
ARGV.each {|s|
puts expandShortenURI(s)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment