, , , , , ,

Does it looks odd?? You have so many websites which allows you to minimise your url like tinyurl, bit.ly etc etc list is endless, but what if you get some API of those to work with so you can minimise the url with your rails application or as a stand-alone ruby program??

Bit.ly comes with that. It provides ruby programmers an interface by which they can minimise the url. Wondering How? see it in action..

I am creating a simple ruby program here, if you want you can use it in your application…

All you need is json and open-uri to finish it off.

require ‘open-uri’
require ‘json’

apikey=’YOUR API KEY’
url = “http://api.bit.ly/shorten?version=#{version}&longUrl=#{code}&login=#{user}&apiKey=#{apikey}”
buffer = open(url, “UserAgent” => “Ruby-ExpandLink”).read
result = JSON.parse(buffer)
shorturl = result[‘results’]['shortUrl']

That is it. Run this program in console/command prompt, where ever you want to see the output.

Post your queries, suggestions