pdmfc/short-url-package-php-8-support 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pdmfc/short-url-package-php-8-support

Composer 安装命令:

composer require pdmfc/short-url-package-php-8-support

包简介

Url Shortener

README 文档

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:
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

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!

统计信息

  • 总下载量: 5.07k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-02-18