lasserafn / php-ordrestyring
A PHP Api wrapper for Ordrestyring.dk
Requires
- guzzlehttp/guzzle: ^6.2
- illuminate/support: ^5.3|^5.4
This package is auto-updated.
Last update: 2024-12-19 22:12:40 UTC
README
REST Api Wrapper for Ordrestyring v2 API.
It's inspired by the Query Builder from Laravel and similar, and uses a nice fluent syntax. Example:
$ordrestyring->cases() ->with('hours', 'type') ->where('status', 1) ->sortDescending() ->sortBy('id') ->perPage(15) ->page(4) ->get();
This will return a Illuminate/Collection
of cases, with related hours and type, ordered descending by id, and take 15 results from page 4.
You can also do things like:
$ordrestyring->users()->find(10);
$ordrestyring->debtors()->first();
$ordrestyring->departments()->where('number', '!=', 19)->all();
$ordrestyring->debtors()->where('id', [1,2,3,4])->get(); // Will get debtors with id 1, 2, 3 and/or 4
Installation
composer require lasserafn/php-ordrestyring
Usage
First step is to get an API token for you Ordrestyring account by contacting Ordrestyring.
$ordrestyring = new LasseRafn\Ordrestyring\Ordrestyring('API-KEY'); $ordrestyring->cases()->get();
You'd probably want to add a use statement instead:
use LasseRafn\Ordrestyring\Ordrestyring;
Exceptions
All request exceptions will throw an exception, which extends GuzzleHttp\Exception\ClientException
. The returned exception is LasseRafn\Ordrestyring\Exceptions\RequestException
and will get the error message from Ordrestyring if one is present, and default to the ClientException message if none is present. So handling exceptions can be as simple as:
try { // try to get something from the api, but nothing is found. } catch( LasseRafn\Ordrestyring\Exceptions\RequestException $exception ) { echo $exception->message; // could redirect back with the message. }
Would echo out something like: "This item does not exists" (according to their API)
Supported endpoints
- Debtors
- Debtor Invoices
- Delivery Addresses
- Cases
- More to come...
Tests
Tests are in the making...