germania-kg/fabricsapi-client

HTTP-Client for Germania's Fabrics API

4.0.1 2022-04-08 08:58 UTC

This package is auto-updated.

Last update: 2022-09-08 10:01:43 UTC


README

68747470733a2f2f7374617469632e6765726d616e69612d6b672e636f6d2f6c6f676f732f67612d6c6f676f2d323031362d7765622e7376677a

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