From 18686e11ac24ee5b41baaa92c6d72cd10d96ccff Mon Sep 17 00:00:00 2001 From: Dave Rolsky Date: Mon, 27 Oct 2014 16:06:26 -0500 Subject: [PATCH 1/8] Add docs for all model-returning methods on the Reader class --- src/GeoIp2/Database/Reader.php | 36 ++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/GeoIp2/Database/Reader.php b/src/GeoIp2/Database/Reader.php index 8201e1e..442a23e 100644 --- a/src/GeoIp2/Database/Reader.php +++ b/src/GeoIp2/Database/Reader.php @@ -91,6 +91,18 @@ class Reader implements ProviderInterface return $this->modelFor('Country', 'Country', $ipAddress); } + /** + * This method returns a GeoIP2 Connection Type model. + * + * @param string $ipAddress IPv4 or IPv6 address as a string. + * + * @return \GeoIp2\Model\ConnectionType + * + * @throws \GeoIp2\Exception\AddressNotFoundException if the address is + * not in the database. + * @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database + * is corrupt or invalid + */ public function connectionType($ipAddress) { return $this->flatModelFor( @@ -100,6 +112,18 @@ class Reader implements ProviderInterface ); } + /** + * This method returns a GeoIP2 Domain model. + * + * @param string $ipAddress IPv4 or IPv6 address as a string. + * + * @return \GeoIp2\Model\Domain + * + * @throws \GeoIp2\Exception\AddressNotFoundException if the address is + * not in the database. + * @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database + * is corrupt or invalid + */ public function domain($ipAddress) { return $this->flatModelFor( @@ -109,6 +133,18 @@ class Reader implements ProviderInterface ); } + /** + * This method returns a GeoIP2 ISP model. + * + * @param string $ipAddress IPv4 or IPv6 address as a string. + * + * @return \GeoIp2\Model\Isp + * + * @throws \GeoIp2\Exception\AddressNotFoundException if the address is + * not in the database. + * @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database + * is corrupt or invalid + */ public function isp($ipAddress) { return $this->flatModelFor( From fbf4583b3ee8d1f3dcbb194cd02fc146943af9e0 Mon Sep 17 00:00:00 2001 From: Dave Rolsky Date: Mon, 27 Oct 2014 16:30:40 -0500 Subject: [PATCH 2/8] Add support for Anonymous IP database --- maxmind-db | 2 +- src/GeoIp2/Database/Reader.php | 21 ++++++++++ src/GeoIp2/Model/AnonymousIp.php | 50 +++++++++++++++++++++++ tests/GeoIp2/Test/Database/ReaderTest.php | 14 +++++++ 4 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 src/GeoIp2/Model/AnonymousIp.php diff --git a/maxmind-db b/maxmind-db index 1d28147..e53ed8c 160000 --- a/maxmind-db +++ b/maxmind-db @@ -1 +1 @@ -Subproject commit 1d2814761753aefe32311cb917ab1e4f16d9fd7e +Subproject commit e53ed8cde6951be3bbd0fdb300d69c898b399a97 diff --git a/src/GeoIp2/Database/Reader.php b/src/GeoIp2/Database/Reader.php index 442a23e..a57b75d 100644 --- a/src/GeoIp2/Database/Reader.php +++ b/src/GeoIp2/Database/Reader.php @@ -91,6 +91,27 @@ class Reader implements ProviderInterface return $this->modelFor('Country', 'Country', $ipAddress); } + /** + * This method returns a GeoIP2 Anonymous IP model. + * + * @param string $ipAddress IPv4 or IPv6 address as a string. + * + * @return \GeoIp2\Model\Domain + * + * @throws \GeoIp2\Exception\AddressNotFoundException if the address is + * not in the database. + * @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database + * is corrupt or invalid + */ + public function anonymousIp($ipAddress) + { + return $this->flatModelFor( + 'AnonymousIp', + 'GeoIP2-Anonymous-IP', + $ipAddress + ); + } + /** * This method returns a GeoIP2 Connection Type model. * diff --git a/src/GeoIp2/Model/AnonymousIp.php b/src/GeoIp2/Model/AnonymousIp.php new file mode 100644 index 0000000..07f7800 --- /dev/null +++ b/src/GeoIp2/Model/AnonymousIp.php @@ -0,0 +1,50 @@ +isAnonymous = $this->get('is_anonymous'); + $this->isAnonymousVpn = $this->get('is_anonymous_vpn'); + $this->isHostingProvider = $this->get('is_hosting_provider'); + $this->isPublicProxy = $this->get('is_public_proxy'); + $this->isTorExitNode = $this->get('is_tor_exit_node'); + $this->ipAddress = $this->get('ip_address'); + } +} diff --git a/tests/GeoIp2/Test/Database/ReaderTest.php b/tests/GeoIp2/Test/Database/ReaderTest.php index 6a2d859..68a4732 100644 --- a/tests/GeoIp2/Test/Database/ReaderTest.php +++ b/tests/GeoIp2/Test/Database/ReaderTest.php @@ -88,6 +88,20 @@ class ReaderTest extends \PHPUnit_Framework_TestCase $reader->close(); } + public function testAnonymousIp() + { + $reader = new Reader('maxmind-db/test-data/GeoIP2-Anonymous-IP-Test.mmdb'); + $ipAddress = '1.2.0.1'; + + $record = $reader->anonymousIp($ipAddress); + $this->assertEquals(1, $record->isAnonymous); + $this->assertEquals(1, $record->isAnonymousVpn); + $this->assertEquals(0, $record->isHostingProvider); + $this->assertEquals(0, $record->isPublicProxy); + $this->assertEquals(0, $record->isTorExitNode); + $this->assertEquals($ipAddress, $record->ipAddress); + $reader->close(); + } public function testConnectionType() { From 0c6ba34623559dcaaf94db833deed76111529740 Mon Sep 17 00:00:00 2001 From: Dave Rolsky Date: Mon, 27 Oct 2014 16:39:20 -0500 Subject: [PATCH 3/8] Remove apigen dep --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index 76badab..fcfe5cf 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,6 @@ "php": ">=5.3.1" }, "require-dev": { - "apigen/apigen": "2.8.2", "phpunit/phpunit": "4.2.*", "satooshi/php-coveralls": "dev-master" }, From 9e6449290f0faada985189dde1832349905b11ab Mon Sep 17 00:00:00 2001 From: Dave Rolsky Date: Mon, 27 Oct 2014 17:21:10 -0500 Subject: [PATCH 4/8] Use assertSame instead of assertEquals to test boolean attributes --- tests/GeoIp2/Test/Database/ReaderTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/GeoIp2/Test/Database/ReaderTest.php b/tests/GeoIp2/Test/Database/ReaderTest.php index 68a4732..e87b4a6 100644 --- a/tests/GeoIp2/Test/Database/ReaderTest.php +++ b/tests/GeoIp2/Test/Database/ReaderTest.php @@ -94,11 +94,11 @@ class ReaderTest extends \PHPUnit_Framework_TestCase $ipAddress = '1.2.0.1'; $record = $reader->anonymousIp($ipAddress); - $this->assertEquals(1, $record->isAnonymous); - $this->assertEquals(1, $record->isAnonymousVpn); - $this->assertEquals(0, $record->isHostingProvider); - $this->assertEquals(0, $record->isPublicProxy); - $this->assertEquals(0, $record->isTorExitNode); + $this->assertSame(true, $record->isAnonymous); + $this->assertSame(true, $record->isAnonymousVpn); + $this->assertSame(null, $record->isHostingProvider); + $this->assertSame(null, $record->isPublicProxy); + $this->assertSame(null, $record->isTorExitNode); $this->assertEquals($ipAddress, $record->ipAddress); $reader->close(); } From 970d1dba45c74d516efeb9174b7eda1194d9b38b Mon Sep 17 00:00:00 2001 From: Dave Rolsky Date: Mon, 27 Oct 2014 17:21:38 -0500 Subject: [PATCH 5/8] Fix return vlaue docs for anonymousIp method --- src/GeoIp2/Database/Reader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GeoIp2/Database/Reader.php b/src/GeoIp2/Database/Reader.php index a57b75d..fcc04a9 100644 --- a/src/GeoIp2/Database/Reader.php +++ b/src/GeoIp2/Database/Reader.php @@ -96,7 +96,7 @@ class Reader implements ProviderInterface * * @param string $ipAddress IPv4 or IPv6 address as a string. * - * @return \GeoIp2\Model\Domain + * @return \GeoIp2\Model\AnonymousIp * * @throws \GeoIp2\Exception\AddressNotFoundException if the address is * not in the database. From 68593409680319152b9e95c55cad27af4bd64793 Mon Sep 17 00:00:00 2001 From: Dave Rolsky Date: Mon, 27 Oct 2014 17:24:27 -0500 Subject: [PATCH 6/8] Add Changes for Anonymous IP support --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index febb556..07aeb05 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ CHANGELOG * Update ApiGen dependency to version that isn't broken on case sensitive file systems. +* Added support for the GeoIP2 Anonymous IP database. The + `GeoIP\Database\Reader` class now has an `anonymousIp` method which returns + a `GeoIP2\Model\AnonymousIp` object. + 2.0.0 (2014-09-22) ------------------ From e5f61fd275396682c7dc64e9330f4e215aed4a4d Mon Sep 17 00:00:00 2001 From: Dave Rolsky Date: Tue, 28 Oct 2014 10:09:53 -0500 Subject: [PATCH 7/8] Add example for Anonymous-IP database in README.md --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index 80b64de..ff90f2d 100644 --- a/README.md +++ b/README.md @@ -114,6 +114,24 @@ print($record->location->longitude . "\n"); // -93.2323 ``` +### Anonymoous-IP Example ### + +```php +anonymousIp('128.101.101.101'); + +if ($record->isAnonymous) { print "anon\n"; } +print($record->ipAddress . "\n"); // '128.101.101.101' + +``` + ### Connection-Type Example ### ```php From ffc6493c8dd38ca853a3d118734b50a68a74bf75 Mon Sep 17 00:00:00 2001 From: Dave Rolsky Date: Tue, 28 Oct 2014 10:26:28 -0500 Subject: [PATCH 8/8] Fix small typo in CHANGELOG.md --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 07aeb05..ac1c035 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,9 +6,8 @@ CHANGELOG * Update ApiGen dependency to version that isn't broken on case sensitive file systems. - * Added support for the GeoIP2 Anonymous IP database. The - `GeoIP\Database\Reader` class now has an `anonymousIp` method which returns + `GeoIP2\Database\Reader` class now has an `anonymousIp` method which returns a `GeoIP2\Model\AnonymousIp` object. 2.0.0 (2014-09-22)