toneflix-code / cuttly-laravel
A Laravel API wrapper for Cutt.ly API.
Installs: 8 647
Dependents: 0
Suggesters: 0
Security: 0
Stars: 6
Watchers: 0
Forks: 5
Open Issues: 0
Requires
- php: ^8.0|^8.1
- guzzlehttp/guzzle: ^7.0
- illuminate/support: ^8.0|^9.0|^10.0
Requires (Dev)
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.0
README
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.
Requirements
Installation
You can install the package via composer:
composer require toneflix-code/cuttly-laravel
Service Provider & Facade (Optional)
Register provider and facade on your config/app.php
file.
'providers' => [ ..., ToneflixCode\Cuttly\CuttlyServiceProvider::class, ] 'aliases' => [ ..., 'Cuttly' => ToneflixCode\Cuttly\CuttlyFacade::class, ]
Configuration (Optional)
php artisan vendor:publish --provider="ToneflixCode\Cuttly\CuttlyServiceProvider"
API Keys
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
Usage
Shorten Url
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);
Parameters
function shorten( ?string $url = null, ?string $name = null, $noTitle = false, $public = false )
Response
{ "status": "7", "date": "2022-05-22", "shortLink": "https://cutt.ly/aHKP2Bu", "title": "cuttly-laravel" }
Delete a shortened link.
use ToneflixCode\Cuttly\Cuttly; // Path $response = (new Cuttly())->delete('rHKG1eb'); // Link $response = (new Cuttly())->delete('https://cutt.ly/rHKG1eb');
Change the name of a link
use ToneflixCode\Cuttly\Cuttly; // Path $response = (new Cuttly())->changeName('rHKG1eb', 'anewname'); // Link $response = (new Cuttly())->changeName('https://cutt.ly/rHKG1eb', 'anewname');
Add a tag to a link
use ToneflixCode\Cuttly\Cuttly; // Path $response = (new Cuttly())->addTag('rHKG1eb', 'atag'); // Link $response = (new Cuttly())->addTag('https://cutt.ly/rHKG1eb', 'atag');
Change the source url of the shortened link.
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');
Change the title of the shortened link.
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');
Set a unique stat count for a short link
use ToneflixCode\Cuttly\Cuttly; // Path $response = (new Cuttly())->changeTitle('rHKG1eb', 15); // Link $response = (new Cuttly())->changeTitle('https://cutt.ly/rHKG1eb', 15);
Response
{ "status": "1" }
Error Handling
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()); }
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email code@toneflix.com.ng instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.