Skip to content

Instantly share code, notes, and snippets.

@atnan
Created April 13, 2009 14:20
Show Gist options
  • Save atnan/94463 to your computer and use it in GitHub Desktop.
Save atnan/94463 to your computer and use it in GitHub Desktop.
require "uri"
require "net/http"
class ShortUrl
def self.expand(url)
uri = URI.parse(url)
response = Net::HTTP.start(uri.host, uri.port) do |request|
request.head(uri.path)
end
response["Location"]
rescue
url
end
end
%w( tinyurl.com is.gd bit.ly ).each do |provider|
puts ShortUrl.expand("http://#{provider}/abc")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment