germania-kg/fabricsapi-client

HTTP-Client for Germania's Fabrics API

4.1.1 2023-01-30 09:15 UTC

This package is auto-updated.

Last update: 2024-11-16 14:01:41 UTC


README

Germania KG · FabricsAPI client

Packagist PHP version Tests

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