From e60181f13abb59374e70246e935ed3f3b076f7f2 Mon Sep 17 00:00:00 2001 From: Gregory Oschwald Date: Wed, 10 Jul 2013 15:24:40 -0700 Subject: [PATCH] Rename GeoIP2 => GeoIp2 for consistency --- .gitignore | 1 + README.md | 16 ++-- phpunit.xml.dist | 4 +- src/GeoIP2/Exception/GeoIP2Exception.php | 10 --- src/GeoIp2/Exception/GeoIp2Exception.php | 10 +++ .../Exception/HttpException.php | 4 +- .../Exception/WebServiceException.php | 2 +- src/{GeoIP2 => GeoIp2}/Model/City.php | 34 ++++----- src/{GeoIP2 => GeoIp2}/Model/CityIspOrg.php | 24 +++--- src/{GeoIP2 => GeoIp2}/Model/Country.php | 26 +++---- src/{GeoIP2 => GeoIp2}/Model/Omni.php | 24 +++--- .../Record/AbstractPlaceRecord.php | 2 +- .../Record/AbstractRecord.php | 2 +- src/{GeoIP2 => GeoIp2}/Record/City.php | 2 +- src/{GeoIP2 => GeoIp2}/Record/Continent.php | 2 +- src/{GeoIP2 => GeoIp2}/Record/Country.php | 2 +- src/{GeoIP2 => GeoIp2}/Record/Location.php | 2 +- src/{GeoIP2 => GeoIp2}/Record/MaxMind.php | 2 +- src/{GeoIP2 => GeoIp2}/Record/Postal.php | 2 +- .../Record/RepresentedCountry.php | 2 +- src/{GeoIP2 => GeoIp2}/Record/Subdivision.php | 2 +- src/{GeoIP2 => GeoIp2}/Record/Traits.php | 2 +- src/{GeoIP2 => GeoIp2}/WebService/Client.php | 74 +++++++++---------- .../Test/Model/CountryTest.php | 18 ++--- .../Test/Model/NameTest.php | 7 +- .../Test/Model/OmniTest.php | 48 ++++++------ .../Test/WebService/ClientTest.php | 30 ++++---- tests/bootstrap.php | 2 +- 28 files changed, 179 insertions(+), 177 deletions(-) delete mode 100644 src/GeoIP2/Exception/GeoIP2Exception.php create mode 100644 src/GeoIp2/Exception/GeoIp2Exception.php rename src/{GeoIP2 => GeoIp2}/Exception/HttpException.php (83%) rename src/{GeoIP2 => GeoIp2}/Exception/WebServiceException.php (94%) rename src/{GeoIP2 => GeoIp2}/Model/City.php (72%) rename src/{GeoIP2 => GeoIp2}/Model/CityIspOrg.php (68%) rename src/{GeoIP2 => GeoIp2}/Model/Country.php (72%) rename src/{GeoIP2 => GeoIp2}/Model/Omni.php (68%) rename src/{GeoIP2 => GeoIp2}/Record/AbstractPlaceRecord.php (96%) rename src/{GeoIP2 => GeoIp2}/Record/AbstractRecord.php (96%) rename src/{GeoIP2 => GeoIp2}/Record/City.php (97%) rename src/{GeoIP2 => GeoIp2}/Record/Continent.php (97%) rename src/{GeoIP2 => GeoIp2}/Record/Country.php (97%) rename src/{GeoIP2 => GeoIp2}/Record/Location.php (98%) rename src/{GeoIP2 => GeoIp2}/Record/MaxMind.php (93%) rename src/{GeoIP2 => GeoIp2}/Record/Postal.php (96%) rename src/{GeoIP2 => GeoIp2}/Record/RepresentedCountry.php (98%) rename src/{GeoIP2 => GeoIp2}/Record/Subdivision.php (98%) rename src/{GeoIP2 => GeoIp2}/Record/Traits.php (99%) rename src/{GeoIP2 => GeoIp2}/WebService/Client.php (83%) rename tests/{GeoIP2 => GeoIp2}/Test/Model/CountryTest.php (91%) rename tests/{GeoIP2 => GeoIp2}/Test/Model/NameTest.php (95%) rename tests/{GeoIP2 => GeoIp2}/Test/Model/OmniTest.php (86%) rename tests/{GeoIP2 => GeoIp2}/Test/WebService/ClientTest.php (92%) diff --git a/.gitignore b/.gitignore index ed7b1de..23f8cd7 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ _site composer.lock composer.phar phpunit.xml +geoip2-php.sublime-* vendor/ *.sw? t.php diff --git a/README.md b/README.md index 830b275..e78c267 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ In the future, this distribution will also provide the same API for the GeoIP2 downloadable databases. These databases have not yet been released as a downloadable product. -See ``GeoIP2\WebService\Client`` for details on the web service client +See ``GeoIp2\WebService\Client`` for details on the web service client API. ## Installation ## @@ -63,7 +63,7 @@ require 'vendor/autoload.php'; ## Usage ## -To use this API, you must create a new ``\GeoIP2\WebService\Client`` +To use this API, you must create a new ``\GeoIp2\WebService\Client`` object with your ``$userId`` and ``$licenseKey``, then you call the method corresponding to a specific end point, passing it the IP address you want to look up. @@ -79,7 +79,7 @@ See the API documentation for more details. ```php omni('24.24.24.24'); @@ -93,18 +93,18 @@ the [GeoIP2 web service docs](http://dev.maxmind.com/geoip2/geoip/web-service). If the web service returns an explicit error document, this is thrown as a -```\GeoIP2\Exception\WebServiceException```. If some other sort of transport -error occurs, this is thrown as a ```\GeoIP2\Exception\HttpException```. +```\GeoIp2\Exception\WebServiceException```. If some other sort of transport +error occurs, this is thrown as a ```\GeoIp2\Exception\HttpException```. The difference is that the web service error includes an error message and error code delivered by the web service. The latter is thrown when some sort of unanticipated error occurs, such as the web service returning a 500 or an invalid error document. If the web service returns any status code besides 200, 4xx, or 5xx, this also -becomes a ```\GeoIP2\Exception\HttpException```. +becomes a ```\GeoIp2\Exception\HttpException```. Finally, if the web service returns a 200 but the body is invalid, the client -throws a ```\GeoIP2\Exception\GeoIP2Exception```. +throws a ```\GeoIp2\Exception\GeoIp2Exception```. ## What data is returned? ## @@ -121,7 +121,7 @@ See the for details on what data each end point may return. The only piece of data which is always returned is the ```ipAddress``` -attribute in the ``GeoIP2\Record\Traits`` record. +attribute in the ``GeoIp2\Record\Traits`` record. Every record class attribute has a corresponding predicate method so you can check to see if the attribute is set. diff --git a/phpunit.xml.dist b/phpunit.xml.dist index e935730..5125fef 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -3,13 +3,13 @@ - ./tests/GeoIP2/Test/ + ./tests/GeoIp2/Test/ - ./src/GeoIP2/ + ./src/GeoIp2/ diff --git a/src/GeoIP2/Exception/GeoIP2Exception.php b/src/GeoIP2/Exception/GeoIP2Exception.php deleted file mode 100644 index 1e0c9a6..0000000 --- a/src/GeoIP2/Exception/GeoIP2Exception.php +++ /dev/null @@ -1,10 +0,0 @@ -city = new \GeoIP2\Record\City($this->get('city'), $languages); - $this->location = new \GeoIP2\Record\Location($this->get('location')); - $this->postal = new \GeoIP2\Record\Postal($this->get('postal')); + $this->city = new \GeoIp2\Record\City($this->get('city'), $languages); + $this->location = new \GeoIp2\Record\Location($this->get('location')); + $this->postal = new \GeoIp2\Record\Postal($this->get('postal')); $this->createSubdivisions($raw, $languages); } @@ -94,7 +94,7 @@ class City extends Country foreach ($raw['subdivisions'] as $sub) { array_push( $this->subdivisions, - new \GeoIP2\Record\Subdivision($sub, $languages) + new \GeoIp2\Record\Subdivision($sub, $languages) ); } } @@ -114,7 +114,7 @@ class City extends Country private function mostSpecificSubdivision() { return empty($this->subdivisions)? - new \GeoIP2\Record\Subdivision(array(), $this->languages): + new \GeoIp2\Record\Subdivision(array(), $this->languages): end($this->subdivisions); } } diff --git a/src/GeoIP2/Model/CityIspOrg.php b/src/GeoIp2/Model/CityIspOrg.php similarity index 68% rename from src/GeoIP2/Model/CityIspOrg.php rename to src/GeoIp2/Model/CityIspOrg.php index 3badfe5..79ead9d 100644 --- a/src/GeoIP2/Model/CityIspOrg.php +++ b/src/GeoIp2/Model/CityIspOrg.php @@ -1,6 +1,6 @@ raw = $raw; - $this->continent = new \GeoIP2\Record\Continent( + $this->continent = new \GeoIp2\Record\Continent( $this->get('continent'), $languages ); - $this->country = new \GeoIP2\Record\Country( + $this->country = new \GeoIp2\Record\Country( $this->get('country'), $languages ); - $this->maxmind = new \GeoIP2\Record\MaxMind($this->get('maxmind')); - $this->registeredCountry = new \GeoIP2\Record\Country( + $this->maxmind = new \GeoIp2\Record\MaxMind($this->get('maxmind')); + $this->registeredCountry = new \GeoIp2\Record\Country( $this->get('registered_country'), $languages ); - $this->representedCountry = new \GeoIP2\Record\RepresentedCountry( + $this->representedCountry = new \GeoIp2\Record\RepresentedCountry( $this->get('represented_country'), $languages ); - $this->traits = new \GeoIP2\Record\Traits($this->get('traits')); + $this->traits = new \GeoIp2\Record\Traits($this->get('traits')); $this->languages = $languages; } diff --git a/src/GeoIP2/Model/Omni.php b/src/GeoIp2/Model/Omni.php similarity index 68% rename from src/GeoIP2/Model/Omni.php rename to src/GeoIp2/Model/Omni.php index 4445a04..19dbb71 100644 --- a/src/GeoIP2/Model/Omni.php +++ b/src/GeoIp2/Model/Omni.php @@ -1,6 +1,6 @@ isSuccessful()) { $body = $this->handleSuccess($response, $uri); - $class = "GeoIP2\\Model\\" . $class; + $class = "GeoIp2\\Model\\" . $class; return new $class($body, $this->languages); } else { $this->handleNon200($response, $uri); @@ -216,7 +216,7 @@ class Client private function handleSuccess($response, $uri) { if ($response->getContentLength() == 0) { - throw new GeoIP2Exception( + throw new GeoIp2Exception( "Received a 200 response for $uri but did not " . "receive a HTTP body." ); @@ -225,7 +225,7 @@ class Client try { return $response->json(); } catch (RuntimeException $e) { - throw new GeoIP2Exception( + throw new GeoIp2Exception( "Received a 200 response for $uri but could not decode " . "the response as JSON: " . $e->getMessage() ); @@ -244,7 +244,7 @@ class Client try { $body = $response->json(); if (!isset($body['code']) || !isset($body['error'])) { - throw new GeoIP2Exception( + throw new GeoIp2Exception( 'Response contains JSON but it does not specify ' . 'code or error keys: ' . $response->getBody() ); diff --git a/tests/GeoIP2/Test/Model/CountryTest.php b/tests/GeoIp2/Test/Model/CountryTest.php similarity index 91% rename from tests/GeoIP2/Test/Model/CountryTest.php rename to tests/GeoIp2/Test/Model/CountryTest.php index f456aa4..7a54fcd 100644 --- a/tests/GeoIP2/Test/Model/CountryTest.php +++ b/tests/GeoIp2/Test/Model/CountryTest.php @@ -1,8 +1,8 @@ assertInstanceOf( - 'GeoIP2\Model\Country', + 'GeoIp2\Model\Country', $this->model, - 'minimal GeoIP2::Model::Country object' + 'minimal GeoIp2::Model::Country object' ); $this->assertInstanceOf( - 'GeoIP2\Record\Continent', + 'GeoIp2\Record\Continent', $this->model->continent ); $this->assertInstanceOf( - 'GeoIP2\Record\Country', + 'GeoIp2\Record\Country', $this->model->country ); $this->assertInstanceOf( - 'GeoIP2\Record\Country', + 'GeoIp2\Record\Country', $this->model->registeredCountry ); $this->assertInstanceOf( - 'GeoIP2\Record\RepresentedCountry', + 'GeoIp2\Record\RepresentedCountry', $this->model->representedCountry ); $this->assertInstanceOf( - 'GeoIP2\Record\Traits', + 'GeoIp2\Record\Traits', $this->model->traits ); } diff --git a/tests/GeoIP2/Test/Model/NameTest.php b/tests/GeoIp2/Test/Model/NameTest.php similarity index 95% rename from tests/GeoIP2/Test/Model/NameTest.php rename to tests/GeoIp2/Test/Model/NameTest.php index c34686d..9b3cfaf 100644 --- a/tests/GeoIP2/Test/Model/NameTest.php +++ b/tests/GeoIp2/Test/Model/NameTest.php @@ -1,8 +1,8 @@ raw, array('ru', 'ja')); $this->assertEquals( diff --git a/tests/GeoIP2/Test/Model/OmniTest.php b/tests/GeoIp2/Test/Model/OmniTest.php similarity index 86% rename from tests/GeoIP2/Test/Model/OmniTest.php rename to tests/GeoIp2/Test/Model/OmniTest.php index 00dc5d3..343fa0a 100644 --- a/tests/GeoIP2/Test/Model/OmniTest.php +++ b/tests/GeoIp2/Test/Model/OmniTest.php @@ -1,8 +1,8 @@ assertInstanceOf( - 'GeoIP2\Model\Omni', + 'GeoIp2\Model\Omni', $model, - 'GeoIP2\Model\Omni object' + 'GeoIp2\Model\Omni object' ); $this->assertInstanceOf( - 'GeoIP2\Record\City', + 'GeoIp2\Record\City', $model->city, '$model->city' ); $this->assertInstanceOf( - 'GeoIP2\Record\Continent', + 'GeoIp2\Record\Continent', $model->continent, '$model->continent' ); $this->assertInstanceOf( - 'GeoIP2\Record\Country', + 'GeoIp2\Record\Country', $model->country, '$model->country' ); $this->assertInstanceOf( - 'GeoIP2\Record\Location', + 'GeoIp2\Record\Location', $model->location, '$model->location' ); $this->assertInstanceOf( - 'GeoIP2\Record\Country', + 'GeoIp2\Record\Country', $model->registeredCountry, '$model->registeredCountry' ); $this->assertInstanceOf( - 'GeoIP2\Record\RepresentedCountry', + 'GeoIp2\Record\RepresentedCountry', $model->representedCountry, '$model->representedCountry' ); $subdivisions = $model->subdivisions; foreach ($subdivisions as $subdiv) { - $this->assertInstanceOf('GeoIP2\Record\Subdivision', $subdiv); + $this->assertInstanceOf('GeoIp2\Record\Subdivision', $subdiv); } $this->assertInstanceOf( - 'GeoIP2\Record\Subdivision', + 'GeoIp2\Record\Subdivision', $model->mostSpecificSubdivision, '$model->mostSpecificSubdivision' ); $this->assertInstanceOf( - 'GeoIP2\Record\Traits', + 'GeoIp2\Record\Traits', $model->traits, '$model->traits' ); @@ -150,43 +150,43 @@ class OmniTest extends \PHPUnit_Framework_TestCase $model = new Omni($raw, array('en')); $this->assertInstanceOf( - 'GeoIP2\Model\Omni', + 'GeoIp2\Model\Omni', $model, - 'GeoIP2\Model\Omni object with no data except traits.ipAddress' + 'GeoIp2\Model\Omni object with no data except traits.ipAddress' ); $this->assertInstanceOf( - 'GeoIP2\Record\City', + 'GeoIp2\Record\City', $model->city, '$model->city' ); $this->assertInstanceOf( - 'GeoIP2\Record\Continent', + 'GeoIp2\Record\Continent', $model->continent, '$model->continent' ); $this->assertInstanceOf( - 'GeoIP2\Record\Country', + 'GeoIp2\Record\Country', $model->country, '$model->country' ); $this->assertInstanceOf( - 'GeoIP2\Record\Location', + 'GeoIp2\Record\Location', $model->location, '$model->location' ); $this->assertInstanceOf( - 'GeoIP2\Record\Country', + 'GeoIp2\Record\Country', $model->registeredCountry, '$model->registeredCountry' ); $this->assertInstanceOf( - 'GeoIP2\Record\RepresentedCountry', + 'GeoIp2\Record\RepresentedCountry', $model->representedCountry, '$model->representedCountry' ); @@ -198,13 +198,13 @@ class OmniTest extends \PHPUnit_Framework_TestCase ); $this->assertInstanceOf( - 'GeoIP2\Record\Subdivision', + 'GeoIp2\Record\Subdivision', $model->mostSpecificSubdivision, '$model->mostSpecificSubdivision' ); $this->assertInstanceOf( - 'GeoIP2\Record\Traits', + 'GeoIp2\Record\Traits', $model->traits, '$model->traits' ); @@ -234,7 +234,7 @@ class OmniTest extends \PHPUnit_Framework_TestCase $model = new Omni($raw, array('en')); $this->assertInstanceOf( - 'GeoIP2\Model\Omni', + 'GeoIp2\Model\Omni', $model, 'no exception when Omni model gets raw data with unknown keys' ); diff --git a/tests/GeoIP2/Test/WebService/ClientTest.php b/tests/GeoIp2/Test/WebService/ClientTest.php similarity index 92% rename from tests/GeoIP2/Test/WebService/ClientTest.php rename to tests/GeoIp2/Test/WebService/ClientTest.php index 8b0f4a9..f8d9e96 100644 --- a/tests/GeoIP2/Test/WebService/ClientTest.php +++ b/tests/GeoIp2/Test/WebService/ClientTest.php @@ -1,8 +1,8 @@ client($this->getResponse('1.2.3.4')) ->country('1.2.3.4'); - $this->assertInstanceOf('GeoIP2\Model\Country', $country); + $this->assertInstanceOf('GeoIp2\Model\Country', $country); $this->assertEquals( 42, @@ -155,7 +155,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase $omni = $this->client($this->getResponse('1.2.3.4')) ->omni('1.2.3.4'); - $this->assertInstanceOf('GeoIP2\Model\Omni', $omni); + $this->assertInstanceOf('GeoIp2\Model\Omni', $omni); $this->assertEquals( 42, @@ -169,7 +169,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase $city = $this->client($this->getResponse('1.2.3.4')) ->city('1.2.3.4'); - $this->assertInstanceOf('GeoIP2\Model\City', $city); + $this->assertInstanceOf('GeoIp2\Model\City', $city); } public function testMe() @@ -177,14 +177,14 @@ class ClientTest extends \PHPUnit_Framework_TestCase $client = $this->client($this->getResponse('me')); $this->assertInstanceOf( - 'GeoIP2\Model\CityIspOrg', + 'GeoIp2\Model\CityIspOrg', $client->cityIspOrg('me'), 'can set ip parameter to me' ); } /** - * @expectedException GeoIP2\Exception\GeoIP2Exception + * @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. */ public function testNoBodyException() @@ -195,7 +195,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException GeoIP2\Exception\GeoIP2Exception + * @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: */ public function testBadBodyException() @@ -207,7 +207,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase /** - * @expectedException GeoIP2\Exception\WebServiceException + * @expectedException GeoIp2\Exception\WebServiceException * @expectedExceptionCode 400 * @expectedExceptionMessage The value "1.2.3" is not a valid ip address */ @@ -220,7 +220,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException GeoIP2\Exception\HttpException + * @expectedException GeoIp2\Exception\HttpException * @expectedExceptionCode 400 * @expectedExceptionMessage with no body */ @@ -232,7 +232,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException GeoIP2\Exception\GeoIP2Exception + * @expectedException GeoIp2\Exception\GeoIp2Exception * @expectedExceptionMessage Response contains JSON but it does not specify code or error keys */ public function testWeirdErrorBodyIPException() @@ -244,7 +244,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException GeoIP2\Exception\HttpException + * @expectedException GeoIp2\Exception\HttpException * @expectedExceptionCode 400 * @expectedExceptionMessage did not include the expected JSON body */ @@ -257,7 +257,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException GeoIP2\Exception\HttpException + * @expectedException GeoIp2\Exception\HttpException * @expectedExceptionCode 500 * @expectedExceptionMessage Received a server error (500) */ @@ -270,7 +270,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException GeoIP2\Exception\HttpException + * @expectedException GeoIp2\Exception\HttpException * @expectedExceptionCode 300 * @expectedExceptionMessage Received a very surprising HTTP status (300) */ @@ -283,7 +283,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException GeoIP2\Exception\HttpException + * @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 */ diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 55b6856..398bd62 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -4,4 +4,4 @@ if (!$loader = @include __DIR__.'/../vendor/autoload.php') { die('Project dependencies missing'); } -$loader->add('GeoIP2\Test', __DIR__); +$loader->add('GeoIp2\Test', __DIR__);