diff --git a/CHANGELOG.md b/CHANGELOG.md index febb556..ac1c035 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ CHANGELOG * Update ApiGen dependency to version that isn't broken on case sensitive file systems. +* Added support for the GeoIP2 Anonymous IP database. The + `GeoIP2\Database\Reader` class now has an `anonymousIp` method which returns + a `GeoIP2\Model\AnonymousIp` object. 2.0.0 (2014-09-22) ------------------ 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 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" }, 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 8201e1e..fcc04a9 100644 --- a/src/GeoIp2/Database/Reader.php +++ b/src/GeoIp2/Database/Reader.php @@ -91,6 +91,39 @@ 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\AnonymousIp + * + * @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. + * + * @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 +133,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 +154,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( 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..e87b4a6 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->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(); + } public function testConnectionType() {