From a5fe44c3d3d406f8e6cdda0401ba9238b45a650e Mon Sep 17 00:00:00 2001
From: Gregory Oschwald
This attribute is only available from the Omni end point.
+ *+ * This attribute is only available from the Insight web service end + * point. + *
*/ class Traits extends AbstractRecord { diff --git a/src/GeoIp2/WebService/Client.php b/src/GeoIp2/WebService/Client.php index 61d5004..7b6bdc2 100644 --- a/src/GeoIp2/WebService/Client.php +++ b/src/GeoIp2/WebService/Client.php @@ -15,10 +15,10 @@ use Guzzle\Http\Exception\ClientErrorResponseException; use Guzzle\Http\Exception\ServerErrorResponseException; /** - * This class provides a client API for all the GeoIP2 web service's - * end points. The end points are Country, City, City/ISP/Org, and Omni. Each - * end point returns a different set of data about an IP address, with Country - * returning the least data and Omni the most. + * This class provides a client API for all the GeoIP2 Precision web service + * end points. The end points are Country, City, and Insights. Each end point + * returns a different set of data about an IP address, with Country returning + * the least data and Insights the most. * * Each web service end point is represented by a different model class, and * these model classes in turn contain multiple Record classes. The record @@ -80,7 +80,7 @@ class Client implements ProviderInterface } /** - * This method calls the GeoIP2 City endpoint. + * This method calls the GeoIP2 Precision: City endpoint. * * @param string $ipAddress IPv4 or IPv6 address as a string. If no * address is provided, the address that the web service is called @@ -112,7 +112,41 @@ class Client implements ProviderInterface } /** - * This method calls the GeoIP2 Country endpoint. + * This method calls the GeoIP2 Precision: City endpoint. + * + * @param string $ipAddress IPv4 or IPv6 address as a string. If no + * address is provided, the address that the web service is called + * from will be used. + * + * @return \GeoIp2\Model\City + * + * @throws \GeoIp2\Exception\AddressNotFoundException if the address you + * provided is not in our database (e.g., a private address). + * @throws \GeoIp2\Exception\AuthenticationException if there is a problem + * with the user ID or license key that you provided. + * @throws \GeoIp2\Exception\OutOfQueriesException if your account is out + * of queries. + * @throws \GeoIp2\Exception\InvalidRequestException} if your request was + * received by the web service but is invalid for some other reason. + * This may indicate an issue with this API. Please report the error to + * MaxMind. + * @throws \GeoIp2\Exception\HttpException if an unexpected HTTP error + * code or message was returned. This could indicate a problem with the + * connection between your server and the web service or that the web + * service returned an invalid document or 500 error code. + * @throws \GeoIp2\Exception\GeoIp2Exception This serves as the parent + * class to the above exceptions. It will be thrown directly if a 200 + * status code is returned but the body is invalid. + * + * @deprecated deprecated since version 0.7.0 + */ + public function cityIspOrg($ipAddress = 'me') + { + return $this->city($ipAddress); + } + + /** + * This method calls the GeoIP2 Precision: Country endpoint. * * @param string $ipAddress IPv4 or IPv6 address as a string. If no * address is provided, the address that the web service is called @@ -144,13 +178,13 @@ class Client implements ProviderInterface } /** - * This method calls the GeoIP2 City/ISP/Org endpoint. + * This method calls the GeoIP2 Precision: Insights endpoint. * * @param string $ipAddress IPv4 or IPv6 address as a string. If no * address is provided, the address that the web service is called * from will be used. * - * @return \GeoIp2\Model\CityIspOrg + * @return \GeoIp2\Model\Insights * * @throws \GeoIp2\Exception\AddressNotFoundException if the address you * provided is not in our database (e.g., a private address). @@ -169,20 +203,22 @@ class Client implements ProviderInterface * @throws \GeoIp2\Exception\GeoIp2Exception This serves as the parent * class to the above exceptions. It will be thrown directly if a 200 * status code is returned but the body is invalid. + * + * @deprecated deprecated since version 0.7.0 */ - public function cityIspOrg($ipAddress = 'me') + public function insights($ipAddress = 'me') { - return $this->responseFor('city_isp_org', 'CityIspOrg', $ipAddress); + return $this->responseFor('insights', 'Insights', $ipAddress); } /** - * This method calls the GeoIP2 Omni endpoint. + * This method calls the GeoIP2 Precision: Insights (prev. Omni) endpoint. * * @param string $ipAddress IPv4 or IPv6 address as a string. If no * address is provided, the address that the web service is called * from will be used. * - * @return \GeoIp2\Model\Omni + * @return \GeoIp2\Model\Insights * * @throws \GeoIp2\Exception\AddressNotFoundException if the address you * provided is not in our database (e.g., a private address). @@ -201,10 +237,12 @@ class Client implements ProviderInterface * @throws \GeoIp2\Exception\GeoIp2Exception This serves as the parent * class to the above exceptions. It will be thrown directly if a 200 * status code is returned but the body is invalid. + * + * @deprecated deprecated since version 0.7.0 */ public function omni($ipAddress = 'me') { - return $this->responseFor('omni', 'Omni', $ipAddress); + return $this->insights($ipAddress); } private function responseFor($endpoint, $class, $ipAddress) @@ -354,6 +392,6 @@ class Client implements ProviderInterface private function baseUri() { - return 'https://' . $this->host . '/geoip/v2.0'; + return 'https://' . $this->host . '/geoip/v2.1'; } } diff --git a/tests/GeoIp2/Test/Model/OmniTest.php b/tests/GeoIp2/Test/Model/InsightsTest.php similarity index 92% rename from tests/GeoIp2/Test/Model/OmniTest.php rename to tests/GeoIp2/Test/Model/InsightsTest.php index 0f4ae7a..9bbb49d 100644 --- a/tests/GeoIp2/Test/Model/OmniTest.php +++ b/tests/GeoIp2/Test/Model/InsightsTest.php @@ -2,9 +2,9 @@ namespace GeoIp2\Test\Model; -use GeoIp2\Model\Omni; +use GeoIp2\Model\Insights; -class OmniTest extends \PHPUnit_Framework_TestCase +class InsightsTest extends \PHPUnit_Framework_TestCase { public function testFull() @@ -69,12 +69,12 @@ class OmniTest extends \PHPUnit_Framework_TestCase ), ); - $model = new Omni($raw, array('en')); + $model = new Insights($raw, array('en')); $this->assertInstanceOf( - 'GeoIp2\Model\Omni', + 'GeoIp2\Model\Insights', $model, - 'GeoIp2\Model\Omni object' + 'GeoIp2\Model\Insights object' ); $this->assertInstanceOf( @@ -147,12 +147,12 @@ class OmniTest extends \PHPUnit_Framework_TestCase { $raw = array('traits' => array('ip_address' => '5.6.7.8')); - $model = new Omni($raw, array('en')); + $model = new Insights($raw, array('en')); $this->assertInstanceOf( - 'GeoIp2\Model\Omni', + 'GeoIp2\Model\Insights', $model, - 'GeoIp2\Model\Omni object with no data except traits.ipAddress' + 'GeoIp2\Model\Insights object with no data except traits.ipAddress' ); $this->assertInstanceOf( @@ -231,12 +231,12 @@ class OmniTest extends \PHPUnit_Framework_TestCase ); // checking whether there are exceptions with unknown keys - $model = new Omni($raw, array('en')); + $model = new Insights($raw, array('en')); $this->assertInstanceOf( - 'GeoIp2\Model\Omni', + 'GeoIp2\Model\Insights', $model, - 'no exception when Omni model gets raw data with unknown keys' + 'no exception when Insights model gets raw data with unknown keys' ); $this->assertEquals( diff --git a/tests/GeoIp2/Test/WebService/ClientTest.php b/tests/GeoIp2/Test/WebService/ClientTest.php index 21a55bf..ae0f1a2 100644 --- a/tests/GeoIp2/Test/WebService/ClientTest.php +++ b/tests/GeoIp2/Test/WebService/ClientTest.php @@ -198,18 +198,22 @@ class ClientTest extends \PHPUnit_Framework_TestCase } - public function testOmni() + public function testInsights() { - $omni = $this->client($this->getResponse('1.2.3.4')) - ->omni('1.2.3.4'); - $this->assertInstanceOf('GeoIp2\Model\Omni', $omni); + $methods = array('omni', 'insights'); + foreach ($methods as $method) { + $record = $this->client($this->getResponse('1.2.3.4')) + ->$method('1.2.3.4'); - $this->assertEquals( - 42, - $omni->continent->geonameId, - 'continent geoname_id is 42' - ); + $this->assertInstanceOf('GeoIp2\Model\Insights', $record); + + $this->assertEquals( + 42, + $record->continent->geonameId, + 'continent geoname_id is 42' + ); + } } public function testCity() @@ -225,7 +229,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase $client = $this->client($this->getResponse('me')); $this->assertInstanceOf( - 'GeoIp2\Model\CityIspOrg', + 'GeoIp2\Model\City', $client->cityIspOrg('me'), 'can set ip parameter to me' ); @@ -233,7 +237,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase /** * @expectedException GeoIp2\Exception\GeoIp2Exception - * @expectedExceptionMessage Received a 200 response for https://geoip.maxmind.com/geoip/v2.0/country/1.2.3.5 but did not receive a HTTP body. + * @expectedExceptionMessage Received a 200 response for https://geoip.maxmind.com/geoip/v2.1/country/1.2.3.5 but did not receive a HTTP body. */ public function testNoBodyException() { @@ -244,7 +248,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase /** * @expectedException GeoIp2\Exception\GeoIp2Exception - * @expectedExceptionMessage Received a 200 response for https://geoip.maxmind.com/geoip/v2.0/country/2.2.3.5 but could not decode the response as JSON: + * @expectedExceptionMessage Received a 200 response for https://geoip.maxmind.com/geoip/v2.1/country/2.2.3.5 but could not decode the response as JSON: */ public function testBadBodyException() { @@ -332,7 +336,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase /** * @expectedException GeoIp2\Exception\HttpException * @expectedExceptionCode 406 - * @expectedExceptionMessage Received a 406 error for https://geoip.maxmind.com/geoip/v2.0/country/1.2.3.12 with the following body: Cannot satisfy your Accept-Charset requirements + * @expectedExceptionMessage Received a 406 error for https://geoip.maxmind.com/geoip/v2.1/country/1.2.3.12 with the following body: Cannot satisfy your Accept-Charset requirements */ public function test406Exception() { @@ -426,7 +430,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase $request = $all_requests[0]; $this->assertEquals( - 'https://geoip.maxmind.com/geoip/v2.0/country/1.2.3.4', + 'https://geoip.maxmind.com/geoip/v2.1/country/1.2.3.4', $request->getUrl(), 'got expected URI for Country request' ); From 6cf9b98993e0ec77edb8b5bffa1d6ed6ff111a4b Mon Sep 17 00:00:00 2001 From: Gregory Oschwaldmilitary
- * but this could expand to include other types such as embassy
- * in the future. Returned by all endpoints.
+ * but this could expand to include other types in the future.
*/
class RepresentedCountry extends Country
{
From 7d78bd9b2ea64fe7f399b1f62b4d43e9f8390c82 Mon Sep 17 00:00:00 2001
From: Gregory Oschwald - * This attribute is only available from the Insight web service end + * This attribute is only available from the Insights web service end * point. *
*/