setono / budbee-php-sdk
Consume the Budbee API with this PHP SDK
Installs: 3 392
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 2
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-12-18 18:24:04 UTC
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.