Goshortener

GoShortener shortens urls to http://goo.gl style short urls.

View the Project on GitHub luckydev/goshortener

GoShortener.

Its a small ruby gem that uses Google URL shortener API service to shorten/expand given URLs.

$ gem install goshortener

Initialize

go = GoShortener.new(YOUR_API_KEY)

Shorten URLs

short_url = go.shorten "http://github.com/luckydev"

Lengthen URLs

long_url = go.lengthen short_url

Example usage in IRB

ruby-1.9.2-p136 :001 > require "goshortener"
 => true 
ruby-1.9.2-p136 :002 > go = GoShortener.new("yourapikeyfromgoogle")
 => #<GoShortener:0x93b35e0 @base_url="https://www.googleapis.com/urlshortener/v1/url", @api_key="yourapikeyfromgoogle"> 
ruby-1.9.2-p136 :003 > go.shorten "http://github.com/luckydev"
 => "http://goo.gl/TCZHi" 
ruby-1.9.2-p136 :004 > go.lengthen "http://goo.gl/TCZHi"
 => "http://github.com/luckydev"

Example usage in rails apps

If you are using goshortener in a rails project, you can put the following lines in an initializer file. For example, in config/initializers/goshortener.rb

GO = GoShortener.new(YOUR_API_KEY)

And then use GO constant throughout your app to shorten/expand URLs

Author

Anand (@luckydev on Github)