openpublicmedia/roisolutions-php

PHP client for ROI Solutions APIs.

0.9.1 2024-05-11 13:08 UTC

This package is auto-updated.

Last update: 2024-12-11 14:21:29 UTC


README

This library abstracts interactions with ROI Solutions APIs.

Implemented APIs:

Installation

Install via composer:

composer require openpublicmedia/roisolutions-php

Use

REST API

The OpenPublicMedia\RoiSolutions\Rest\Client queries the REST API.

Examples

Creating a client

use OpenPublicMedia\RoiSolutions\Rest\Client;

$userId = 'USER_ID';
$password = 'pAsSw0rD';
$clientCode = 'CLIENTCODE';

$client = new Client($userId, $password, $clientCode);

Providing a cache service is also supported (and recommended) when creating the client. If the client has a cache service it will be used to cache the authentication token provided by the API across multiple requests for the lifetime of the token.

A PSR-16 compliant interface is preferred but any class providing set($key, $value) and get($key, $default) methods will suffice.

use OpenPublicMedia\RoiSolutions\Rest\Client;
use Tochka\Cache\ArrayFileCache;

$userId = 'USER_ID';
$password = 'pAsSw0rD';
$clientCode = 'CLIENTCODE';
$cache = new ArrayFileCache('.', 'my_awesome_cache');

$client = new Client($userId, $password, $clientCode, cache: $cache);

Handling exceptions

Custom exceptions are provided for 404 response and general errors. Additional information from the API response is captured in these exceptions.

use OpenPublicMedia\RoiSolutions\Rest\Exception\RequestException;

try {
    $results = $client->request('get', 'donors');
} catch (RequestException $e) {
    var_dump(get_class($e));
    var_dump($e->getMessage());
    var_dump($e->getCode());
    var_dump($e->getStatusCodeReported());
    var_dump($e->getTitle());
    var_dump($e->getDetail());
    var_dump($e->getInstanceCode());
    var_dump($e->getHelpLink());
}

Development goals

See CONTRIBUTING for information about contributing to this project.

v1