Minimise URL in Ruby

Does it looks odd?? You have so many websites which allows you to minimise your url like tinyurl, 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?? 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 = “{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


6 thoughts on “Minimise URL in Ruby

  1. Mike Sutton December 6, 2009 / 12:22 PM

    Thanks for that post, helped me immensely, but the last line should be:
    shorturl = result[‘results’][‘shortUrl’]

  2. Venkatesh July 19, 2012 / 9:12 AM


    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.

    • Puneet Pandey August 23, 2012 / 9:38 AM


      Really sorry man, no idea on how to do that with PHP!

  3. Rodrigo December 8, 2013 / 10:21 AM

    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.

  4. Kareem August 28, 2014 / 5:33 PM

    Everything is very open with a precise explanation of the issues. It was really informative. Your website is extremely helpful. Thank you for sharing!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s