Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions src/Geocoder/Provider/GeoIPsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,25 +157,23 @@ protected function executeQuery($query)
}

// Make sure that we do have proper result array
if (empty($response['locations']) || !is_array($response['locations']) || empty($response['locations'][0])) {
if (empty($response['location']) || !is_array($response['location'])) {
throw new NoResultException(sprintf('Invalid response from GeoIPs server for query %s', $query));
}

// Pick the first location from the response
$locations = array();
foreach ($response['locations'] as $location) {
$locations[] = array_merge($this->getDefaults(), array(
'country' => '' === $location['country_name'] ? null : $location['country_name'],
'countryCode' => '' === $location['country_code'] ? null : $location['country_code'],
'region' => '' === $location['region_name'] ? null : $location['region_name'],
'regionCode' => '' === $location['region_code'] ? null : $location['region_code'],
'county' => '' === $location['county_name'] ? null : $location['county_name'],
'city' => '' === $location['city_name'] ? null : $location['city_name'],
'latitude' => '' === $location['latitude'] ? null : $location['latitude'],
'longitude' => '' === $location['longitude'] ? null : $location['longitude'],
'timezone' => '' === $location['timezone'] ? null : $location['timezone'],
));
}
$location = $response['location'];
$locations[] = array_merge($this->getDefaults(), array(
'country' => '' === $location['country_name'] ? null : $location['country_name'],
'countryCode' => '' === $location['country_code'] ? null : $location['country_code'],
'region' => '' === $location['region_name'] ? null : $location['region_name'],
'regionCode' => '' === $location['region_code'] ? null : $location['region_code'],
'county' => '' === $location['county_name'] ? null : $location['county_name'],
'city' => '' === $location['city_name'] ? null : $location['city_name'],
'latitude' => '' === $location['latitude'] ? null : $location['latitude'],
'longitude' => '' === $location['longitude'] ? null : $location['longitude'],
'timezone' => '' === $location['timezone'] ? null : $location['timezone'],
));

return $locations;
}
Expand Down
8 changes: 4 additions & 4 deletions tests/Geocoder/Tests/Provider/GeoIPsProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function testGetGeocodedDataWithRealIPv4GetsFakeContentFormattedEmpty()
"message": "Success",
"notes": "The following results has been returned",
"code": "200_1",
"locations": [{
"location": {
"ip" : "66.147.244.214",
"owner" : "",
"continent_name" : "",
Expand All @@ -124,7 +124,7 @@ public function testGetGeocodedDataWithRealIPv4GetsFakeContentFormattedEmpty()
"latitude" : "",
"longitude" : "",
"timezone" : ""
}],
},
"unit_test": {
"elapsed_time": "0.0676",
"memory_usage": "2.2MB"
Expand Down Expand Up @@ -156,7 +156,7 @@ public function testGetGeocodedDataWithRealIPv4GetsFakeContent()
"message": "Success",
"notes": "The following results has been returned",
"code": "200_1",
"locations": [{
"location": {
"ip" : "66.147.244.214",
"owner" : "BLUEHOST INC.",
"continent_name" : "NORTH AMERICA",
Expand All @@ -170,7 +170,7 @@ public function testGetGeocodedDataWithRealIPv4GetsFakeContent()
"latitude" : "40.3402",
"longitude" : "-111.6073",
"timezone" : "MST"
}]
}
}}';

$provider = new GeoIPsProvider($this->getMockAdapterReturns($json), 'api_key');
Expand Down