lasserafn/php-ordrestyring

A PHP Api wrapper for Ordrestyring.dk

0.03 2020-05-15 11:16 UTC

README

REST Api Wrapper for Ordrestyring v2 API.

Build Status Coverage StyleCI Status Total Downloads Latest Stable Version License

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...