Download the PHP package germania-kg/downloadsapi-client without Composer
On this page you can find all versions of the php package germania-kg/downloadsapi-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download germania-kg/downloadsapi-client
More information about germania-kg/downloadsapi-client
Files in germania-kg/downloadsapi-client
Package downloadsapi-client
Short Description API Client for Germania's Downloads API
License proprietary
Informations about the package downloadsapi-client
DownloadsApi Client
Server-side PHP client for retrieving a list of available downloads from Germania's Downloads API.
Installation
The v5 release is a complete rewrite, so there is no “upgrading” procedure.
This package requires a PSR-18 HTTP client implementation and a PSR-17 HTT factory implementation. Suggestions are Guzzle 7 via guzzlehttp/guzzle and Nyholm's nyholm/psr7 which (despite its name) provides the PSR-17 factories as well:
Basics
Interface and abstract class
Interface DownloadsApiInterface provides public methods for retrieving documents, all and latest and request, with the latter for internal use. All of these return an iterable. There are also interceptors for the authentication key:
Abstract class DownloadsApiAbstract prepares the all and latest methods to delegate directly to the request method. It also utilizes various useful traits such as Psr\Log\LoggerAwareTrait
, LoglevelTrait
and AuthenticationTrait
. – So any class extending this abstract will thus provide:
PSR-6 Cache Support
Class CacheDownloadsApiDecorator wraps an existing DownloadsApi instance and adds support for PSR-6 Caches. It extends DownloadsApiDecorator which itself extends DownloadsApiAbstract, so the class also implements DownloadsApiInterface.
The constructor requires a DownloadsApi (or DownloadsApiInterface) instance and a PSR-6 Cache Item Pool. You may optionally pass a cache lifetime in seconds which defaults to 14400 (4 hours).
The API client
The DownloadsApi API client extends DownloadsApiAbstract und thus implements DownloadsApiInterface. The constructor requires a PSR-18 HTTP Client, a PSR-17 Request factory and an API key. – To obtain an API key, ask the web developers over at Germania KG.
Retrieve documents
Public methods all and latest return an Array iterable with the documents provided by Germania's Documents API.
Example record
The above print_r( $document )
will reveal something like this:
Filtering results
To narrow down the results, both the all and latest methods accept an array with filter values. The fiter values may contain multiple values, separated with comma.
Think of the filter array items as WHERE … AND…
clauses, and comma-separated values as 'a' OR 'b'
Errors and Exceptions
It should be plenty to watch out for \Germania\DownloadsApi\Exceptions\DownloadsApiExceptionInterface
since all concrete exception classes implement this interface.
Exceptions during request:
Whenever a PSR-18 client request fails, a DownloadsApiRuntimeException will be thrown. This class implements DownloadsApiExceptionInterface
and extends \RuntimeException
.
HTTP Error responses:
When a API call returns an HTTP error response, a DownloadsApiResponseException will be thrown. This class implements DownloadsApiExceptionInterface
and extends \RuntimeException
.
Unexpected values in response:
Whenever a response (even with status 200 OK) can't be decoded to an useful array, a DownloadsApiUnexpectedValueException will be thrown. This class implements DownloadsApiExceptionInterface
and extends \UnexpectedValueException
.
Unit tests and development
Copy phpunit.xml.dist
to phpunit.xml
and fill in the Authentication data you obtained from Germania.
AUTH_TOKEN
when you've got an auth token for the Downloads API at hand.- Otherwise, fill in
AUTH_API
,AUTH_USER
, andAUTH_PASS
. The auth token will then be fetched from Germania's Auth API before each test.
In order to run unit tests, run PhpUnit like this:
Issues
All versions of downloadsapi-client with dependencies
germania-kg/response-decoder Version ^1.0
psr/log Version ^1.1
psr/cache Version ^1.0|^2.0|^3.0
psr/http-factory Version ^1.0
psr/http-client Version ^1.0