aftermarketpl/api
Composer 安装命令:
composer require aftermarketpl/api
包简介
Client for the AfterMarket.pl public API.
关键字:
README 文档
README
This library allows you to issue calls to the AfterMarket.pl public API from PHP.
Quick start
Install the library using composer.
composer require aftermarketpl/api
Create the API client object, providing your API key. Click here to obtain your API key.
$client = new Aftermarketpl\Api\Client(array( "key" => "... your public key ...", "secret" => "... your secret key ...", ));
Call an API function and obtain a result. Click here to see the list of API functions.
try { $result = $client->send("/domain/check", array( "names" => array("check-1.pl", "check-2.pl"), )); print_r($result); } catch(Aftermarketpl\Api\Exception\Exception $exception) { print_r($exception->getResponse()); }
Use Guzzle-style asynchronous call:
$promise = $client->sendAsync("/domain/check", array( "names" => array("check-1.pl", "check-2.pl"), )); $promise->then( function($result) { print_r($result); }, function($exception) { print_r($exception->$getResponse(); } ); $promise->wait();
Installation
You can install the API library in two ways.
- The easiest way is to use
composer:
composer require aftermarketpl/api
- If you are not using
composer, you can install the library manually. In order to do that, download and unpack the files (only thelibdirectory is necessary), and include the library's autoloader in your PHP files:
require "... path to the lib folder.../autoload.php";
In the latter case, you don't need the Guzzle library if you don't plan on using asynchronous requests
- the library will switch to plain CURL in that case.
API keys
To connect to the API, you need an API key. Click here to obtain your API key.
You can have more than one API key. Each API key has a set of operations which can be performed using that key. You can also limit the key usage to a specific set of IP addresses.
After creating an API key, you can modify its permissions, revoke or disable it on the Aftermarket.pl website.
Reference
Creating the class
To create a new client class, use:
$client = new Aftermarketpl\Api\Client($options);
The $options variable is an array, which can contain the following values:
key- The public key used to connect to the API.secret- The secret key used to connect to the API.debug- If set totrue, the CURL calls to the API will be performed with the CURL_VERBOSE flag, allowing you to debug connection errors.url- Alternative URL to use when connecting to the API. You don't normally need to use this option.
The parameters key and secret are necessary for making calls to the API.
However, you do not need to specify them at class creation time - see the section Modifying the class below.
Making API calls
$result = $client->send($command, $parameters);
The function send() is used to send an API command to the server.
You need to specify two parameters:
$command- The name of the command, for example"/domain/check". Click here to see the list of API functions.$parameters- Array containing the command parameters. The actual contents depend on the command. Can be omitted of the command does not take any parameters.
The return value is the data structure returned by the API command. Its contents also depend on the actual command used - see the API reference for details on what is being returned by each command.
Asynchronous calls
$promise = $client->sendAsync($command, $parameters); $promise->then(function($response) { ... }, function($exception) { ... }); $response = $promise->wait();
The function sendAsync() uses the Guzzle library to send an API call asynchronously.
The input parameters are the same as with the send() function,
but the returned value is a promise which resolves to the data structure returned from the API command.
Refer to Guzzle documentation for information on how to use promises with asynchronous calls.
Exceptions
If something goes wrong, a subclass of Aftermarketpl\Api\Exception\Exception is thrown.
This class extends the standard Exception class with the method getResponse(),
which returns the contents of the response received from the server.
This value is, of course, only valid when the actual call to the server has been made;
if the error occurred before that, the value is null.
Modifying the class
You can modify the created client class in runtime, using the following functions:
$client->setAuth($key, $secret);` $client->getAuthKey(); $client->getAuthSecret(); $client->setDebug($debug); $client->getDebug(); $client->setUrl($url); $client->getUrl();
aftermarketpl/api 适用场景与选型建议
aftermarketpl/api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.57k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 11 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「aftermarket」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 aftermarketpl/api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 aftermarketpl/api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 aftermarketpl/api 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
A lightweight plain-PHP framework for database-backed CRUD APIs.
Modern, strongly-typed, PSR-compliant PHP client for the WeFact v2 API.
PHP SDK for the Enconvert file conversion API
支付宝开放平台v3协议文档,支持最新版PHP8+
Usgm PHP Library
统计信息
- 总下载量: 3.57k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2018-11-14