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’
code=’https://www.google.com/accounts/ServiceLogin?service=mail&passive=true&rm=false&continue=http%3A%2F%2Fmail.google.com%2Fmail%2F%3Fui%3Dhtml%26zy%3Dl&bsv=zpwhtygjntrz&scc=1<mpl=default<mplcache=2&hl=en’
user=’YOUR USERNAME’
apikey=’YOUR API KEY’
version=’2.0.1′
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
Puneet
Thanks for that post, helped me immensely, but the last line should be:
shorturl = result[‘results’][‘shortUrl’]
Hi,
Thanks for your post. Can you please explain how to use Yourls in ruby. Actually its in PHP. Do you have any idea on this.
@Venkatesh,
Really sorry man, no idea on how to do that with PHP!
Attractive section of content. I just stumbled upon your weblog and in accession capital to assert that I get in fact enjoyed account your blog posts. Any way I’ll be subscribing to your augment and even I achievement you access consistently fast.
Everything is very open with a precise explanation of the issues. It was really informative. Your website is extremely helpful. Thank you for sharing!