HTTPレスポンスがリダイレクトであればLocationヘッダを読んでいます。
短縮URLがネストしている場合にも対応すべく、再帰的に処理しています。
require 'net/http'
require 'uri'
def expand_url(url)
begin
response = Net::HTTP.get_response(URI.parse(url))
rescue
return url
end
case response
when Net::HTTPRedirection
expand_url(response['location'])
else
url
end
end
puts expand_url("http://bit.ly/ICFCzV")