pdmfc / short-url-package-php-8-support
URL缩短器
dev-master
2024-02-15 18:42 UTC
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-09-16 20:01:26 UTC
README
A Http client to interact with the Short Url api service offered by PDM
目录
安装
Composer
- 在您的
composer.json
文件中,在"repositories"
部分添加以下内容
{ "type": "vcs", "url": "https://github.com/pdmfc/short-url-package-php-8-support.git" }
- 需要此包
composer require pdmfc/short-url-package-php-8-support
配置
- 发布配置文件
php artisan vendor:publish --tag="short_config"
- 将以下环境变量添加到您的
.env
文件中,并使用当前应用程序所需的值定义
SHORT_URL_API_ID= SHORT_URL_API_TOKEN= SHORT_URL_API_BASE_URL=
API
- 如果请求头不正确,响应将是以下内容
{ "message": "Access is not allowed" }
getUrl(string $shortUrl)
用法
use Pdmfc\Shorturl\Client\ShortUrlClient; $client = new ShortUrlClient(); $response = $client->getUrl('Nc');
成功响应
{ "Id": 2, "shortUrl": "http://teste.ll/Nc", "qr_code": "<?xml version=\"1.0\" encodin..." }
失败响应
{ "message": "shortUrls Nc not found" }
createUrl(array $params)
用法
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', ]);
成功响应
{ "Id": 26, "shortUrl": "http://s.pdm.pt/1C", "qrCode": "<?xml version=\"1.0\" encoding..." }
失败响应
{ "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', ]);
成功响应
{ "Id": 26, "shortUrl": "http://teste.ll/1C", "qrCode": "<?xml version=\"1.0\" encoding..." }
失败响应
{ "message": "Is not possible update the short url" }
deleteUrl(string $shortUrl)
use Pdmfc\Shorturl\Client\ShortUrlClient; $client = new ShortUrlClient(); $response = $client->deleteUrl('Nc');
成功响应
{ "message": "Code Nc was deleted with success" }
失败响应
{ "message": "Is not possible delete a short url" }
{ "message": "shortUrls Nc not found" }
参数
测试
要运行测试套件,首先必须复制phpunit.xml.dist
cp phpunit.xml.dist phpunit.xml
确保在您的phpunit配置文件中取消注释ENV变量,并添加必要的值
<env name="SHORT_URL_API_BASE_URL" value=""/> <env name="SHORT_URL_API_ID" value=""/> <env name="SHORT_URL_API_TOKEN" value=""/>
现在您可以运行测试套件
vendor/bin/phpunit
⚠️小心!
不要直接将您的phpunit配置值添加到
phpunit.xml.dist
文件中,因为这个文件将位于版本控制仓库中!