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