Uso de request original
This commit is contained in:
@ -5,6 +5,7 @@ use Incoviba\Common\Implement\Exception\EmptyResponse;
|
|||||||
use Incoviba\Service\Worker;
|
use Incoviba\Service\Worker;
|
||||||
use Psr\Http\Client\ClientExceptionInterface;
|
use Psr\Http\Client\ClientExceptionInterface;
|
||||||
use Psr\Http\Client\ClientInterface;
|
use Psr\Http\Client\ClientInterface;
|
||||||
|
use Psr\Http\Message\RequestInterface;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Incoviba\Common\Ideal;
|
use Incoviba\Common\Ideal;
|
||||||
use Incoviba\Model;
|
use Incoviba\Model;
|
||||||
@ -16,6 +17,13 @@ class Request extends Ideal\Service implements Worker
|
|||||||
parent::__construct($logger);
|
parent::__construct($logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected RequestInterface $request;
|
||||||
|
public function setRequest(RequestInterface $request): self
|
||||||
|
{
|
||||||
|
$this->request = $request;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Model\Job $job
|
* @param Model\Job $job
|
||||||
* @return bool
|
* @return bool
|
||||||
@ -23,13 +31,16 @@ class Request extends Ideal\Service implements Worker
|
|||||||
*/
|
*/
|
||||||
public function execute(Model\Job $job): bool
|
public function execute(Model\Job $job): bool
|
||||||
{
|
{
|
||||||
$url = $job->configuration['url'];
|
$url = $job->configuration['url'] ?? $job->configuration['action'];
|
||||||
$method = strtolower($job->configuration['method']);
|
$method = strtolower($job->configuration['method']) ?? 'get';
|
||||||
$body = $job->configuration['body'];
|
$body = $job->configuration['body'];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$response = $this->client->{$method}($url, [
|
$response = $this->client->{$method}($url, [
|
||||||
'json' => $body,
|
'json' => $body,
|
||||||
|
'headers' => [
|
||||||
|
'Authorization' => $this->request->getHeaderLine('Authorization')
|
||||||
|
]
|
||||||
]);
|
]);
|
||||||
} catch (ClientExceptionInterface $exception) {
|
} catch (ClientExceptionInterface $exception) {
|
||||||
throw new EmptyResponse($url, $exception);
|
throw new EmptyResponse($url, $exception);
|
||||||
|
Reference in New Issue
Block a user