germania-kg / fabricsapi-client
HTTP-Client for Germania's Fabrics API
4.1.1
2023-01-30 09:15 UTC
Requires
- php: ^7.4|^8.0
- germania-kg/cachecallable: ^2.0
- germania-kg/fabrics: ^5.0
- germania-kg/response-decoder: ^1.0
- guzzlehttp/guzzle: ^6.0|^7.0
- psr/cache: ^1.0
- psr/log: ^1.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.0|^3.0
- php-coveralls/php-coveralls: ^2.0
- phpspec/prophecy: ^1.16
- phpspec/prophecy-phpunit: ^2.0
- phpstan/phpstan: ^1.9
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-12-16 14:10:49 UTC
README
Germania KG · FabricsAPI client
Installation
composer require germania-kg/fabricsapi-client "^4.0"
Instantiation
The FabricsApiClient requures a Guzzle client with configured API base URL at hand:
<?php use Germania\FabricsApiClient\FabricsApiClient; $guzzle = new \GuzzleHttp\Client([ // Note the trailing slash! 'base_uri' => "https://path/to/api/" ]); $reader = new FabricsApiClient($guzzle);
Cache results
For better performance, a PSR-6 CacheItemPool may be used to cache the results. The CacheFabricsApiClient wraps the above FabricsApiClient:
<?php use Germania\FabricsApiClient\CacheFabricsApiClient; $api_reader = new FabricsApiClient($guzzle); $psr6 = ...; $lifetime = 86400; $reader = new CacheFabricsApiClient($api_reader, $psr6, $lifetime);
Usage
Read all fabrics
// iterable $all_fabrics = $reader->collection("anyCollection"); // Sort by pattern $all_fabrics = $reader->collection("anyCollection", null, "pattern");
Search fabrics
// iterable $matching_fabrics = $reader->collection("anyCollection", "seaflower"); // Sort by pattern $matching_fabrics = $reader->collection("anyCollection", "seaflower", "pattern");
Read single fabric
// Germania\Fabrics\FabricInterface $single = reader->fabric("anyCollection", "1-2345");
Unit tests
Copy phpunit.xml.dist
to phpunit.xml
and adapt to your needs. Obtain Germania's Fabrics API URL and the collection slug, otherwise the Unit Tests will fail and ask a wrong API…
<php> <env name="FABRICS_API" value="https://api.test.com/" /> <env name="FABRICS_SLUG" value="duette" /> <env name="FABRIC_NUMBER" value="1-2345" /> </php>
Run PhpUnit test or composer scripts like this:
$ composer test # or $ vendor/bin/phpunit