baywa-re-lusy/users-api-sdk

BayWa r.e. LUSY Users API SDK

3.1.0 2023-03-13 12:40 UTC

This package is auto-updated.

Last update: 2024-04-13 14:50:41 UTC


README

This SDK can be used to retrieve Users and Subsidiaries.

All dependencies injected into the constructor are PSR-compatible:

Installation

composer require baywa-re-lusy/users-api-sdk

Usage

use Laminas\Cache\Storage\Adapter\Apcu;

$tokenCache  = new \Laminas\Cache\Psr\CacheItemPool\CacheItemPoolDecorator(new Apcu());
$resultCache = new \Laminas\Cache\Psr\CacheItemPool\CacheItemPoolDecorator(new Apcu());
$httpClient  = new \GuzzleHttp\Client();

$usersApiClient = new \BayWaReLusy\UsersAPI\SDK\UsersApiClient(
    "<URL to Users API>",
    "<URL to Token API Endpoint>",
    "<Client ID>",
    "<Client Secret>",
    $tokenCache,
    $resultCache,
    $httpClient    
);

$users            = $usersApiClient->getUsers();
$subsidiaries     = $usersApiClient->getSubsidiaries();
$user             = $usersApiClient->getUser('<userId>');

Cache Refresh via Console commands

This SDK contains Symfony Console commands to refresh the User/Subsidiary cache. You can include the Console commands into your application:

$cliApp = new \Symfony\Component\Console\Application();

$cliApp->add(new \BayWaReLusy\UsersAPI\SDK\Console\RefreshUserCache($usersApiClient));
$cliApp->add(new \BayWaReLusy\UsersAPI\SDK\Console\RefreshSubsidiaryCache($usersApiClient)));

And then run the Console commands with:

./console users-api-sdk:refresh-user-cache
./console users-api-sdk:refresh-subsidiary-cache