Initial xentral_oss_20.3.c9ffacf

This commit is contained in:
Alex
2021-05-21 08:49:41 +02:00
parent 5406e4a551
commit 34e5ac43d9
18884 changed files with 2109867 additions and 0 deletions
@@ -0,0 +1,65 @@
<?php
declare(strict_types=1);
namespace Xentral\Modules\Hubspot;
use \Psr\Http\Message\ResponseInterface;
final class HubspotHttpResponseService
{
/** @var ResponseInterface $response */
private $response;
/**
* @param ResponseInterface $response
*/
public function __construct(ResponseInterface $response)
{
$this->response = $response;
}
/**
* Returns the json response body
*
* @return array
*/
public function getJson(): array
{
$content = (string)$this->response->getBody();
$jsonResponse = json_decode($content, true);
if ($jsonResponse === null || (json_last_error() !== JSON_ERROR_NONE)) {
return [];
}
return $jsonResponse;
}
/**
* @return int
*/
public function getStatusCode() : int
{
return $this->response->getStatusCode();
}
/**
* Returns the error message
*
* @return string
*/
public function getError(): string
{
if (!in_array($this->getStatusCode(), [200, 201, 204])) {
if (($resp = $this->getJson()) && array_key_exists('error', $resp)) {
return $resp['error'];
}
return 'Unknown Error';
}
return '';
}
}