waimao/shorturl-service

v1.0.2 2018-09-03 04:22 UTC

This package is not auto-updated.

Last update: 2021-02-16 16:47:21 UTC


README

Build Status URL Shortener Service

Latest Stable Version Total Downloads Latest Unstable Version License

This library allows you to shorten a URL using online services such as Google or Bit.ly. Expanding shortened URLs is also possible.

1.Installation

Add the following to your composer.json file :

{
    "require": {
        "waimao/shorturl-service":"dev-master"
    }
}

2. Description

Currently supports the 2 major services:

  • Google URL Shortener (goo.gl/XXXXX)
  • Bitly.com: (bit.ly/XXXXX, j.mp/XXXXX)

3. Supported Services

3.1. Google API

Get an API key at https://developers.google.com/url-shortener/v1/getting_started#APIKey.

<?php

//Create the short url. Optionally pass the $apiKey credentials
$googl = new \Waimao\Service\ShortLink\Google($apiKey);
echo $url = $googl->shorten($longUrl);

//Expand a short URL into the original URL. Optionally pass the $apiKey credentials
$googl = new \Waimao\Service\ShortLink\Google($apiKey);
echo $url = $googl->expand($shortUrl);

//Get all data, including statistics for a shortened URL
$googl = new \Waimao\Service\ShortLink\Google($apiKey);
$array = $googl->stats($shortUrl);

3.2. Bit.ly API

Get an API Key at https://bitly.com/a/oauth_apps.

<?php

//Create the short url.
$bitly = new \Waimao\Service\ShortLink\Bitly($user,$pass);
echo $url = $bitly->shorten($longUrl);

//Expand a short URL into the original URL.
$bitly = new \Waimao\Service\ShortLink\Bitly($user,$pass);
echo $url = $bitly->expand($shortUrl);

Bit.ly implements many analytic features not taken into account in this library. All extra features can be found in the API documentation.

4. Fully tested.

Testing has been done using PHPUnit and Travis-CI. All code has been tested to be compatible from PHP 5.3 up to PHP 5.5 and Facebook's PHP Virtual Machine: HipHop.

5. Author

Nil Portugués Calderó