bybrand/shortener-url

URL Shortener to many providers used internally in Bybrand.

v0.0.8 2022-01-05 22:56 UTC

This package is auto-updated.

Last update: 2024-04-06 03:42:24 UTC


README

A dominant URL shortener enabled to many providers. The idea with this extension is your changing between providers without changing lines of the code in the application.

This code is used in production to make short links on email signatures from the Bybrand.

  • Providers supported:: Bitly, and Rebrandly.

Installation

composer require bybrand/shortenerURL

Usage

First, you need to get the API settings from to your provider. Usually, the domain, token, and workspace, and the next is set in class.

Take a example:

use Bybrand\ShortenerURL\Provider;
use Bybrand\ShortenerURL\Shorten;
use Bybrand\ShortenerURL\Exception\ShortenFailed;

$provider = new Provider\Bitly([
    'group'  => '',
    'domain' => '',
    'token'  => '',
]);

$shorten = new Shorten($provider);
$shorten->destination('long url');

// If failed return Exception;
$shorten->create();

// Get all returned params.
$result = $shorten->toArray();

Extra methods

Too, you can use auxiliary methods how:

// Return a short url.
$shorten->getLink();

// Return the ID from the register in the provider.
$shorten->getId();

Testing

bash
$ ./vendor/bin/phpunit

or individual method test, by group.

bash
$ ./vendor/bin/phpunit --group=Bitly

License

The MIT License (MIT). Please see License File for more information.