Yii 1.1: bitly-url-shortener

Bit.ly URL Shortener
6 followers

This extensions allows you to perform REST callbacks to the {@link bit.ly} service and perform several operations such as:

  • Shorten a url
  • Expand a short url into it's long form
  • Validate api login and key
  • Get the number of clicks for a short URL
  • Check if a domain uses the Bitly.Pro

Resources

Documentation

Requirements

  • Yii 1.0 or above

Description:

This extensions allows you to perform REST callbacks to the {@link bit.ly} service and perform several operations such as:

  • Shorten a url
  • Expand a short url into it's long form
  • Validate api login and key
  • Get the number of clicks for a short URL
  • Check if a domain uses the Bitly.Pro

Usage:

Each operation has it's own method listed below. You can refer to the method description to see a full description of it's usage, examples and the output example, as well as see all the available parameters you can pass to each method.

This class also supports caching, So if you perform a callback it will cache the result to reduce the number of calls the extensions needs to perform. It will cache the data based on all postParams, format and callback type, So no conflicts and duplicated values will be saved/retrieved.

Installation:

  • Extract the release file under protected/extensions

In order to activate the extension and use it's methods you will need to add the following component code to your application configuration.

'bitly' => array(
        'class' => 'application.extensions.bitly.VGBitly',
        'login' => 'xxxxx', // login name
        'apiKey' => 'xxxxxx', // apikey 
        'format' => 'xml', // default format of the response this can be either xml, json (some callbacks support txt as well)
        ),

You can also pass specify parameters such as:

  • 'cacheID' => the type of cache component to use, Defaults to 'cache', Set false to disable caching.
  • 'cachingDuration' => number of seconds to save the records in cache.
  • 'throwExceptions' => wheterhe to throw exceptions or not. You can always retrieve the last error message and code happened by accessing the {@see getErrorMessage} and {@see getErrorNumber}.

Full Documentation:

  • {@link http://code.google.com/p/bitly-api/wiki/ApiDocumentation}

Shorten URL

Yii::app()->bitly->shorten('http://www.betaworks.com')->getResponseData();

Output:

Array
(
  [status_code] => 200
  [status_txt] => OK
  [data] => Array
      (
          [url] => http://bit.ly/9PCy42
          [hash] => 9PCy42
          [global_hash] => 25iRBL
          [long_url] => http://www.betaworks.com
          [new_hash] => 0
      )
)

Expand URL callback

Yii::app()->bitly->expand('http://bit.ly/1RmnUT')->getResponseData();

Output:

Array
(
  [status_code] => 200
  [status_txt] => OK
  [data] => Array
      (
          [entry] => Array
              (
                  [short_url] => http://bit.ly/1RmnUT
                  [long_url] => http://google.com
                  [user_hash] => 1RmnUT
                  [global_hash] => 1RmnUT
              )
      )
)

Validate callback

Yii::app()->bitly->validate('loginName', 'APIKEY')->getResponseData();

Output:

Array
(
 [status_code] => 200
  [status_txt] => OK
  [data] => Array
      (
          [valid] => 1
      )
)

# Clicks callback

Yii::app()->bitly->clicks('http://bit.ly/1RmnUT')->getResponseData();

Output:

Array
(
 [status_code] => 200
 [data] => Array
      (
          [clicks] => Array
              (
                  [short_url] => http://bit.ly/1RmnUT
                  [global_hash] => 1RmnUT
                  [user_clicks] => 3508
                  [user_hash] => 1RmnUT
                  [global_clicks] => 3508
              )
      )
  [status_txt] => OK
)

Bitly.Pro callback

Yii::app()->bitly->bitly_pro_domain('nyti.ms')->getResponseData();

Output:

Array
(
 [status_code] => 200
  [data] => Array
      (
          [domain] => nyti.ms
          [bitly_pro_domain] => 1
      )
  [status_txt] => OK
)

Change Log

April 12, 2010

  • Initial release.

Total 2 comments

#7160 report it
hoplayann at 2012/02/29 03:52am
Easy to use.

Simple and easy to use.

I am now using it for our project Wiklab.nl - Moeite met kiezen? (Make up your mind web application) http://www.wiklab.nl.

I configured our Bitly account as well to be able to use our domain for the URL shortening. It works great.

thanks Yann

#535 report it
Shiki at 2010/04/30 10:09pm
Excellent!

Nice work man. Very easy to use.

Leave a comment

Please to leave your comment.

Create extension
Downloads
  • Yii Version: 1.1
  • License: New BSD License
  • Developed by: Vince.
  • Category: Web Service
  • Votes: +8
  • Downloaded: 1,602 times
  • Created on: Apr 12, 2010
  • Last updated: Apr 12, 2010