setono / budbee-php-sdk
使用此PHP SDK消费Budbee API
v1.1.0
2023-02-20 07:47 UTC
Requires
- php: >=7.4
- cuyz/valinor: ^0.17 || ^1.0
- php-http/discovery: ^1.14
- psr/http-client: ^1.0
- psr/http-client-implementation: ^1
- psr/http-factory: ^1.0
- psr/http-factory-implementation: ^1
- psr/http-message: ^1.0
- psr/log: ^1.1 || ^2.0 || ^3.0
Requires (Dev)
- infection/infection: ^0.26
- kriswallsmith/buzz: ^1.2
- nyholm/psr7: ^1.5
- phpspec/prophecy-phpunit: ^2.0
- phpunit/phpunit: ^9.5
- psalm/plugin-phpunit: ^0.18
- setono/code-quality-pack: ^2.4
This package is auto-updated.
Last update: 2024-09-18 17:43:24 UTC
README
在PHP中使用Budbee API。
安装
composer require setono/budbee-php-sdk
使用
获取可用寄存柜
<?php use Setono\Budbee\Client\Client; use Setono\Budbee\DTO\Collection; use Setono\Budbee\DTO\Box; require_once '../vendor/autoload.php'; $client = new Client('API_KEY', 'API_SECRET'); // Set a logger to log more details about exceptions thrown // $client->setLogger($logger); // Enable sandbox mode to test your integration // $client->setSandbox(); $boxes = $client ->boxes() ->getAvailableLockers('DK', '1159') ; /** @var Box $box */ foreach ($boxes as $box) { echo $box->name . " ($box->id)\n"; echo $box->address->street . "\n"; echo $box->address->postalCode . ' ' . $box->address->city . "\n"; echo $box->address->country . "\n\n"; }
将输出类似的内容
Budbee CPH Office (BOX0012)
Ehlersvej 11
2900 Hellerup
DK
其他请求
如果你要调用的端点或方法尚未存在,你有两种选择:1) 创建一个PR并添加缺失的部分或2) 使用通用的request
方法
<?php use Setono\Budbee\Client\Client; require_once '../vendor/autoload.php'; $client = new Client('API_KEY', 'API_SECRET'); /** @var \Psr\Http\Message\ResponseInterface $response */ $response = $client->request(/** @var \Psr\Http\Message\RequestInterface $request */ $request);
生产使用
该库内部使用CuyZ/Valinor库,该库特别适合将API响应转换为DTO。然而,这个库有一些开销,并且启用缓存时表现最佳。
当你实例化Client
时,你可以提供一个MapperBuilder
实例。利用这个机会设置一个缓存
<?php use CuyZ\Valinor\Cache\FileSystemCache; use CuyZ\Valinor\MapperBuilder; use Setono\Budbee\Client\Client; use Setono\Budbee\DTO\Collection; use Setono\Budbee\DTO\Box; require_once '../vendor/autoload.php'; $cache = new FileSystemCache('path/to/cache-directory'); $client = new Client('API_KEY', 'API_SECRET', (new MapperBuilder())->withCache($cache));
你可以在这里了解更多信息:Valinor: 性能和缓存。