setono/budbee-php-sdk
最新稳定版本:v1.1.0
Composer 安装命令:
composer require setono/budbee-php-sdk
包简介
Consume the Budbee API with this PHP SDK
README 文档
README
Consume the Budbee API in PHP.
Installation
composer require setono/budbee-php-sdk
Usage
Get available lockers
<?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"; }
will output something like:
Budbee CPH Office (BOX0012)
Ehlersvej 11
2900 Hellerup
DK
Other requests
If the endpoint or method you want to call isn't present yet, you have two options: 1) Create a PR and add the missing parts or 2) use the generic request method:
<?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);
Production usage
Internally this library uses the CuyZ/Valinor library which is particularly well suited for turning API responses in DTOs. However, this library has some overhead and works best with a cache enabled.
When you instantiate the Client you can provide a MapperBuilder instance. Use this opportunity to set a cache:
<?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));
You can read more about it here: Valinor: Performance and caching.
统计信息
- 总下载量: 4.23k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-02-15