urlreversi: Revert your shortened URLs

  • Authors: null
0 vote
Dependency:
compile ":urlreversi:1.0"

 Documentation

Summary

Installation

grails install-plugin urlreversi

Description

Introduction

What it does

This plugin reverses a shortened url - for example http://tinyurl.com/5d4 or http://ow.ly/ZDrQ

This plugin really does nothing special. It just detects to which original url the given shrinked url points to and returns this url. Given the simple protocol the typical url shrinking facilities follow (http redirect) it should work with almost all existing shortening services. This plugin provides a service to use from within grails and a convenient tag for direct usage in the web layer. See further documentation below.

Use case example

A typical use case for this plugin can be in an grails app that mashes up with twitter posts. Regardless of what shrinking service is used in any tweet - this plugin should be able to resolve the original link on demand and transparently. This can be useful in community environments to improve user convenience or to do some stats about your "community links".

Similar tools

There are dozens of similar technologies out there. For example users can install the longurlplease Firefox extension from http://www.longurlplease.com to have only original urls while surfing. A more similar technology is the service that is hosted at http://longurl.org. With this plugin such a service can be realized really easy in a grails app.

Ideas for using this plugin within your grails app

You might want to use this plugin in your app: If you have some shortened links that shall be demystified. If you want to detect link doublettes from different shortening services.

How to use

  • How to use the tag(lib)
    • As a text in your html page
Usage is straight forward:
<div><urlreversi:revert2Long url='http://bit.ly/1t6DhR'/></div>
will result in the text : <div>http://www.spiegel.de</div>
    • As a link in your html page
If you want to use the long url directly as a link target you can write:
<a href="${urlreversi.revert2Long(url:'http://bit.ly/1t6DhR')}">${urlreversi.revert2Long(url:'http://bit.ly/1t6DhR')}</a>
Which will of course result in this html: <a href="http://www.spiegel.de">http://www.spiegel.de</a>
  • How to use the service
Using the service from a grails artifact is a matter of convention as always:
def urlReverterService
in your controller class is enough to make use of the Service.
  • Combined example: AJAX
Controller Code:
def urlReverterService

def index = { }

def ajax = { def longUrl = urlReverterService.urlReversi(params.url) render "Long Url: ${longUrl.toString()}" }

GSP Code:

<h1>Ajax call: <g:remoteLink action="ajax" params="[url:'http://bit.ly/1t6DhR']" update="upd">Ajax Link</g:remoteLink></h1>
                            <p id="upd">I am the ajax element that gets updated</p>
  • Differences between tag and service
The service doesn't catch exceptions while the tag does: The tag returns the input url param in case of an exception or an empty string. The is true even if the given url is invalid.

Simple usage example