pdmfc / short-url-package-php-8-support
Url Shortener
Installs: 2 519
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=7.3
- guzzlehttp/guzzle: ^7.4
Requires (Dev)
- orchestra/testbench: ^6.7
- phpunit/phpunit: ^9.0
This package is not auto-updated.
Last update: 2024-12-23 21:10:41 UTC
README
A Http client to interact with the Short Url api service offered by PDM
Table of contents
Installation
Composer:
- In your
composer.json
add the following to the"repositories"
section:
{ "type": "vcs", "url": "https://github.com/pdmfc/short-url-package-php-8-support.git" }
- Require the package:
composer require pdmfc/short-url-package-php-8-support
Configuration
- Publish the config file:
php artisan vendor:publish --tag="short_config"
- Add the following environment variables to your
.env
file with the necessary values defined for your current application:
SHORT_URL_API_ID= SHORT_URL_API_TOKEN= SHORT_URL_API_BASE_URL=
Api
- If the request headers are incorrect, the response will be the following:
{ "message": "Access is not allowed" }
getUrl(string $shortUrl)
Usage:
use Pdmfc\Shorturl\Client\ShortUrlClient; $client = new ShortUrlClient(); $response = $client->getUrl('Nc');
Successful response:
{ "Id": 2, "shortUrl": "http://teste.ll/Nc", "qr_code": "<?xml version=\"1.0\" encodin..." }
Unsuccessful response:
{ "message": "shortUrls Nc not found" }
createUrl(array $params)
Usage:
use Pdmfc\Shorturl\Client\ShortUrlClient; $client = new ShortUrlClient(); $response = $client->createUrl([ 'domainUrl' => 's.pdm.pt', 'originalUrl' => 'www.original-url.com/long', 'liveTime' => 0, 'active' => true, 'shortUrl' => '1C', ]);
Successful response:
{ "Id": 26, "shortUrl": "http://s.pdm.pt/1C", "qrCode": "<?xml version=\"1.0\" encoding..." }
Unsuccessful response:
{ "message": "Is not possible create a short url" }
changeUrl(string $shortUrl, array $params)
use Pdmfc\Shorturl\Client\ShortUrlClient; $client = new ShortUrlClient(); $response = $client->updateUrl('Nc', [ 'originalUrl' => 'www.original-url-changed.com', ]);
Successful response:
{ "Id": 26, "shortUrl": "http://teste.ll/1C", "qrCode": "<?xml version=\"1.0\" encoding..." }
Unsuccessful response:
{ "message": "Is not possible update the short url" }
deleteUrl(string $shortUrl)
use Pdmfc\Shorturl\Client\ShortUrlClient; $client = new ShortUrlClient(); $response = $client->deleteUrl('Nc');
Successful response:
{ "message": "Code Nc was deleted with success" }
Unsuccessful responses:
{ "message": "Is not possible delete a short url" }
{ "message": "shortUrls Nc not found" }
Params:
Tests
To run the test suite, first you must copy the phpunit.xml.dist
:
cp phpunit.xml.dist phpunit.xml
Make sure to uncomment the ENV variables on your phpunit configuration file and add the necessary values:
<env name="SHORT_URL_API_BASE_URL" value=""/> <env name="SHORT_URL_API_ID" value=""/> <env name="SHORT_URL_API_TOKEN" value=""/>
Now you can run the test suite:
vendor/bin/phpunit
⚠️ Be careful!
Do not add your phpunit config values directly into the
phpunit.xml.dist
file since this file will be in the version control repository!