Convert Shorten URL (, tinyurl,, and many more) to Full URL in Ruby

Posted: October 13th, 2009 | Author: | Filed under: IT Related | Tags: , , , , | 4 Comments »

You might worry to visit directly to a shorten URL because who knows it may contain some malicious script/code

I’ve found a solution “Python: Convert those TinyURL (, tinyurl, to full URLS” in but the code is in Python.

Here is how you can perform the conversion in Ruby

require 'net/http'
def ConvertToFull(tinyurl)
   url = URI.parse(tinyurl)
   host, port =, url.port if && url.port
   req =
   res = Net::HTTP.start(host, port) {|http|  http.request(req) }
   return res.header['location']
puts ConvertToFull('') #here is how you can call the function. Thank you Captain Obvious!

**UPDATED on 19/10/2009**

I’ve work on a more complete version which can determine Shorten URL or Full URL and return the full URL for the shorten URL.. email for for the code 😉