ezknock/ezknock-php-sdk
Composer 安装命令:
composer require ezknock/ezknock-php-sdk
包简介
EZ Knock API client built on top of HTTPlug
README 文档
README
Official PHP bindings to the EZ Knock API
Project Updates
Installation
This library supports PHP 7.3 and later
This library uses HTTPlug as HTTP client. HTTPlug is an abstraction that allows this library to support many different HTTP Clients. Therefore, you need to provide it with an adapter for the HTTP library you prefer. You can find all the available adapters in Packagist. This documentation assumes you use the Guzzle7 Client, but you can replace it with any adapter that you prefer.
The recommended way to install ezknock-php-sdk is through Composer:
composer require ezknock/ezknock-php-sdk php-http/guzzle7-adapter
Clients
Initialize your client using your access token:
use EZKnock\Client as EZKClient; $client = new EZKClient('<insert_token_here>');
If you already have an access token you can find it here. If you want to create or learn more about access tokens then you can find more info here.
For most use cases the code snippet above should suffice. However, if needed, you can customize the EZKnock client as follows:
Use a custom HTTP client
This client needs to implement Psr\Http\Client\ClientInterface
$client->setHttpClient($yourHttpClient);
Use a custom request factory
This factory needs to implement Http\Message\RequestFactory
$client->setRequestFactory($yourRequestFactory);
Use a custom URI factory
This factory needs to implement Http\Message\UriFactory
$client->setUriFactory($yourUriFactory);
Coverage
Get coverage information by Zip code.
try { $data = $client->buyers->coverage('73301'); print_r($data); } catch (Exception $ex) { print_r($ex->getMessage()); print_r($ex->getDebug()); }
Create order
Create an order
$data = [ 'recipients' => [ [ 'firstname' => 'Ryann', 'lastname' => 'Ullrich', 'company' => 'Romaguera, Yundt and Marvin', 'email' => 'nikita67@kihn.com' ] ], 'address' => '2453 W Vita Locks Rapids', 'address_2' => 'BLDG 377', 'city' => 'Austin', 'state' => 'TX', 'zip' => '78749', 'return_type' => 'default', 'originals' => false, 'witnessfees' => true, 'instructions' => 'Aut perferendis et necessitatibus. Vel tempore molestiae ut nihil dolore. Rem dolor sed nulla cupiditate.', 'min_attempts' => 3, 'documents' => 'ORDER FOR ALTERNATIVE SERVICE AND TO EXTEND TIME FOR SERVICE OF PROCESS; SUMMONS; COMPLAINT; EXHIBIT; NOTICE TO DEFENDANT', 'attempt_by' => '2021-05-10', 'diligence_by' => '2021-05-15', 'complete_by' => '2021-05-20', 'service_files' => [fopen('/path/to/file.pdf', 'r')], 'other_files' => [fopen('/path/to/file.pdf', 'r')], 'return_file' => fopen('/path/to/file.pdf', 'r'), 'qualifications' => [1, 2, 3], 'costs' => [ [ 'name' => 'delivery', 'amount' => 50 ], [ 'name' => 'rush', 'amount' => 20 ] ] ]; try { $order = $client->buyers->createOrder($data); print_r($order); } catch (Exception $ex) { print_r($ex->getMessage()); print_r($ex->getDebug()); }
Rate Limits
Rate limit info is passed via the rate limit headers. You can access this information as follows:
$rate_limit = $client->getRateLimit(); print("{$rate_limit['remaining']} {$rate_limit['limit']} \n"); print_r($rate_limit['reset_at']->format(DateTime::ISO8601));
For more info on rate limits and these headers please see the API reference docs
Pagination
When listing, the EZ Knock API may return a pagination object:
{
"pages": {
"next": "..."
}
}
You can grab the next page of results using the client:
$client->nextPage($response->pages);
Exceptions
Exceptions are handled by HTTPlug. Every exception thrown implements Http\Client\Exception. See the http client exceptions and the client and server errors.
The EZ Knock API may return an unsuccessful HTTP response, for example when a resource is not found (404).
If you want to catch errors you can wrap your API call into a try/catch block:
try { $user = $client->buyers->coverage('73301'); } catch(Http\Client\Exception $e) { if ($e->getCode() == '404') { // Handle 404 error return; } else { throw $e; } }
Pull Requests
-
Add tests! Your patch won't be accepted if it doesn't have tests.
-
Document any change in behaviour. Make sure the README and any other relevant documentation are kept up-to-date.
-
Create topic branches. Don't ask us to pull from your master branch.
-
One pull request per feature. If you want to do more than one thing, send multiple pull requests.
-
Send coherent history. Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please squash them before sending them to us.
ezknock/ezknock-php-sdk 适用场景与选型建议
ezknock/ezknock-php-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 70 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 05 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「Guzzle」 「ezknock」 「ezknockmarketplace.com」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ezknock/ezknock-php-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ezknock/ezknock-php-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ezknock/ezknock-php-sdk 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
Cloudflare Middleware For Guzzle
Simplifies working with holaluz API endpoints
Wrapper for Slack Web API
HipChat API Client
A few tools for working with Guzzle
统计信息
- 总下载量: 70
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2021-05-04