Shorten URL'S using bit.ly API in RailsPosted by: Prachi | 22 Oct 2013 | Comments
In this blog we are going to create shorten URL's in rails application using Bit.ly API in ruby step by step.
For this you required to have bitly login and api_keys.
Create your account on
https://bitly.com. Get your login and api_key for your account.
Check settings -> Advanced -> showlegacykey.
Steps for creating shorten urls in Ruby using bit.ly API
- Ruby has a
gem bitlyfor bit.ly API.
gem install bitly
If you want to configure bitly through an initializer. Add code to
Bitly.configure do |config| config.api_version = 3 config.login = "Bitly_Username" config.api_key = "API_KEY" end
To get the client, use Bitly.client:
client = Bitly.client
You can then use that client to shorten or expand urls :
url = client.shorten('http://cuberoot.in/') url.long_url #=> "http://cuberoot.in/" url.short_url #=> "http://bit.ly/1eTMCoC"
And it is done!