Coding Tidbits

Cube Root is an exclusive Ruby on Rails Consultancy. Find our programming ramblings here.

Shorten URL'S using API in Rails

In this blog we are going to create shorten URL’s in rails application using API in ruby step by step.

  1. For this you required to have bitly login and api_keys.

  2. Create your account on . Get your login and api_key for your account.

    Check settings -> Advanced -> show_legacy_key.

  3. Steps for creating shorten urls in Ruby using API

gem install bitly

If you want to configure bitly through an initializer. Add code to config/initializers/bitly.rb

Bitly.configure do |config|
  config.api_version = 3
  config.login = "Bitly_Username"
  config.api_key = "API_KEY"

To get the client, use Bitly.client:

client = Bitly.client

You can then use that client to shorten or expand urls :

 url = client.shorten('')
 #=> ""

 #=> ""

And it is done!