A Http client to interact with the Short Url api service offered by PDM
- In your
composer.jsonadd 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- Publish the config file:
php artisan vendor:publish --tag="short_config"- Add the following environment variables to your
.envfile with the necessary values defined for your current application:
SHORT_URL_API_ID=
SHORT_URL_API_TOKEN=
SHORT_URL_API_BASE_URL=- If the request headers are incorrect, the response will be the following:
{
"message": "Access is not allowed"
}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"
}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"
}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"
}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"
}| Param | Type | Required | Default | Description | Example |
|---|---|---|---|---|---|
domainUrl |
string | ➖ | ➖ | Short url domain | http://teste.com |
originalUrl |
string | ✔️ | ➖ | Url where you will be redirected | www.original-url.com/long |
liveTime |
integer | ➖ | 0 |
expiration time | 60 |
active |
boolean | ➖ | true |
Define if the link is active | false |
shortUrl |
string | ➖ | ➖ | Uri to be generated. If none provided, it will automatically generated | a12 |
To run the test suite, first you must copy the phpunit.xml.dist:
cp phpunit.xml.dist phpunit.xmlMake 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/phpunitDo not add your phpunit config values directly into the
phpunit.xml.distfile since this file will be in the version control repository!