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