- Tinyurl - This one converts regular URL's to TinyURL's and vice-versa. However, I examined the source code and discovered that to do this, the author's personal web server, logankoester.com, is called. This concerned me because: What if this service goes down? My program would stop working.
- ShortURL - This one converts original URL's into many "short URL" formats such as TinyURL, RubyURL, and mooURL. Unfortunately there is no way to reverse any of these URL's. Since I needed the reverse functionality, I had to pass this one by.
require 'rubygems'
require 'net/http'
def reverse_tinyurl(url)
url_parts = url.split('.com/')
preview_url = "http://preview.tinyurl.com/#{url_parts[1]}"
response = Net::HTTP.get_response(URI.parse(preview_url))
original_url = response.body.scan(/redirecturl" href="(.*)">/)[0][0]
end
puts reverse_tinyurl('http://tinyurl.com/6nzb8u')
Running this program would print out the URL to my blog, http://kweiner.blogspot.com.
By the way, I also found TinyURL Callback API in JavaScript, but I wanted a server-side solution. Additionally, I found the TinyURLReverser from Yahoo Pipes, but I wasn't clear on how this worked. I need to examine this one a little further.