yuseferi/google-shortly-php

A PHP library to generate shortened URL through The Google Shortener API

v1.0 2020-01-25 10:38 UTC

This package is not auto-updated.

Last update: 2024-04-29 05:49:30 UTC


README

A PHP5 library to generate shortened URL through The Google URL Shortener API.

Usage

Using an Google API key is highly recommended. To acquire an API key follow the instructions.

Shorten URL

Shorten a long URL using The Google URL Shortener API

try {
    $googShort = new \yuseferi\GoogShortly('YOUR_GOOGLE_API');
    echo $googShort->shorten('http://yuseferi.com');
} catch (\yuseferi\GoogShortlyException $e) {
    printf('Error (%d): %s', $e->getCode(), $e->getMessage());
}

Expand URL

Expand a short URL using The Google URL Shortener API

try {
    $googShort = new \yuseferi\GoogShortly('YOUR_GOOGLE_API');
    echo $googShort->expand('http://goo.gl/KkZ8');
} catch (\yuseferi\GoogShortlyException $e) {
    printf('Error (%d): %s', $e->getCode(), $e->getMessage());
}

Install

Via composer:

$ composer require yuseferi/google-shortly-php

Without composer

Clone the project using git clone https://github.com/yuseferi/google-shortly-php/ and include the source file with require_once("google-shortly-php/src/GoogShortly.php");

Test

First install the dependencies, and after you can run:

GOOGLE_API=YOUR_GOOGLE_API vendor/bin/phpunit

License

Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php