akaunting/app/Traits/SiteApi.php

38 lines
899 B
PHP
Raw Normal View History

2017-09-14 19:21:00 +00:00
<?php
namespace App\Traits;
use GuzzleHttp\Client;
2018-05-25 03:11:53 +00:00
use GuzzleHttp\Exception\RequestException;
2017-09-14 19:21:00 +00:00
trait SiteApi
{
2019-11-16 07:21:14 +00:00
protected static function getRemote($path, $method = 'GET', $data = [])
2017-09-14 19:21:00 +00:00
{
2019-11-16 07:21:14 +00:00
$base = 'https://api.akaunting.com/';
2017-09-14 19:21:00 +00:00
$client = new Client(['verify' => false, 'base_uri' => $base]);
2019-11-16 07:21:14 +00:00
$headers['headers'] = [
'Authorization' => 'Bearer ' . setting('apps.api_key'),
2017-09-14 19:21:00 +00:00
'Accept' => 'application/json',
2019-03-09 14:24:27 +00:00
'Referer' => url('/'),
2018-12-19 12:36:40 +00:00
'Akaunting' => version('short'),
'Language' => language()->getShortCode()
2019-11-16 07:21:14 +00:00
];
2017-09-14 19:21:00 +00:00
2017-10-17 13:56:53 +00:00
$data['http_errors'] = false;
2017-09-14 19:21:00 +00:00
$data = array_merge($data, $headers);
2018-05-25 03:11:53 +00:00
try {
2019-11-16 07:21:14 +00:00
$result = $client->request($method, $path, $data);
2018-05-25 03:11:53 +00:00
} catch (RequestException $e) {
$result = $e;
}
2017-09-14 19:21:00 +00:00
return $result;
}
2018-05-25 13:57:58 +00:00
}