Easily use the API of the url shortener Rebrandly.
This packages requires PHP 7.4 or higher.
This package can be used in any PHP project or with any framework.
You can install the package via composer:
composer require vdhicts/rebrandly-api-client
This package tries to offer you a complete implementation of the Rebrandly API. Some endpoints are restricted to certain plans Rebrandly offer (like scripts and tags).
All endpoints can be retrieved from the Rebrandly
class. This class needs the Client
.
use Vdhicts\Rebrandly;
// Initialize the client and the Rebrandly instance
$client = new Rebrandly\Client('API_KEY');
$rebrandly = new Rebrandly\Rebrandly($client);
// Access the endpoints
$linksEndpoint = $rebrandly->links();
For example, to retrieve all links:
$links = $rebrandly->links()->list();
Some endpoints of the Rebrandly API offer some filtering. Those filters can be set in the Options
class. For example,
to order your links by clicks:
$links = $rebrandly->links()->list(new Options(['orderBy' => 'clicks', 'orderDir' => 'asc']));
This client will always return the related models. When creating a new resource, the object is provided to the create
method. For example, to create a link:
$link = new Rebrandly\Models\Link();
$link->setDestination('https://time-tracker.vdhicts.nl');
$link->setSlashtag('time-tracker');
$link->setDomain($domain);
$rebrandly->links()->create($link);
To create a link for you custom domain, you need to specify the domain in the Link
model:
$domain = new Rebrandly\Models\Domain();
$domain->setFullName('yourdomain.tld');
$link->setDomain($domain);
$rebrandly->links()->create($link);
When something goes wrong, the client will throw a RebrandlyException
. If you want to catch exceptions from this
package, that's the one you should catch. Error responses from the API also result in the RebrandlyException
.
For Laravel users, I would suggest adding the api key to your .env
file:
REBRANDLY_API_KEY="your-key"
And create a config file for Rebrandly or add this to your project's config file. Then initialize the client with the config value:
$client = new Rebrandly\Client(config('rebrandly.api_key'));
Unit tests are available in the tests
folder. Run via phpunit:
vendor\bin\phpunit
By default a coverage report will be generated in the build/coverage
folder.
Any contribution is welcome, but it should meet the PSR-2 standard and please create one pull request per feature. In exchange you will be credited as contributor on this page.
If you discover any security related issues in this or other packages of Vdhicts, please email [email protected] instead of using the issue tracker.
This package is open-source software licensed under the MIT license.
This package isn't an official package from Rebrandly, so they probably won't offer support for it. If you encounter a problem with this client, please open an issue on GitHub.
Vdhicts is the name of my personal company. Vdhicts develops and implements IT solutions for businesses and educational institutions.