public function deserialize(ResponseInterface $response, $class)
{
$body = $response->getBody()->__toString();
if (strpos($response->getHeaderLine('Content-Type'), 'application/json') !== 0) {
throw new DeserializeException('The ModelDeserializer cannot deserialize response with Content-Type:' . $response->getHeaderLine('Content-Type'));
}
$data = json_decode($body, true);
if (JSON_ERROR_NONE !== json_last_error()) {
throw new DeserializeException(sprintf('Error (%d) when trying to json_decode response', json_last_error()));
}
if (is_subclass_of($class, ApiResponse::class)) {
$object = call_user_func($class . '::create', $data);
} else {
$object = new $class($data);
}
return $object;
}