Cleanup of cli
This commit is contained in:
@ -1,9 +1,11 @@
|
||||
<?php
|
||||
namespace ProVM\Common\Service;
|
||||
namespace ProVM\Service;
|
||||
|
||||
use HttpResponseException;
|
||||
use Psr\Http\Client\ClientInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Safe\Exceptions\JsonException;
|
||||
use function Safe\json_encode;
|
||||
|
||||
class Communicator
|
||||
@ -26,6 +28,9 @@ class Communicator
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws HttpResponseException
|
||||
*/
|
||||
protected function handleResponse(ResponseInterface $response): ResponseInterface
|
||||
{
|
||||
if ($response->getStatusCode() < 200 or $response->getStatusCode() >= 300) {
|
||||
@ -33,6 +38,11 @@ class Communicator
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws HttpResponseException
|
||||
* @throws JsonException
|
||||
*/
|
||||
protected function request(string $method, string $uri, ?array $body = null): ResponseInterface
|
||||
{
|
||||
$options = [];
|
||||
@ -45,20 +55,39 @@ class Communicator
|
||||
return $this->handleResponse($this->getClient()->request($method, $uri, $options));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws HttpResponseException
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function get(string $uri): ResponseInterface
|
||||
{
|
||||
return $this->request('get', $uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws HttpResponseException
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function post(string $uri, array $data): ResponseInterface
|
||||
{
|
||||
return $this->request('post', $uri, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws HttpResponseException
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function put(string $uri, array $data): ResponseInterface
|
||||
{
|
||||
return $this->request('put', $uri, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws HttpResponseException
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function delete(string $uri, array $data): ResponseInterface
|
||||
{
|
||||
return $this->request('delete', $uri, $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user