A PHP wrapper for Ordrestyring.dk
Switch branches/tags
Nothing to show
Clone or download
Latest commit 77e590a Sep 22, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Style Sep 22, 2017
.coveralls.yml Coveralls and travis Jan 24, 2017
.gitignore Initial Jan 24, 2017
.travis.yml Coveralls and travis Jan 24, 2017
LICENSE.md Coveralls and travis Jan 24, 2017
README.md Readme Sep 22, 2017
composer.json Initial Jan 24, 2017
composer.lock Initial Jan 24, 2017
phpunit.xml Phpunit Jan 24, 2017

README.md

PHP wrapper for Ordrestyring.dk

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