public function sendData($data)
{
// don't throw exceptions for 4xx errors
$this->httpClient->getEventDispatcher()->addListener('request.error', function ($event) {
if ($event['response']->isClientError()) {
$event->stopPropagation();
}
});
$httpRequest = $this->httpClient->createRequest($this->getHttpMethod(), $this->getEndpoint(), array('Accept' => 'application/json'), $data);
$httpResponse = $httpRequest->setAuth($this->getClientId(), $this->getSecret())->send();
// Empty response body should be parsed also as and empty array
$body = $httpResponse->getBody(true);
$jsonToArrayResponse = !empty($body) ? $httpResponse->json() : array();
return $this->response = new RestResponse($this, $jsonToArrayResponse, $httpResponse->getStatusCode());
}