Project

url_shorty

0.0
No commit activity in last 3 years
No release in over 3 years
By using this gem we can able to shorten a URL and also able to expand the Short URLs.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.15
~> 10.0
~> 3.2

Runtime

~> 0.15.6
~> 2.0.2
 Project Readme

UrlShorty

UrlShorty is ruby gem to simplify URL shortening using Google URL shortener. You can refer the gem Documentation here

Using this you can,

  • Shorten a Long URL
  • Expand a Shortened URL
  • Get Analytics details of a Shortened URL.

Installation

Add this line to your application's Gemfile:

gem 'url_shorty'

And then execute:

$ bundle

Or install it yourself as:

$ gem install url_shorty

Usage

Get Google URL Shortener API Key:

Refer Google URL Shortener Getting Started page to create a API key for google url Shortener service.

Setting up API key:

	UrlShorty.api_key("<Your_API_KEY>")

Shorten URL:

	UrlShorty.shorten_url("<Long_URL>")

Example:

	UrlShorty.shorten_url("https://github.com/Balaji-Ramasubramanian/UrlShorty")
	#=>"https://goo.gl/XojnVs" 

Expand URL:

	UrlShorty.expand_url("<Shorten_URL>")

Example:

	UrlShorty.expand_url("https://goo.gl/XojnVs")
	#=> "https://github.com/Balaji-Ramasubramanian/UrlShorty"

Get Analytics:

To get summary of the analytics for the shortened URL,

	UrlShorty.get_analytics("<Shorten_URL>")

Basics Info:

  • kind
  • id
  • longUrl
  • status
  • created

Example:

	url_analytics_data = UrlShorty.get_analytics("https://goo.gl/XojnVs")
	url_analytics_data.kind  	
	#=> "urlshortener#url"
	url_analytics_data.id 		
	#=> "https://goo.gl/XojnVs"
	url_analytics_data.longUrl 	
	#=> "https://github.com/Balaji-Ramasubramanian/UrlShorty"
	url_analytics_data.created 	
	#=> "2017-11-26T07:26:32.556+00:00"

Usage Info:

Available Scopes:

  • allTime
  • month
  • week
  • twoHours

Available information:

  • shortUrlClicks
  • longUrlClicks
  • referers
  • countries
  • browsers
  • platforms

Example

	url_analytics_data = UrlShorty.get_analytics("https://goo.gl/SeRtHU")
	url_analytics_data.analytics.allTime.shortUrlClicks 			
	#=> "88"
	url_analytics_data.analytics.allTime.referers[0].count 		
	#=>"73"
	url_analytics_data.analytics.month.browsers[1].id 			
	#=>"Chrome"
	url_analytics_data.analytics.twoHours.platforms[2].id 		
	#=>"Macintosh"

License

The gem is available as open source under the terms of the MIT License.