Cutt.ly is a Link Management Platform with all features you need in one place. Shorten, brand, manage and track your links the easy way, this library aims to work around thier API implementation by providing a wrapper arround it.
Please refere to Cutt.ly API Documentation for detailed api use description.
You can install the package via composer:
composer require toneflix-code/cuttly-laravel
Register provider and facade on your config/app.php
file.
'providers' => [
...,
ToneflixCode\Cuttly\CuttlyServiceProvider::class,
]
'aliases' => [
...,
'Cuttly' => ToneflixCode\Cuttly\CuttlyFacade::class,
]
php artisan vendor:publish --provider="ToneflixCode\Cuttly\CuttlyServiceProvider"
To start using this library you are required to configure your API keys in your .env file with these variables
CUTTLY_KEY=your-cutt.ly API key
use ToneflixCode\Cuttly\Cuttly;
// Default
$response = (new Cuttly)->shorten('https://github.com/toneflix/cuttly-laravel');
// With Name
$response = (new Cuttly)->shorten('https://github.com/toneflix/cuttly-laravel', 'cuttly-laravel');
// No Title | Public
$response = (new Cuttly)->shorten('https://github.com/toneflix/cuttly-laravel', 'cuttly-laravel', true, true);
function shorten(
?string $url = null,
?string $name = null,
$noTitle = false,
$public = false
)
{
"status": "7",
"date": "2022-05-22",
"shortLink": "https://cutt.ly/aHKP2Bu",
"title": "cuttly-laravel"
}
use ToneflixCode\Cuttly\Cuttly;
// Path
$response = (new Cuttly)->delete('rHKG1eb');
// Link
$response = (new Cuttly)->delete('https://cutt.ly/rHKG1eb');
use ToneflixCode\Cuttly\Cuttly;
// Path
$response = (new Cuttly)->changeName('rHKG1eb', 'anewname');
// Link
$response = (new Cuttly)->changeName('https://cutt.ly/rHKG1eb', 'anewname');
use ToneflixCode\Cuttly\Cuttly;
// Path
$response = (new Cuttly)->addTag('rHKG1eb', 'atag');
// Link
$response = (new Cuttly)->addTag('https://cutt.ly/rHKG1eb', 'atag');
use ToneflixCode\Cuttly\Cuttly;
// Path
$response = (new Cuttly)->changeUrl('rHKG1eb', 'https://github.com/toneflix-code/cuttly-laravel');
// Link
$response = (new Cuttly)->changeUrl('https://cutt.ly/rHKG1eb', 'https://github.com/toneflix-code/cuttly-laravel');
use ToneflixCode\Cuttly\Cuttly;
// Path
$response = (new Cuttly)->changeTitle('rHKG1eb', 'A new title');
// Link
$response = (new Cuttly)->changeTitle('https://cutt.ly/rHKG1eb', 'A new title');
use ToneflixCode\Cuttly\Cuttly;
// Path
$response = (new Cuttly)->changeTitle('rHKG1eb', 15);
// Link
$response = (new Cuttly)->changeTitle('https://cutt.ly/rHKG1eb', 15);
{
"status": "1"
}
Every request that returns an error code or response from the Cutt.ly API will throw a ToneflixCode\Cuttly\Exceptions\CuttlyException
exception this is done to enable the developer to elegantly handle errors in whichever way or manner they deem most appropriate or fit.
use ToneflixCode\Cuttly\Cuttly;
use ToneflixCode\Cuttly\Exceptions\CuttlyException;
try {
$response = (new Cuttly)->shorten('https://github.com/toneflix/cuttly-laravel');
dd($response);
} catch (CuttlyException $th) {
dd($th->getMessage());
}
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.