mirror of
https://gh.wpcy.net/https://github.com/hayBIT/freescout2ant.git
synced 2026-07-15 07:13:10 +08:00
39 lines
1.3 KiB
PHP
39 lines
1.3 KiB
PHP
<?php
|
||
|
||
namespace Modules\AmeiseModule\Services;
|
||
|
||
use Illuminate\Support\Facades\Http;
|
||
|
||
class AmeiseApiClient
|
||
{
|
||
public function __construct(
|
||
protected AmeiseTokenService $tokenService
|
||
) {}
|
||
|
||
/**
|
||
* Universelle Methode für API‑Calls (GET, POST, …).
|
||
*
|
||
* @param string $method HTTP‑Methode (GET|POST|PUT|PATCH|DELETE)
|
||
* @param string $uri Endpunkt relativ zur Base‑URI
|
||
* @param array $options query|json je nach Methode
|
||
*/
|
||
public function request(string $method, string $uri, array $options = [])
|
||
{
|
||
$token = $this->tokenService->getValidAccessToken();
|
||
|
||
$http = Http::withOptions([
|
||
'base_uri' => rtrim(config('ameisemodule.ameise_base_uri'), '/').'/',
|
||
])->withHeaders([
|
||
'Authorization' => "Bearer {$token}",
|
||
]);
|
||
|
||
return match (strtoupper($method)) {
|
||
'GET' => $http->get($uri, $options['query'] ?? []),
|
||
'POST' => $http->post($uri, $options['json'] ?? []),
|
||
'PUT' => $http->put($uri, $options['json'] ?? []),
|
||
'PATCH' => $http->patch($uri, $options['json'] ?? []),
|
||
'DELETE' => $http->delete($uri, $options['query'] ?? []),
|
||
default => throw new \InvalidArgumentException("Unsupported method {$method}"),
|
||
};
|
||
}
|
||
}
|