magento2-docker/app/code/IpSupply/ChatMessage/Helper/Request/GetEventsRequest.php

50 lines
1.1 KiB
PHP
Executable File

<?php
namespace IpSupply\ChatMessage\Helper\Request;
use GuzzleHttp\ClientInterface;
use IpSupply\ChatMessage\Helper\Authentication;
class GetEventsRequest extends RequestAbstract
{
use SimpleValidationTrait;
/**
* @var ClientInterface
*/
protected $httpClient;
/**
* @inheritDoc
*/
public function __construct(ClientInterface $client)
{
$this->httpClient = $client;
}
/**
* @inheritDoc
*/
public function initialize($serverUrl, ParametersInterface $params, Authentication $defaultAuthentication)
{
$this->validate($params, ['queue_id', 'last_event_id']);
$auth = $params->getAuthentication();
if (empty($auth)) {
$auth = $defaultAuthentication;
}
$response = $this->httpClient->request('POST',
$serverUrl . '/api/v1/events',
[
'auth' => [
$auth->getUsername(),
$auth->getApiKey(),
],
'form_params' => $params->getData()
]
);
return GetEventsResponse::fromHttpResponse($response);
}
}