for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php declare(strict_types=1);
namespace JSKOS;
use Http\Client\HttpClient;
use Http\Discovery\HttpClientDiscovery;
use Http\Discovery\MessageFactoryDiscovery;
use Http\Client\Exception as ClientException;
/**
* JSKOS API Client
*/
class Client extends Service
{
protected $baseUrl;
protected $httpClient;
protected $requestFactory;
public function __construct(
string $baseUrl,
HttpClient $client=null,
RequestFactory $requestFactory=null
)
$this->baseUrl = $baseUrl;
$this->requestFactory = $requestFactory ?: MessageFactoryDiscovery::find();
$this->httpClient = $client ?: HttpClientDiscovery::find();
}
public function query(array $query=[], string $path=''): Result {
$url = $this->baseUrl . $path;
if (count($query)) {
$url .= '?' . http_build_query($query);
$request = $this->requestFactory->createRequest('GET', $url, []);
$response = $this->httpClient->sendRequest($request);
# TOOD: detect and throw error
$data = json_decode((string)$response->getBody(),true);
# TODO: add total, offset, limit of page
return new Result($data ?? []);