bramin/cuttlylaravel

Interact with the Cutt.ly API via Laravel's Http helper and facade


README

Latest Version on Packagist GitHub Code Style Action Status Total Downloads

Cutt.ly is a URL shortening service. This package uses Laravel's Http helper to interact with that service to create, update and delete shortened links.

Installation

You can install the package via composer:

composer require bramin/cuttlylaravel

You can publish the config file with:

php artisan vendor:publish --tag="cuttly-laravel-config"

This is the contents of the published config file:

return [
    'key' => '',
    'user_domain' => '0',
    'no_title' => '1',
    'public' => '1',
];

Make sure to set the key to your key from Cutt.ly

Usage

Include the Cuttly Facade

use Bramin\CuttlyPHP\Facades\Cuttly;

Test the api status

$success = Cuttly::ping();

Create a new link:

$details = Cuttly::create('https://google.com', '', false, true, true);

Parameters:

  • short: The URL to be shortened (required)
  • name: The first and only uri segment after the domain name. Passing null or an empty array will generate a random and unique string.
  • userDomain: whether it should use the custom domain name instead of cutt.ly. Defaults to false.
  • noTitle: Disables the title lookup to improve speed. Defaults to true.
  • public: Whether the link is public or private. Defaults to true.

Link analytics:

$success = Cuttly::getAnalytics('https://cutt.ly/abcd', '2022-04-01', '2022-05-01');

Parameters:

  • short: The URL to be shortened (required)
  • dateFrom: Sets the start date of the period to return data for. Format: YYYY-MM-DD, e.g. 2021-03-02
  • dateTo: Sets the end date of the period to return data for. Format: YYYY-MM-DD, e.g. 2021-03-02

Add a tag to a link:

$success = Cuttly::addTag('https://cutt.ly/abcd', 'tagname');

Update the source of a link:

$success = Cuttly::updateSource('https://cutt.ly/abcd', 'http://www.google.com');

Update the title of a link:

$success = Cuttly::updateTitle('https://cutt.ly/abcd', 'Google Home Page');

Delete a link:

$success = Cuttly::delete('https://cutt.ly/abcd');

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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