private function executeQuery($query)
{
$request = $this->getMessageFactory()->createRequest('GET', $query);
$content = (string) $this->getHttpClient()->sendRequest($request)->getBody();
if (empty($content)) {
throw new NoResult(sprintf('Could not execute query "%s".', $query));
}
$json = json_decode($content, true);
if (!is_array($json) || !count($json)) {
throw new NoResult(sprintf('Could not execute query "%s".', $query));
}
if (!array_key_exists('geoplugin_status', $json) || 200 !== $json['geoplugin_status'] && 206 !== $json['geoplugin_status']) {
throw new NoResult(sprintf('Could not execute query "%s".', $query));
}
$data = array_filter($json);
$adminLevels = [];
$region = \igorw\get_in($data, ['geoplugin_regionName']);
$regionCode = \igorw\get_in($data, ['geoplugin_regionCode']);
if (null !== $region || null !== $regionCode) {
$adminLevels[] = ['name' => $region, 'code' => $regionCode, 'level' => 1];
}
$results = [];
$results[] = array_merge($this->getDefaults(), ['locality' => isset($data['geoplugin_city']) ? $data['geoplugin_city'] : null, 'country' => isset($data['geoplugin_countryName']) ? $data['geoplugin_countryName'] : null, 'countryCode' => isset($data['geoplugin_countryCode']) ? $data['geoplugin_countryCode'] : null, 'adminLevels' => $adminLevels, 'latitude' => isset($data['geoplugin_latitude']) ? $data['geoplugin_latitude'] : null, 'longitude' => isset($data['geoplugin_longitude']) ? $data['geoplugin_longitude'] : null]);
return $this->returnResults($results);
}