<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Xanda's Blog !~! &#187; ow.ly bit.ly</title>
	<atom:link href="http://blog.xanda.org/tag/ow-ly-bit-ly/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.xanda.org</link>
	<description>Human Knowledge Belongs To The World.</description>
	<lastBuildDate>Tue, 13 Jul 2010 10:10:58 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Convert Shorten URL (bit.ly, tinyurl, ow.ly, and many more) to Full URL in Ruby</title>
		<link>http://blog.xanda.org/2009/10/13/convert-shorten-url-bit-ly-tinyurl-ow-ly-to-full-url-in-ruby/</link>
		<comments>http://blog.xanda.org/2009/10/13/convert-shorten-url-bit-ly-tinyurl-ow-ly-to-full-url-in-ruby/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 03:26:57 +0000</pubDate>
		<dc:creator>xanda</dc:creator>
				<category><![CDATA[IT Related]]></category>
		<category><![CDATA[convert]]></category>
		<category><![CDATA[ow.ly bit.ly]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[shorten url]]></category>
		<category><![CDATA[tinyurl]]></category>

		<guid isPermaLink="false">http://blog.xanda.org/?p=963</guid>
		<description><![CDATA[You might worry to visit directly to a shorten URL because who knows it may contain some malicious script/code
I&#8217;ve found a solution &#8220;Python: Convert those TinyURL (bit.ly, tinyurl, ow.ly) to full URLS&#8221; in stackoverflow.com but the code is in Python.
Here is how you can perform the conversion in Ruby

#!/usr/bin/ruby
&#160;
require 'net/http'
&#160;
def ConvertToFull&#40;tinyurl&#41;
   url = [...]]]></description>
			<content:encoded><![CDATA[<p>You might worry to visit directly to a shorten URL because who knows it may contain some malicious script/code</p>
<p>I&#8217;ve found a solution &#8220;<a href="http://stackoverflow.com/questions/748324/python-convert-those-tinyurl-bit-ly-tinyurl-ow-ly-to-full-urls/1552895" target="_blank">Python: Convert those TinyURL (bit.ly, tinyurl, ow.ly) to full URLS</a>&#8221; in stackoverflow.com but the code is in Python.</p>
<p>Here is how you can perform the conversion in Ruby</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#!/usr/bin/ruby</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'net/http'</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">def</span> ConvertToFull<span style="color:#006600; font-weight:bold;">&#40;</span>tinyurl<span style="color:#006600; font-weight:bold;">&#41;</span>
   url = <span style="color:#CC00FF; font-weight:bold;">URI</span>.<span style="color:#9900CC;">parse</span><span style="color:#006600; font-weight:bold;">&#40;</span>tinyurl<span style="color:#006600; font-weight:bold;">&#41;</span>
   host, port = url.<span style="color:#9900CC;">host</span>, url.<span style="color:#9900CC;">port</span> <span style="color:#9966CC; font-weight:bold;">if</span> url.<span style="color:#9900CC;">host</span> <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> url.<span style="color:#9900CC;">port</span>
   req = <span style="color:#6666ff; font-weight:bold;">Net::HTTP::Get</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>url.<span style="color:#9900CC;">path</span><span style="color:#006600; font-weight:bold;">&#41;</span>
   res = <span style="color:#6666ff; font-weight:bold;">Net::HTTP</span>.<span style="color:#9900CC;">start</span><span style="color:#006600; font-weight:bold;">&#40;</span>host, port<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>http<span style="color:#006600; font-weight:bold;">|</span>  http.<span style="color:#9900CC;">request</span><span style="color:#006600; font-weight:bold;">&#40;</span>req<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
   <span style="color:#0000FF; font-weight:bold;">return</span> res.<span style="color:#9900CC;">header</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'location'</span><span style="color:#006600; font-weight:bold;">&#93;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">puts</span> ConvertToFull<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'http://bit.ly/rgCbf'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#008000; font-style:italic;">#here is how you can call the function. Thank you Captain Obvious!</span></pre></div></div>

<p>**UPDATED on 19/10/2009**</p>
<p>I&#8217;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 <img src='http://blog.xanda.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.xanda.org/2009/10/13/convert-shorten-url-bit-ly-tinyurl-ow-ly-to-full-url-in-ruby/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
