bitly-url-shortener Bit.ly URL Shortener

  1. Documentation
  2. Change Log

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:
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.
7 0
5 followers
2 205 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: Web Service
Tags:
Developed by: Vince.
Created on: Apr 12, 2010
Last updated: 8 years ago

Downloads

show all