A PHP Api wrapper for Ordrestyring.dk
REST Api Wrapper for Ordrestyring v2 API., (*1)
It's inspired by the Query Builder from Laravel and similar, and uses a nice fluent syntax. Example:, (*3)
$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., (*4)
You can also do things like:, (*5)
$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
composer require lasserafn/php-ordrestyring
First step is to get an API token for you Ordrestyring account by contacting Ordrestyring., (*6)
$ordrestyring = new LasseRafn\Ordrestyring\Ordrestyring('API-KEY'); $ordrestyring->cases()->get();
You'd probably want to add a use statement instead:, (*7)
use LasseRafn\Ordrestyring\Ordrestyring;
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:, (*8)
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), (*9)
Tests are in the making..., (*10)