lasserafn/php-ordrestyring

PHP 对 Ordrestyring.dk 的 Api 封装

0.03 2020-05-15 11:16 UTC

README

REST Api 封装 Ordrestyring v2 API

Build Status Coverage StyleCI Status Total Downloads Latest Stable Version License

它受到 Laravel 的 Query Builder 以及类似的启发,并使用了一种流畅的语法。示例

$ordrestyring->cases()
             ->with('hours', 'type')
             ->where('status', 1)
             ->sortDescending()
             ->sortBy('id')
             ->perPage(15)
             ->page(4)
             ->get();

这将返回一个包含相关小时和类型的 Illuminate/Collection 的案例,按 id 降序排列,并从第 4 页取 15 个结果。

你还可以做类似的事情

$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

用法

第一步是通过联系 Ordrestyring 获取你 Ordrestyring 账户的 API 令牌。

$ordrestyring = new LasseRafn\Ordrestyring\Ordrestyring('API-KEY');

$ordrestyring->cases()->get();

你可能还想添加一个使用声明

use LasseRafn\Ordrestyring\Ordrestyring;

异常处理

所有请求异常都将抛出一个异常,该异常扩展 GuzzleHttp\Exception\ClientException。返回的异常是 LasseRafn\Ordrestyring\Exceptions\RequestException,如果存在错误信息,将从 Ordrestyring 获取该信息,如果不存在,则默认为 ClientException 的信息。因此,异常处理可以非常简单,如下所示

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

将输出类似:“此项目不存在”(根据他们的 API)的内容

支持的端点

  • 债务人
  • 债务人发票
  • 配送地址
  • 案例
  • 更多内容即将到来...

测试

测试正在进行中...