├── CONTRIBUTING.md ├── config └── cuttly.php ├── src ├── Facades │ └── Cuttly.php ├── Exceptions │ └── MissingApiKey.php ├── CuttlyApiWrapper.php ├── HttpResponse.php ├── CuttlyServiceProvider.php └── Cuttly.php ├── phpunit.xml ├── .github └── workflows │ └── tests.yml ├── LICENSE.md ├── composer.json └── README.md /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /config/cuttly.php: -------------------------------------------------------------------------------- 1 | 'https://cutt.ly/api/api.php', 5 | 'api_key' => '', 6 | ]; 7 | -------------------------------------------------------------------------------- /src/Facades/Cuttly.php: -------------------------------------------------------------------------------- 1 | httpClient = new Client([ 16 | 'base_uri' => $baseUrl, 17 | ] 18 | ); 19 | } 20 | 21 | public function getHttpClient(): Client 22 | { 23 | return $this->httpClient; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/HttpResponse.php: -------------------------------------------------------------------------------- 1 | response = $response; 14 | } 15 | 16 | public function getBody() 17 | { 18 | return (string) $this->response->getBody(); 19 | } 20 | 21 | public function toObject() 22 | { 23 | $body = (string) $this->response->getBody(); 24 | 25 | return json_decode($body) ?? (object) []; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | ./tests/Unit 10 | 11 | 12 | ./tests/Feature 13 | 14 | 15 | 16 | 17 | ./src 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/CuttlyServiceProvider.php: -------------------------------------------------------------------------------- 1 | app->runningInConsole()) { 15 | $this->publishes([ 16 | __DIR__.'/../config/cuttly.php' => config_path('cuttly.php'), 17 | ], 'config'); 18 | } 19 | } 20 | 21 | public function register() 22 | { 23 | $this->mergeConfigFrom(__DIR__.'/../config/cuttly.php', 'cuttly'); 24 | 25 | $this->app->singleton('cuttly', function (Container $app) { 26 | return new Cuttly($app); 27 | }); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /.github/workflows/tests.yml: -------------------------------------------------------------------------------- 1 | name: PHP Composer 2 | 3 | on: 4 | push: 5 | branches: [ "main" ] 6 | pull_request: 7 | branches: [ "main" ] 8 | 9 | permissions: 10 | contents: read 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v3 19 | 20 | - name: Validate composer.json and composer.lock 21 | run: composer validate --strict 22 | 23 | - name: Cache Composer packages 24 | id: composer-cache 25 | uses: actions/cache@v3 26 | with: 27 | path: vendor 28 | key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} 29 | restore-keys: | 30 | ${{ runner.os }}-php- 31 | 32 | - name: Install dependencies 33 | run: composer install --prefer-dist --no-progress 34 | 35 | # Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit" 36 | # Docs: https://getcomposer.org/doc/articles/scripts.md 37 | 38 | # - name: Run test suite 39 | # run: composer run-script test 40 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023 slvler slvler@proton.me 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "slvler/cuttly", 3 | "description": "Cutt.ly API wrapper for Laravel", 4 | "keywords": [ 5 | "cuttly", 6 | "laravel", 7 | "php" 8 | ], 9 | "homepage": "https://github.com/slvler/laravel-url-shortener", 10 | "license": "MIT", 11 | "type": "library", 12 | "authors": [ 13 | { 14 | "name": "slvler", 15 | "email": "slvler@proton.me" 16 | } 17 | ], 18 | "require": { 19 | "php": "^8.1", 20 | "guzzlehttp/guzzle": "^7.2", 21 | "illuminate/support": "^9.0|^10.0" 22 | }, 23 | "require-dev": { 24 | "friendsofphp/php-cs-fixer": "^3.6", 25 | "orchestra/testbench": "^7.0", 26 | "phpunit/phpunit": "^9.5.8", 27 | "laravel/pint": "^1.18" 28 | }, 29 | "autoload": { 30 | "psr-4": { 31 | "Slvler\\Cuttly\\": "src/" 32 | } 33 | }, 34 | "autoload-dev": { 35 | "psr-4": { 36 | "Slvler\\Cuttly\\Tests\\": "tests/" 37 | } 38 | }, 39 | "scripts": { 40 | "test": "vendor/bin/phpunit tests", 41 | "pint": "vendor/bin/pint", 42 | "post-create-project-cmd": [ 43 | "@php artisan key:generate --ansi" 44 | ] 45 | }, 46 | "extra": { 47 | "laravel": { 48 | "providers": [ 49 | "Slvler\\Cuttly\\CuttlyServiceProvider" 50 | ], 51 | "aliases": { 52 | "Cuttly": "Slvler\\Cuttly\\Facades\\Cuttly" 53 | } 54 | } 55 | }, 56 | "minimum-stability": "stable", 57 | "prefer-stable": true 58 | } 59 | -------------------------------------------------------------------------------- /src/Cuttly.php: -------------------------------------------------------------------------------- 1 | get('cuttly.api_key'); 18 | 19 | if (empty($apiKey) || ! isset($apiKey)) { 20 | throw MissingApiKey::create(); 21 | } 22 | 23 | $baseURL = $app['config']->get('cuttly.base_uri'); 24 | 25 | if (empty($baseURL) || ! isset($baseURL)) { 26 | throw new InvalidArgumentException('Invalid Cuttly API base URL.'); 27 | } 28 | 29 | parent::__construct($baseURL); 30 | 31 | $this->key = $apiKey; 32 | } 33 | 34 | public function short(array $data): string 35 | { 36 | $this->data = $data; 37 | $this->data['key'] = $this->key; 38 | $this->data['short'] = urlencode($data['short']); 39 | $sendData = http_build_query($this->data); 40 | 41 | $response = $this->getHttpClient()->request('GET', '?'.$sendData); 42 | $value = new HttpResponse($response); 43 | 44 | return $value->getBody(); 45 | } 46 | 47 | public function edit(array $data): string 48 | { 49 | $this->data = $data; 50 | $this->data['key'] = $this->key; 51 | $this->data['edit'] = $data['edit']; 52 | $sendData = http_build_query($this->data); 53 | 54 | $response = $this->getHttpClient()->request('GET', '?'.$sendData); 55 | $value = new HttpResponse($response); 56 | 57 | return $value->getBody(); 58 | } 59 | 60 | public function stats(array $data): string 61 | { 62 | $this->data = $data; 63 | $this->data['key'] = $this->key; 64 | $this->data['stats'] = $data['stats']; 65 | $sendData = http_build_query($this->data); 66 | 67 | $response = $this->getHttpClient()->request('GET', '?'.$sendData); 68 | $value = new HttpResponse($response); 69 | 70 | return $value->getBody(); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Cuttly Service 2 | 3 | [![tests](https://github.com/slvler/laravel-url-shortener/actions/workflows/tests.yml/badge.svg)](https://github.com/slvler/laravel-url-shortener) 4 | [![Latest Stable Version](https://img.shields.io/packagist/v/slvler/cuttly.svg)](https://packagist.org/packages/slvler/cuttly) 5 | [![License](https://poser.pugx.org/slvler/balldontlie-laravel/license)](https://packagist.org/packages/slvler/balldontlie-laravel) 6 | [![Total Downloads](https://poser.pugx.org/slvler/cuttly/downloads)](https://packagist.org/packages/slvler/cuttly) 7 | 8 | This package provides a convenient wrapper to the [Cuttly API](https://cutt.ly/api-documentation/regular-api) for Laravel applications. 9 | 10 | ## Requirements 11 | - PHP 8.1 12 | - Laravel 9.x | 10.x 13 | 14 | ## Installation 15 | To install this package tou can use composer: 16 | ```bash 17 | composer require slvler/cuttly 18 | ``` 19 | 20 | ## Usage 21 | #### Find player 22 | ```php 23 | $data['short'] = 'google.com'; 24 | 25 | Cuttly::short($data); 26 | ``` 27 | URL Shortener: 28 | ```json 29 | { 30 | "url": { 31 | "status": 7, 32 | "fullLink": "http://google.com", 33 | "date": "2023-08-07", 34 | "shortLink": "https://cutt.ly/ewdVijlY", 35 | "title": "Google" 36 | } 37 | } 38 | ``` 39 | 40 | #### Edit Url 41 | ```php 42 | $data['edit'] = 'cutt.ly/LwdCoBmo'; 43 | 44 | Cuttly::edit($data); 45 | ``` 46 | Edit URL: 47 | ```json 48 | { 49 | "url": { 50 | "status": 1 51 | } 52 | } 53 | ``` 54 | 55 | #### Find games 56 | ```php 57 | $data['stats'] = 'cutt.ly/ewdVijlY'; 58 | 59 | Cuttly::stats($data); 60 | ``` 61 | URL Stats: 62 | ```json 63 | { 64 | "stats": { 65 | "status": 1, 66 | "clicks": 0, 67 | "date": "2023-08-07", 68 | "title": "Google", 69 | "fullLink": "http://google.com", 70 | "shortLink": "https://cutt.ly/ewdVijlY", 71 | "facebook": 0, 72 | "twitter": 0, 73 | "pinterest": 0, 74 | "instagram": 0, 75 | "googlePlus": 0, 76 | "linkedin": 0, 77 | "rest": 0, 78 | "devices": {}, 79 | "refs": {}, 80 | "bots": "Insufficient subscription level" 81 | } 82 | } 83 | ``` 84 | 85 | ## Testing 86 | ```bash 87 | composer test 88 | ``` 89 | 90 | ## Credits 91 | - [slvler](https://github.com/slvler) 92 | 93 | ## License 94 | The MIT License (MIT). Please see [License File](https://github.com/slvler/balldontlie-service/blob/main/LICENSE.md) for more information. 95 | 96 | ## Contributing 97 | You're very welcome to contribute. 98 | Please see [CONTRIBUTING](https://github.com/slvler/balldontlie-service/blob/main/CONTRIBUTING.md) for details. 99 | --------------------------------------------------------------------------------