Uses Google URL shortener API service to shorten/expand given URLs.
gem install goshortener
of if you are using bundler in your project, add the following line to your Gemfile.
gem "goshortener"
go = GoShortener.new(YOUR_API_KEY)
or
go = GoShortener.new
Using Google API keys will increase the usage quota.
short_url = go.shorten "http://github.com/luckydev"
long_url = go.lengthen short_url
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"
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 anywhere in your rails project, you can call GO.shorten or GO.lengthen
Anand ([email protected])