Compare commits
No commits in common. "master" and "v0.6.3" have entirely different histories.
6
.gitignore
vendored
6
.gitignore
vendored
@ -1,14 +1,12 @@
|
|||||||
_site
|
_site
|
||||||
.gh-pages
|
.gh-pages
|
||||||
.idea
|
.idea
|
||||||
GeoLite2-City.mmdb
|
|
||||||
apigen.phar
|
|
||||||
box.phar
|
|
||||||
build
|
|
||||||
composer.lock
|
composer.lock
|
||||||
composer.phar
|
composer.phar
|
||||||
phpunit.xml
|
phpunit.xml
|
||||||
|
geoip2.phar
|
||||||
geoip2-php.sublime-*
|
geoip2-php.sublime-*
|
||||||
vendor/
|
vendor/
|
||||||
*.sw?
|
*.sw?
|
||||||
|
t.php
|
||||||
*.old
|
*.old
|
||||||
|
58
CHANGELOG.md
58
CHANGELOG.md
@ -1,64 +1,6 @@
|
|||||||
CHANGELOG
|
CHANGELOG
|
||||||
=========
|
=========
|
||||||
|
|
||||||
2.1.1 (2014-12-03)
|
|
||||||
------------------
|
|
||||||
|
|
||||||
* The 2.1.0 Phar builds included a shebang line, causing issues when loading
|
|
||||||
it as a library. This has been corrected. GitHub #33.
|
|
||||||
|
|
||||||
2.1.0 (2014-10-29)
|
|
||||||
------------------
|
|
||||||
|
|
||||||
* 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.
|
|
||||||
* Boolean attributes like those in the `GeoIP2\Record\Traits` class now return
|
|
||||||
`false` instead of `null` when they were not true.
|
|
||||||
|
|
||||||
2.0.0 (2014-09-22)
|
|
||||||
------------------
|
|
||||||
|
|
||||||
* First production release.
|
|
||||||
|
|
||||||
0.9.0 (2014-09-15)
|
|
||||||
------------------
|
|
||||||
|
|
||||||
* IMPORTANT: The deprecated `omni()` and `cityIspOrg()` methods have been
|
|
||||||
removed from `GeoIp2\WebService\Client`.
|
|
||||||
|
|
||||||
0.8.1 (2014-09-12)
|
|
||||||
------------------
|
|
||||||
|
|
||||||
* The check added to the `GeoIP2\Database\Reader` lookup methods in 0.8.0 did
|
|
||||||
not work with the GeoIP2 City Database Subset by Continent with World
|
|
||||||
Countries. This has been fixed. Fixes GitHub issue #23.
|
|
||||||
|
|
||||||
0.8.0 (2014-09-10)
|
|
||||||
------------------
|
|
||||||
|
|
||||||
* The `GeoIp2\Database\Reader` lookup methods (e.g., `city()`, `isp()`) now
|
|
||||||
throw a `BadMethodCallException` if they are used with a database that
|
|
||||||
does not match the method. In particular, doing a `city()` lookup on a
|
|
||||||
GeoIP2 Country database will result in an exception, and vice versa.
|
|
||||||
* A `metadata()` method has been added to the `GeoIP2\Database\Reader` class.
|
|
||||||
This returns a `MaxMind\Db\Reader\Metadata` class with information about the
|
|
||||||
database.
|
|
||||||
* The name attribute was missing from the RepresentedCountry class.
|
|
||||||
|
|
||||||
0.7.0 (2014-07-22)
|
|
||||||
------------------
|
|
||||||
|
|
||||||
* The web service client API has been updated for the v2.1 release of the web
|
|
||||||
service. In particular, the `cityIspOrg` and `omni` methods on
|
|
||||||
`GeoIp2\WebService\Client` should be considered deprecated. The `city`
|
|
||||||
method now provides all of the data formerly provided by `cityIspOrg`, and
|
|
||||||
the `omni` method has been replaced by the `insights` method.
|
|
||||||
* Support was added for GeoIP2 Connection Type, Domain and ISP databases.
|
|
||||||
|
|
||||||
|
|
||||||
0.6.3 (2014-05-12)
|
0.6.3 (2014-05-12)
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
|
130
README.md
130
README.md
@ -9,40 +9,44 @@ the free [GeoLite2 databases](http://dev.maxmind.com/geoip/geoip2/geolite2/).
|
|||||||
|
|
||||||
## Install via Composer ##
|
## Install via Composer ##
|
||||||
|
|
||||||
|
### Define Your Dependencies ###
|
||||||
|
|
||||||
We recommend installing this package with [Composer](http://getcomposer.org/).
|
We recommend installing this package with [Composer](http://getcomposer.org/).
|
||||||
|
To do this, add `geoip2/geoip2` to your `composer.json` file. If you don't
|
||||||
|
have a `composer.json` file, create one in the root directory of your project.
|
||||||
|
|
||||||
### Download Composer ###
|
```json
|
||||||
|
{
|
||||||
To download Composer, run in the root directory of your project:
|
"require": {
|
||||||
|
"geoip2/geoip2": "0.6.*"
|
||||||
```bash
|
}
|
||||||
curl -sS https://getcomposer.org/installer | php
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
You should now have the file `composer.phar` in your project directory.
|
### Install Composer ###
|
||||||
|
|
||||||
|
Run in your project root:
|
||||||
|
|
||||||
|
```
|
||||||
|
curl -s http://getcomposer.org/installer | php
|
||||||
|
```
|
||||||
|
|
||||||
### Install Dependencies ###
|
### Install Dependencies ###
|
||||||
|
|
||||||
Run in your project root:
|
Run in your project root:
|
||||||
|
|
||||||
```
|
```
|
||||||
php composer.phar require geoip2/geoip2:~2.0
|
php composer.phar install
|
||||||
```
|
```
|
||||||
|
|
||||||
You should now have the files `composer.json` and `composer.lock` as well as
|
|
||||||
the directory `vendor` in your project directory. If you use a version control
|
|
||||||
system, `composer.json` should be added to it.
|
|
||||||
|
|
||||||
### Require Autoloader ###
|
### Require Autoloader ###
|
||||||
|
|
||||||
After installing the dependencies, you need to require the Composer autoloader
|
You can autoload all dependencies by adding this to your code:
|
||||||
from your code:
|
```
|
||||||
|
|
||||||
```php
|
|
||||||
require 'vendor/autoload.php';
|
require 'vendor/autoload.php';
|
||||||
```
|
```
|
||||||
|
|
||||||
## Install via Phar ##
|
## Installing via Phar ##
|
||||||
|
|
||||||
Although we strongly recommend using Composer, we also provide a
|
Although we strongly recommend using Composer, we also provide a
|
||||||
[phar archive](http://php.net/manual/en/book.phar.php) containing all of the
|
[phar archive](http://php.net/manual/en/book.phar.php) containing all of the
|
||||||
@ -83,7 +87,7 @@ is thrown. If the database is invalid or corrupt, a
|
|||||||
|
|
||||||
See the API documentation for more details.
|
See the API documentation for more details.
|
||||||
|
|
||||||
### City Example ###
|
### Example ###
|
||||||
|
|
||||||
```php
|
```php
|
||||||
<?php
|
<?php
|
||||||
@ -114,82 +118,6 @@ print($record->location->longitude . "\n"); // -93.2323
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Anonymous IP Example ###
|
|
||||||
|
|
||||||
```php
|
|
||||||
<?php
|
|
||||||
require_once 'vendor/autoload.php';
|
|
||||||
use GeoIp2\Database\Reader;
|
|
||||||
|
|
||||||
// This creates the Reader object, which should be reused across
|
|
||||||
// lookups.
|
|
||||||
$reader = new Reader('/usr/local/share/GeoIP/GeoIP2-Anonymous-IP.mmdb');
|
|
||||||
|
|
||||||
$record = $reader->anonymousIp('128.101.101.101');
|
|
||||||
|
|
||||||
if ($record->isAnonymous) { print "anon\n"; }
|
|
||||||
print($record->ipAddress . "\n"); // '128.101.101.101'
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
### Connection-Type Example ###
|
|
||||||
|
|
||||||
```php
|
|
||||||
<?php
|
|
||||||
require_once 'vendor/autoload.php';
|
|
||||||
use GeoIp2\Database\Reader;
|
|
||||||
|
|
||||||
// This creates the Reader object, which should be reused across
|
|
||||||
// lookups.
|
|
||||||
$reader = new Reader('/usr/local/share/GeoIP/GeoIP2-Connection-Type.mmdb');
|
|
||||||
|
|
||||||
$record = $reader->connectionType('128.101.101.101');
|
|
||||||
|
|
||||||
print($record->connectionType . "\n"); // 'Corporate'
|
|
||||||
print($record->ipAddress . "\n"); // '128.101.101.101'
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
### Domain Example ###
|
|
||||||
|
|
||||||
```php
|
|
||||||
<?php
|
|
||||||
require_once 'vendor/autoload.php';
|
|
||||||
use GeoIp2\Database\Reader;
|
|
||||||
|
|
||||||
// This creates the Reader object, which should be reused across
|
|
||||||
// lookups.
|
|
||||||
$reader = new Reader('/usr/local/share/GeoIP/GeoIP2-Domain.mmdb');
|
|
||||||
|
|
||||||
$record = $reader->domain('128.101.101.101');
|
|
||||||
|
|
||||||
print($record->domain . "\n"); // 'umn.edu'
|
|
||||||
print($record->ipAddress . "\n"); // '128.101.101.101'
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
### ISP Example ###
|
|
||||||
|
|
||||||
```php
|
|
||||||
<?php
|
|
||||||
require_once 'vendor/autoload.php';
|
|
||||||
use GeoIp2\Database\Reader;
|
|
||||||
|
|
||||||
// This creates the Reader object, which should be reused across
|
|
||||||
// lookups.
|
|
||||||
$reader = new Reader('/usr/local/share/GeoIP/GeoIP2-ISP.mmdb');
|
|
||||||
|
|
||||||
$record = $reader->isp('128.101.101.101');
|
|
||||||
|
|
||||||
print($record->autonomousSystemNumber . "\n"); // 217
|
|
||||||
print($record->autonomousSystemOrganization . "\n"); // 'University of Minnesota'
|
|
||||||
print($record->isp . "\n"); // 'University of Minnesota'
|
|
||||||
print($record->organization . "\n"); // 'University of Minnesota'
|
|
||||||
|
|
||||||
print($record->ipAddress . "\n"); // '128.101.101.101'
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
## Web Service Client ##
|
## Web Service Client ##
|
||||||
|
|
||||||
### Usage ###
|
### Usage ###
|
||||||
@ -220,7 +148,7 @@ use GeoIp2\WebService\Client;
|
|||||||
$client = new Client(42, 'abcdef123456');
|
$client = new Client(42, 'abcdef123456');
|
||||||
|
|
||||||
// Replace "city" with the method corresponding to the web service that
|
// Replace "city" with the method corresponding to the web service that
|
||||||
// you are using, e.g., "country", "insights".
|
// you are using, e.g., "country", "cityIspOrg", "omni".
|
||||||
$record = $client->city('128.101.101.101');
|
$record = $client->city('128.101.101.101');
|
||||||
|
|
||||||
print($record->country->isoCode . "\n"); // 'US'
|
print($record->country->isoCode . "\n"); // 'US'
|
||||||
@ -250,12 +178,15 @@ Because of these factors, it is possible for any end point to return a record
|
|||||||
where some or all of the attributes are unpopulated.
|
where some or all of the attributes are unpopulated.
|
||||||
|
|
||||||
See the
|
See the
|
||||||
[GeoIP2 Precision web service docs](http://dev.maxmind.com/geoip/geoip2/web-services)
|
[GeoIP2 web service docs](http://dev.maxmind.com/geoip/geoip2/web-services)
|
||||||
for details on what data each end point may return.
|
for details on what data each end point may return.
|
||||||
|
|
||||||
The only piece of data which is always returned is the `ipAddress`
|
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.
|
||||||
|
|
||||||
## Integration with GeoNames ##
|
## Integration with GeoNames ##
|
||||||
|
|
||||||
[GeoNames](http://www.geonames.org/) offers web services and downloadable
|
[GeoNames](http://www.geonames.org/) offers web services and downloadable
|
||||||
@ -305,16 +236,13 @@ supported.
|
|||||||
|
|
||||||
This library works and is tested with HHVM.
|
This library works and is tested with HHVM.
|
||||||
|
|
||||||
This library also relies on the [Guzzle3 HTTP client](https://github.com/guzzle/guzzle3)
|
This library also relies on the [Guzzle HTTP client](http://guzzlephp.org/)
|
||||||
and the [MaxMind DB Reader](https://github.com/maxmind/MaxMind-DB-Reader-php).
|
and the [MaxMind DB Reader](https://github.com/maxmind/MaxMind-DB-Reader-php).
|
||||||
|
|
||||||
If you are using PHP 5.3 with an autoloader besides Composer, you must load
|
|
||||||
`JsonSerializable.php` in the `compat` directory.
|
|
||||||
|
|
||||||
## Contributing ##
|
## Contributing ##
|
||||||
|
|
||||||
Patches and pull requests are encouraged. All code should follow the
|
Patches and pull requests are encouraged. All code should follow the
|
||||||
PSR-2 style guidelines. Please include unit tests whenever possible. You may obtain the test data for the maxmind-db folder by running `git submodule update --init --recursive` or adding `--recursive` to your initial clone, or from https://github.com/maxmind/MaxMind-DB
|
PSR-2 style guidelines. Please include unit tests whenever possible.
|
||||||
|
|
||||||
## Versioning ##
|
## Versioning ##
|
||||||
|
|
||||||
|
@ -1,26 +0,0 @@
|
|||||||
#!/usr/bin/env php
|
|
||||||
|
|
||||||
<?php
|
|
||||||
|
|
||||||
require_once '../vendor/autoload.php';
|
|
||||||
|
|
||||||
use GeoIp2\Database\Reader;
|
|
||||||
use GeoIp2\Exception\AddressNotFoundException;
|
|
||||||
|
|
||||||
$reader = new Reader('GeoLite2-City.mmdb');
|
|
||||||
$count = 40000;
|
|
||||||
$startTime = microtime(true);
|
|
||||||
for ($i = 0; $i < $count; $i++) {
|
|
||||||
$ip = long2ip(rand(0, pow(2, 32) -1));
|
|
||||||
try {
|
|
||||||
$t = $reader->city($ip);
|
|
||||||
} catch (AddressNotFoundException $e) {
|
|
||||||
}
|
|
||||||
if ($i % 1000 == 0) {
|
|
||||||
print($i . ' ' . $ip . "\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$endTime = microtime(true);
|
|
||||||
|
|
||||||
$duration = $endTime - $startTime;
|
|
||||||
print('Requests per second: ' . $count / $duration . "\n");
|
|
63
bin/release.sh
Executable file
63
bin/release.sh
Executable file
@ -0,0 +1,63 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
TAG=$1
|
||||||
|
|
||||||
|
if [ -z $TAG ]; then
|
||||||
|
echo "Please specify a tag"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$(git status --porcelain)" ]; then
|
||||||
|
echo ". is not clean." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -d .gh-pages ]; then
|
||||||
|
echo "Checking out gh-pages in .gh-pages"
|
||||||
|
git clone -b gh-pages git@git.maxmind.com:GeoIP2-php .gh-pages
|
||||||
|
cd .gh-pages
|
||||||
|
else
|
||||||
|
echo "Updating .gh-pages"
|
||||||
|
cd .gh-pages
|
||||||
|
git pull
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$(git status --porcelain)" ]; then
|
||||||
|
echo ".gh-pages is not clean" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
apigen --quiet --download --title "GeoIP2 PHP API $TAG" --source ../src --destination doc/$TAG
|
||||||
|
|
||||||
|
PAGE=index.md
|
||||||
|
cat <<EOF > $PAGE
|
||||||
|
---
|
||||||
|
layout: default
|
||||||
|
title: MaxMind GeoIP2 PHP API
|
||||||
|
language: php
|
||||||
|
version: $TAG
|
||||||
|
---
|
||||||
|
|
||||||
|
EOF
|
||||||
|
|
||||||
|
cat ../README.md >> $PAGE
|
||||||
|
|
||||||
|
git add doc/
|
||||||
|
git commit -m "Updated for $TAG" -a
|
||||||
|
|
||||||
|
read -e -p "Push to origin? " SHOULD_PUSH
|
||||||
|
|
||||||
|
if [ "$SHOULD_PUSH" != "y" ]; then
|
||||||
|
echo "Aborting"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If we don't push directly to github, the page doesn't get built for some
|
||||||
|
# reason.
|
||||||
|
git push git@github.com:maxmind/GeoIP2-php.git
|
||||||
|
git push
|
||||||
|
|
||||||
|
cd ..
|
||||||
|
git tag -a $TAG
|
||||||
|
git push
|
||||||
|
git push --tags
|
4
box.json
4
box.json
@ -13,8 +13,6 @@
|
|||||||
"finder": [
|
"finder": [
|
||||||
{
|
{
|
||||||
"name": [
|
"name": [
|
||||||
"LICENSE",
|
|
||||||
"LICENSE.*",
|
|
||||||
"*.php",
|
"*.php",
|
||||||
"*.pem",
|
"*.pem",
|
||||||
"*.pem.md5"
|
"*.pem.md5"
|
||||||
@ -29,8 +27,8 @@
|
|||||||
"in": "vendor"
|
"in": "vendor"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
"directories": ["compat", "src/"],
|
"directories": ["compat", "src/"],
|
||||||
"git-version": "git-version",
|
"git-version": "git-version",
|
||||||
"shebang": false,
|
|
||||||
"stub": true
|
"stub": true
|
||||||
}
|
}
|
||||||
|
@ -14,11 +14,11 @@
|
|||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"guzzle/guzzle": "3.*",
|
"guzzle/guzzle": "3.*",
|
||||||
"maxmind-db/reader": "~1.0",
|
"maxmind-db/reader": "~0.3.1",
|
||||||
"php": ">=5.3.1"
|
"php": ">=5.3.1"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "4.2.*",
|
"phpunit/phpunit": "3.7.*",
|
||||||
"satooshi/php-coveralls": "dev-master"
|
"satooshi/php-coveralls": "dev-master"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
#!/usr/bin/env php
|
|
||||||
<?php
|
|
||||||
require_once 'geoip2.phar';
|
|
||||||
use GeoIp2\Database\Reader;
|
|
||||||
|
|
||||||
$reader = new Reader('maxmind-db/test-data/GeoIP2-City-Test.mmdb');
|
|
||||||
|
|
||||||
$record = $reader->city('81.2.69.160');
|
|
||||||
|
|
||||||
if ( $record->country->isoCode === 'GB' ) {
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
print('Problem with Phar!');
|
|
||||||
exit(1);
|
|
@ -1,112 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
TAG=$1
|
|
||||||
|
|
||||||
if [ -z $TAG ]; then
|
|
||||||
echo "Please specify a tag"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -f geoip2.phar ]; then
|
|
||||||
rm geoip2.phar
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -n "$(git status --porcelain)" ]; then
|
|
||||||
echo ". is not clean." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -d vendor ]; then
|
|
||||||
rm -fr vendor
|
|
||||||
fi
|
|
||||||
|
|
||||||
php composer.phar self-update
|
|
||||||
php composer.phar update --no-dev
|
|
||||||
|
|
||||||
if [ ! -f box.phar ]; then
|
|
||||||
wget -O box.phar "https://github.com/box-project/box2/releases/download/2.5.0/box-2.5.0.phar"
|
|
||||||
fi
|
|
||||||
|
|
||||||
php box.phar build
|
|
||||||
|
|
||||||
PHAR_TEST=$(./dev-bin/phar-test.php)
|
|
||||||
if [[ -n $PHAR_TEST ]]; then
|
|
||||||
echo "Phar test outputed non-empty string: $PHAR_TEST"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Download test deps
|
|
||||||
php composer.phar update
|
|
||||||
|
|
||||||
./vendor/bin/phpunit
|
|
||||||
|
|
||||||
if [ ! -d .gh-pages ]; then
|
|
||||||
echo "Checking out gh-pages in .gh-pages"
|
|
||||||
git clone -b gh-pages git@git.maxmind.com:GeoIP2-php .gh-pages
|
|
||||||
pushd .gh-pages
|
|
||||||
else
|
|
||||||
echo "Updating .gh-pages"
|
|
||||||
pushd .gh-pages
|
|
||||||
git pull
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -n "$(git status --porcelain)" ]; then
|
|
||||||
echo ".gh-pages is not clean" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# We no longer have apigen as a dependency in Composer as releases are
|
|
||||||
# sporadically deleted upstream and compatibility is often broken on patch
|
|
||||||
# releases.
|
|
||||||
if [ ! -f apigen.phar ]; then
|
|
||||||
wget -O apigen.phar "https://github.com/apigen/apigen/releases/download/v4.0.0-RC3/apigen-4.0.0-RC3.phar"
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
cat <<EOF > apigen.neon
|
|
||||||
destination: doc/$TAG
|
|
||||||
|
|
||||||
source:
|
|
||||||
- ../src
|
|
||||||
|
|
||||||
title: "GeoIP2 PHP API $TAG"
|
|
||||||
EOF
|
|
||||||
|
|
||||||
php apigen.phar generate
|
|
||||||
|
|
||||||
|
|
||||||
PAGE=index.md
|
|
||||||
cat <<EOF > $PAGE
|
|
||||||
---
|
|
||||||
layout: default
|
|
||||||
title: MaxMind GeoIP2 PHP API
|
|
||||||
language: php
|
|
||||||
version: $TAG
|
|
||||||
---
|
|
||||||
|
|
||||||
EOF
|
|
||||||
|
|
||||||
cat ../README.md >> $PAGE
|
|
||||||
|
|
||||||
git add doc/
|
|
||||||
git commit -m "Updated for $TAG" -a
|
|
||||||
|
|
||||||
read -e -p "Push to origin? " SHOULD_PUSH
|
|
||||||
|
|
||||||
if [ "$SHOULD_PUSH" != "y" ]; then
|
|
||||||
echo "Aborting"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# If we don't push directly to github, the page doesn't get built for some
|
|
||||||
# reason.
|
|
||||||
git push git@github.com:maxmind/GeoIP2-php.git
|
|
||||||
git push
|
|
||||||
|
|
||||||
popd
|
|
||||||
|
|
||||||
git tag -a $TAG
|
|
||||||
git push
|
|
||||||
git push --tags
|
|
@ -1 +1 @@
|
|||||||
Subproject commit e53ed8cde6951be3bbd0fdb300d69c898b399a97
|
Subproject commit f887fec99eabf6d68746e257b894bae854fefc27
|
@ -8,9 +8,13 @@ use MaxMind\Db\Reader as DbReader;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Instances of this class provide a reader for the GeoIP2 database format.
|
* Instances of this class provide a reader for the GeoIP2 database format.
|
||||||
* IP addresses can be looked up using the database specific methods.
|
* IP addresses can be looked up using the <code>country</code>
|
||||||
|
* and <code>city</code> methods. We also provide <code>cityIspOrg</code>
|
||||||
|
* and <code>omni</code> methods to ease compatibility with the web service
|
||||||
|
* client, although we may offer the ability to specify additional databases
|
||||||
|
* to replicate these web services in the future (e.g., the ISP/Org database).
|
||||||
*
|
*
|
||||||
* ## Usage ##
|
* **Usage**
|
||||||
*
|
*
|
||||||
* The basic API for this class is the same for every database. First, you
|
* The basic API for this class is the same for every database. First, you
|
||||||
* create a reader object, specifying a file name. You then call the method
|
* create a reader object, specifying a file name. You then call the method
|
||||||
@ -21,7 +25,7 @@ use MaxMind\Db\Reader as DbReader;
|
|||||||
* the method you called. This model in turn contains multiple record classes,
|
* the method you called. This model in turn contains multiple record classes,
|
||||||
* each of which represents part of the data returned by the database. If
|
* each of which represents part of the data returned by the database. If
|
||||||
* the database does not contain the requested information, the attributes
|
* the database does not contain the requested information, the attributes
|
||||||
* on the record class will have a `null` value.
|
* on the record class will have a <code>null</code> value.
|
||||||
*
|
*
|
||||||
* If the address is not in the database, an
|
* If the address is not in the database, an
|
||||||
* {@link \GeoIp2\Exception\AddressNotFoundException} exception will be
|
* {@link \GeoIp2\Exception\AddressNotFoundException} exception will be
|
||||||
@ -67,7 +71,7 @@ class Reader implements ProviderInterface
|
|||||||
*/
|
*/
|
||||||
public function city($ipAddress)
|
public function city($ipAddress)
|
||||||
{
|
{
|
||||||
return $this->modelFor('City', 'City', $ipAddress);
|
return $this->modelFor('City', $ipAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -84,139 +88,55 @@ class Reader implements ProviderInterface
|
|||||||
*/
|
*/
|
||||||
public function country($ipAddress)
|
public function country($ipAddress)
|
||||||
{
|
{
|
||||||
return $this->modelFor('Country', 'Country', $ipAddress);
|
return $this->modelFor('Country', $ipAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method returns a GeoIP2 Anonymous IP model.
|
* This method returns a GeoIP2 City/ISP/Org model.
|
||||||
*
|
*
|
||||||
* @param string $ipAddress IPv4 or IPv6 address as a string.
|
* @param string $ipAddress IPv4 or IPv6 address as a string.
|
||||||
*
|
*
|
||||||
* @return \GeoIp2\Model\AnonymousIp
|
* @return \GeoIp2\Model\CityIspOrg
|
||||||
*
|
*
|
||||||
* @throws \GeoIp2\Exception\AddressNotFoundException if the address is
|
* @throws \GeoIp2\Exception\AddressNotFoundException if the address is
|
||||||
* not in the database.
|
* not in the database.
|
||||||
* @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
|
* @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
|
||||||
* is corrupt or invalid
|
* is corrupt or invalid
|
||||||
*/
|
*/
|
||||||
public function anonymousIp($ipAddress)
|
public function cityIspOrg($ipAddress)
|
||||||
{
|
{
|
||||||
return $this->flatModelFor(
|
return $this->modelFor('CityIspOrg', $ipAddress);
|
||||||
'AnonymousIp',
|
|
||||||
'GeoIP2-Anonymous-IP',
|
|
||||||
$ipAddress
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method returns a GeoIP2 Connection Type model.
|
* This method returns a GeoIP2 Omni model.
|
||||||
*
|
*
|
||||||
* @param string $ipAddress IPv4 or IPv6 address as a string.
|
* @param string $ipAddress IPv4 or IPv6 address as a string.
|
||||||
*
|
*
|
||||||
* @return \GeoIp2\Model\ConnectionType
|
* @return \GeoIp2\Model\Omni
|
||||||
*
|
*
|
||||||
* @throws \GeoIp2\Exception\AddressNotFoundException if the address is
|
* @throws \GeoIp2\Exception\AddressNotFoundException if the address is
|
||||||
* not in the database.
|
* not in the database.
|
||||||
* @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
|
* @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
|
||||||
* is corrupt or invalid
|
* is corrupt or invalid
|
||||||
*/
|
*/
|
||||||
public function connectionType($ipAddress)
|
public function omni($ipAddress)
|
||||||
{
|
{
|
||||||
return $this->flatModelFor(
|
return $this->modelFor('Omni', $ipAddress);
|
||||||
'ConnectionType',
|
|
||||||
'GeoIP2-Connection-Type',
|
|
||||||
$ipAddress
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private function modelFor($class, $ipAddress)
|
||||||
* 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(
|
|
||||||
'Domain',
|
|
||||||
'GeoIP2-Domain',
|
|
||||||
$ipAddress
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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(
|
|
||||||
'Isp',
|
|
||||||
'GeoIP2-ISP',
|
|
||||||
$ipAddress
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function modelFor($class, $type, $ipAddress)
|
|
||||||
{
|
|
||||||
$record = $this->getRecord($class, $type, $ipAddress);
|
|
||||||
|
|
||||||
$record['traits']['ip_address'] = $ipAddress;
|
|
||||||
$class = "GeoIp2\\Model\\" . $class;
|
|
||||||
|
|
||||||
return new $class($record, $this->locales);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function flatModelFor($class, $type, $ipAddress)
|
|
||||||
{
|
|
||||||
$record = $this->getRecord($class, $type, $ipAddress);
|
|
||||||
|
|
||||||
$record['ip_address'] = $ipAddress;
|
|
||||||
$class = "GeoIp2\\Model\\" . $class;
|
|
||||||
|
|
||||||
return new $class($record);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getRecord($class, $type, $ipAddress)
|
|
||||||
{
|
|
||||||
if (strpos($this->metadata()->databaseType, $type) === false) {
|
|
||||||
$method = lcfirst($class);
|
|
||||||
throw new \BadMethodCallException(
|
|
||||||
"The $method method cannot be used to open a "
|
|
||||||
. $this->metadata()->databaseType . " database"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
$record = $this->dbReader->get($ipAddress);
|
$record = $this->dbReader->get($ipAddress);
|
||||||
if ($record === null) {
|
if ($record === null) {
|
||||||
throw new AddressNotFoundException(
|
throw new AddressNotFoundException(
|
||||||
"The address $ipAddress is not in the database."
|
"The address $ipAddress is not in the database."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return $record;
|
$record['traits']['ip_address'] = $ipAddress;
|
||||||
}
|
$class = "GeoIp2\\Model\\" . $class;
|
||||||
|
|
||||||
/**
|
return new $class($record, $this->locales);
|
||||||
* @throws \InvalidArgumentException if arguments are passed to the method.
|
|
||||||
* @throws \BadMethodCallException if the database has been closed.
|
|
||||||
* @return \MaxMind\Db\Reader\Metadata object for the database.
|
|
||||||
*/
|
|
||||||
public function metadata()
|
|
||||||
{
|
|
||||||
return $this->dbReader->metadata();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,60 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace GeoIp2\Model;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ignore
|
|
||||||
*/
|
|
||||||
abstract class AbstractModel implements \JsonSerializable
|
|
||||||
{
|
|
||||||
protected $raw;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ignore
|
|
||||||
*/
|
|
||||||
public function __construct($raw)
|
|
||||||
{
|
|
||||||
$this->raw = $raw;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ignore
|
|
||||||
*/
|
|
||||||
protected function get($field)
|
|
||||||
{
|
|
||||||
if (isset($this->raw[$field])) {
|
|
||||||
return $this->raw[$field];
|
|
||||||
} else {
|
|
||||||
if (preg_match('/^is_/', $field)) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ignore
|
|
||||||
*/
|
|
||||||
public function __get($attr)
|
|
||||||
{
|
|
||||||
if ($attr != "instance" && property_exists($this, $attr)) {
|
|
||||||
return $this->$attr;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new \RuntimeException("Unknown attribute: $attr");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ignore
|
|
||||||
*/
|
|
||||||
public function __isset($attr)
|
|
||||||
{
|
|
||||||
return $attr != "instance" && isset($this->$attr);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function jsonSerialize()
|
|
||||||
{
|
|
||||||
return $this->raw;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,50 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace GeoIp2\Model;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class provides the GeoIP2 Anonymous IP model.
|
|
||||||
*
|
|
||||||
* @property boolean $isAnonymous This is true if the IP address belongs to
|
|
||||||
* any sort of anonymous network.
|
|
||||||
*
|
|
||||||
* @property boolean $isAnonymousVpn This is true if the IP address belongs to
|
|
||||||
* an anonymous VPN system.
|
|
||||||
*
|
|
||||||
* @property boolean $isHostingProvider This is true if the IP address belongs
|
|
||||||
* to a hosting provider.
|
|
||||||
*
|
|
||||||
* @property boolean $isPublicProxy This is true if the IP address belongs to
|
|
||||||
* a public proxy.
|
|
||||||
*
|
|
||||||
* @property boolean $isTorExitNode This is true if the IP address is a Tor
|
|
||||||
* exit node.
|
|
||||||
*
|
|
||||||
* @property string $ipAddress The IP address that the data in the model is
|
|
||||||
* for.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class AnonymousIp extends AbstractModel
|
|
||||||
{
|
|
||||||
protected $isAnonymous;
|
|
||||||
protected $isAnonymousVpn;
|
|
||||||
protected $isHostingProvider;
|
|
||||||
protected $isPublicProxy;
|
|
||||||
protected $isTorExitNode;
|
|
||||||
protected $ipAddress;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ignore
|
|
||||||
*/
|
|
||||||
public function __construct($raw)
|
|
||||||
{
|
|
||||||
parent::__construct($raw);
|
|
||||||
|
|
||||||
$this->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');
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,10 +3,11 @@
|
|||||||
namespace GeoIp2\Model;
|
namespace GeoIp2\Model;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Model class for the data returned by GeoIP2 City web service and database.
|
* This class provides a model for the data returned by the GeoIP2
|
||||||
|
* City end point.
|
||||||
*
|
*
|
||||||
* The only difference between the City and Insights model classes is which
|
* The only difference between the City, City/ISP/Org, and Omni model
|
||||||
* fields in each record may be populated. See
|
* classes is which fields in each record may be populated. See
|
||||||
* http://dev.maxmind.com/geoip/geoip2/web-services more details.
|
* http://dev.maxmind.com/geoip/geoip2/web-services more details.
|
||||||
*
|
*
|
||||||
* @property \GeoIp2\Record\City $city City data for the requested IP
|
* @property \GeoIp2\Record\City $city City data for the requested IP
|
||||||
@ -32,8 +33,8 @@ namespace GeoIp2\Model;
|
|||||||
*
|
*
|
||||||
* @property \GeoIp2\Record\RepresentedCountry $representedCountry
|
* @property \GeoIp2\Record\RepresentedCountry $representedCountry
|
||||||
* Represented country data for the requested IP address. The represented
|
* Represented country data for the requested IP address. The represented
|
||||||
* country is used for things like military bases. It is only present when
|
* country is used for things like military bases or embassies. It is only
|
||||||
* the represented country differs from the country.
|
* present when the represented country differs from the country.
|
||||||
*
|
*
|
||||||
* @property array $subdivisions An array of {@link \GeoIp2\Record\Subdivision}
|
* @property array $subdivisions An array of {@link \GeoIp2\Record\Subdivision}
|
||||||
* objects representing the country subdivisions for the requested IP
|
* objects representing the country subdivisions for the requested IP
|
||||||
|
57
src/GeoIp2/Model/CityIspOrg.php
Normal file
57
src/GeoIp2/Model/CityIspOrg.php
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace GeoIp2\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class provides a model for the data returned by the GeoIP2
|
||||||
|
* City/ISP/Org end point.
|
||||||
|
*
|
||||||
|
* The only difference between the City, City/ISP/Org, and Omni model
|
||||||
|
* classes is which fields in each record may be populated. See
|
||||||
|
* http://dev.maxmind.com/geoip/geoip2/web-services more details.
|
||||||
|
*
|
||||||
|
* @property \GeoIp2\Record\City $city City data for the requested IP
|
||||||
|
* address.
|
||||||
|
*
|
||||||
|
* @property \GeoIp2\Record\Continent $continent Continent data for the
|
||||||
|
* requested IP address.
|
||||||
|
*
|
||||||
|
* @property \GeoIp2\Record\Country $country Country data for the requested
|
||||||
|
* IP address. This object represents the country where MaxMind believes the
|
||||||
|
* end user is located.
|
||||||
|
*
|
||||||
|
* @property \GeoIp2\Record\Location $location Location data for the
|
||||||
|
* requested IP address.
|
||||||
|
*
|
||||||
|
* @property \GeoIp2\Record\MaxMind $maxmind Data related to your MaxMind
|
||||||
|
* account.
|
||||||
|
*
|
||||||
|
* @property \GeoIp2\Record\Country $registeredCountry Registered country
|
||||||
|
* data for the requested IP address. This record represents the country
|
||||||
|
* where the ISP has registered a given IP block and may differ from the
|
||||||
|
* user's country.
|
||||||
|
*
|
||||||
|
* @property \GeoIp2\Record\RepresentedCountry $representedCountry
|
||||||
|
* Represented country data for the requested IP address. The represented
|
||||||
|
* country is used for things like military bases or embassies. It is only
|
||||||
|
* present when the represented country differs from the country.
|
||||||
|
*
|
||||||
|
* @property array $subdivisions An array of {@link \GeoIp2\Record\Subdivision}
|
||||||
|
* objects representing the country subdivisions for the requested IP
|
||||||
|
* address. The number and type of subdivisions varies by country, but a
|
||||||
|
* subdivision is typically a state, province, county, etc. Subdivisions
|
||||||
|
* are ordered from most general (largest) to most specific (smallest).
|
||||||
|
* If the response did not contain any subdivisions, this method returns
|
||||||
|
* an empty array.
|
||||||
|
*
|
||||||
|
* @property \GeoIp2\Record\Subdivision $mostSpecificSubdivision An object
|
||||||
|
* representing the most specific subdivision returned. If the response
|
||||||
|
* did not contain any subdivisions, this method returns an empty
|
||||||
|
* {@link \GeoIp2\Record\Subdivision} object.
|
||||||
|
*
|
||||||
|
* @property \GeoIp2\Record\Traits $traits Data for the traits of the
|
||||||
|
* requested IP address.
|
||||||
|
*/
|
||||||
|
class CityIspOrg extends City
|
||||||
|
{
|
||||||
|
}
|
@ -1,31 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace GeoIp2\Model;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class provides the GeoIP2 Connection-Type model.
|
|
||||||
*
|
|
||||||
* @property string $connectionType The connection type may take the following
|
|
||||||
* values: "Dialup", "Cable/DSL", "Corporate", "Cellular". Additional
|
|
||||||
* values may be added in the future.
|
|
||||||
*
|
|
||||||
* @property string $ipAddress The IP address that the data in the model is
|
|
||||||
* for.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class ConnectionType extends AbstractModel
|
|
||||||
{
|
|
||||||
protected $connectionType;
|
|
||||||
protected $ipAddress;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ignore
|
|
||||||
*/
|
|
||||||
public function __construct($raw)
|
|
||||||
{
|
|
||||||
parent::__construct($raw);
|
|
||||||
|
|
||||||
$this->connectionType = $this->get('connection_type');
|
|
||||||
$this->ipAddress = $this->get('ip_address');
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,10 +3,11 @@
|
|||||||
namespace GeoIp2\Model;
|
namespace GeoIp2\Model;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Model class for the data returned by GeoIP2 Country web service and database.
|
* This class provides a model for the data returned by the GeoIP2 Country
|
||||||
|
* end point.
|
||||||
*
|
*
|
||||||
* The only difference between the City and Insights model classes is which
|
* The only difference between the City, City/ISP/Org, and Omni model
|
||||||
* fields in each record may be populated. See
|
* classes is which fields in each record may be populated. See
|
||||||
* http://dev.maxmind.com/geoip/geoip2/web-services more details.
|
* http://dev.maxmind.com/geoip/geoip2/web-services more details.
|
||||||
*
|
*
|
||||||
* @property \GeoIp2\Record\Continent $continent Continent data for the
|
* @property \GeoIp2\Record\Continent $continent Continent data for the
|
||||||
@ -26,28 +27,29 @@ namespace GeoIp2\Model;
|
|||||||
*
|
*
|
||||||
* @property \GeoIp2\Record\RepresentedCountry $representedCountry
|
* @property \GeoIp2\Record\RepresentedCountry $representedCountry
|
||||||
* Represented country data for the requested IP address. The represented
|
* Represented country data for the requested IP address. The represented
|
||||||
* country is used for things like military bases. It is only present when
|
* country is used for things like military bases or embassies. It is only
|
||||||
* the represented country differs from the country.
|
* present when the represented country differs from the country.
|
||||||
*
|
*
|
||||||
* @property \GeoIp2\Record\Traits $traits Data for the traits of the
|
* @property \GeoIp2\Record\Traits $traits Data for the traits of the
|
||||||
* requested IP address.
|
* requested IP address.
|
||||||
*/
|
*/
|
||||||
class Country extends AbstractModel
|
class Country implements \JsonSerializable
|
||||||
{
|
{
|
||||||
protected $continent;
|
private $continent;
|
||||||
protected $country;
|
private $country;
|
||||||
protected $locales;
|
private $locales;
|
||||||
protected $maxmind;
|
private $maxmind;
|
||||||
protected $registeredCountry;
|
private $registeredCountry;
|
||||||
protected $representedCountry;
|
private $representedCountry;
|
||||||
protected $traits;
|
private $traits;
|
||||||
|
private $raw;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ignore
|
* @ignore
|
||||||
*/
|
*/
|
||||||
public function __construct($raw, $locales = array('en'))
|
public function __construct($raw, $locales = array('en'))
|
||||||
{
|
{
|
||||||
parent::__construct($raw);
|
$this->raw = $raw;
|
||||||
|
|
||||||
$this->continent = new \GeoIp2\Record\Continent(
|
$this->continent = new \GeoIp2\Record\Continent(
|
||||||
$this->get('continent'),
|
$this->get('continent'),
|
||||||
@ -70,4 +72,37 @@ class Country extends AbstractModel
|
|||||||
|
|
||||||
$this->locales = $locales;
|
$this->locales = $locales;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ignore
|
||||||
|
*/
|
||||||
|
protected function get($field)
|
||||||
|
{
|
||||||
|
return isset($this->raw[$field]) ? $this->raw[$field] : array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ignore
|
||||||
|
*/
|
||||||
|
public function __get($attr)
|
||||||
|
{
|
||||||
|
if ($attr != "instance" && isset($this->$attr)) {
|
||||||
|
return $this->$attr;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new \RuntimeException("Unknown attribute: $attr");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ignore
|
||||||
|
*/
|
||||||
|
public function __isset($attr)
|
||||||
|
{
|
||||||
|
return $attr != "instance" && isset($this->$attr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function jsonSerialize()
|
||||||
|
{
|
||||||
|
return $this->raw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,31 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace GeoIp2\Model;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class provides the GeoIP2 Domain model.
|
|
||||||
*
|
|
||||||
* @property string $domain The second level domain associated with the IP
|
|
||||||
* address. This will be something like "example.com" or "example.co.uk",
|
|
||||||
* not "foo.example.com".
|
|
||||||
*
|
|
||||||
* @property string $ipAddress The IP address that the data in the model is
|
|
||||||
* for.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class Domain extends AbstractModel
|
|
||||||
{
|
|
||||||
protected $domain;
|
|
||||||
protected $ipAddress;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ignore
|
|
||||||
*/
|
|
||||||
public function __construct($raw)
|
|
||||||
{
|
|
||||||
parent::__construct($raw);
|
|
||||||
|
|
||||||
$this->domain = $this->get('domain');
|
|
||||||
$this->ipAddress = $this->get('ip_address');
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,45 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace GeoIp2\Model;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class provides the GeoIP2 Connection-Type model.
|
|
||||||
*
|
|
||||||
* @property integer $autonomousSystemNumber The autonomous system number
|
|
||||||
* associated with the IP address.
|
|
||||||
*
|
|
||||||
* @property string $autonomousSystemOrganization The organization associated
|
|
||||||
* with the registered autonomous system number for the IP address.
|
|
||||||
*
|
|
||||||
* @property string $isp The name of the ISP associated with the IP address.
|
|
||||||
*
|
|
||||||
* @property string $organization The name of the organization associated with
|
|
||||||
* the IP address.
|
|
||||||
*
|
|
||||||
* @property string $ipAddress The IP address that the data in the model is
|
|
||||||
* for.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class Isp extends AbstractModel
|
|
||||||
{
|
|
||||||
protected $autonomousSystemNumber;
|
|
||||||
protected $autonomousSystemOrganization;
|
|
||||||
protected $isp;
|
|
||||||
protected $organization;
|
|
||||||
protected $ipAddress;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ignore
|
|
||||||
*/
|
|
||||||
public function __construct($raw)
|
|
||||||
{
|
|
||||||
parent::__construct($raw);
|
|
||||||
$this->autonomousSystemNumber = $this->get('autonomous_system_number');
|
|
||||||
$this->autonomousSystemOrganization =
|
|
||||||
$this->get('autonomous_system_organization');
|
|
||||||
$this->isp = $this->get('isp');
|
|
||||||
$this->organization = $this->get('organization');
|
|
||||||
|
|
||||||
$this->ipAddress = $this->get('ip_address');
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,10 +3,11 @@
|
|||||||
namespace GeoIp2\Model;
|
namespace GeoIp2\Model;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Model class for the data returned by GeoIP2 Precision: Insights web service.
|
* This class provides a model for the data returned by the GeoIP2
|
||||||
|
* Omni end point.
|
||||||
*
|
*
|
||||||
* The only difference between the City and Insights model classes is which
|
* The only difference between the City, City/ISP/Org, and Omni model
|
||||||
* fields in each record may be populated. See
|
* classes is which fields in each record may be populated. See
|
||||||
* http://dev.maxmind.com/geoip/geoip2/web-services more details.
|
* http://dev.maxmind.com/geoip/geoip2/web-services more details.
|
||||||
*
|
*
|
||||||
* @property \GeoIp2\Record\City $city City data for the requested IP
|
* @property \GeoIp2\Record\City $city City data for the requested IP
|
||||||
@ -32,8 +33,8 @@ namespace GeoIp2\Model;
|
|||||||
*
|
*
|
||||||
* @property \GeoIp2\Record\RepresentedCountry $representedCountry
|
* @property \GeoIp2\Record\RepresentedCountry $representedCountry
|
||||||
* Represented country data for the requested IP address. The represented
|
* Represented country data for the requested IP address. The represented
|
||||||
* country is used for things like military bases. It is only present when
|
* country is used for things like military bases or embassies. It is only
|
||||||
* the represented country differs from the country.
|
* present when the represented country differs from the country.
|
||||||
*
|
*
|
||||||
* @property array $subdivisions An array of {@link \GeoIp2\Record\Subdivision}
|
* @property array $subdivisions An array of {@link \GeoIp2\Record\Subdivision}
|
||||||
* objects representing the country subdivisions for the requested IP
|
* objects representing the country subdivisions for the requested IP
|
||||||
@ -51,6 +52,6 @@ namespace GeoIp2\Model;
|
|||||||
* @property \GeoIp2\Record\Traits $traits Data for the traits of the
|
* @property \GeoIp2\Record\Traits $traits Data for the traits of the
|
||||||
* requested IP address.
|
* requested IP address.
|
||||||
*/
|
*/
|
||||||
class Insights extends City
|
class Omni extends CityIspOrg
|
||||||
{
|
{
|
||||||
}
|
}
|
@ -17,4 +17,18 @@ interface ProviderInterface
|
|||||||
* @return \GeoIp2\Model\City A City model for the requested IP address.
|
* @return \GeoIp2\Model\City A City model for the requested IP address.
|
||||||
*/
|
*/
|
||||||
public function city($ipAddress);
|
public function city($ipAddress);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ipAddress
|
||||||
|
* IPv4 or IPv6 address to lookup.
|
||||||
|
* @return \GeoIp2\Model\CityIspOrg A CityIspOrg model for the requested IP address.
|
||||||
|
*/
|
||||||
|
public function cityIspOrg($ipAddress);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ipAddress
|
||||||
|
* IPv4 or IPv6 address to lookup.
|
||||||
|
* @return \GeoIp2\Model\Omni An Omni model for the requested IP address.
|
||||||
|
*/
|
||||||
|
public function omni($ipAddress);
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ abstract class AbstractRecord implements \JsonSerializable
|
|||||||
*/
|
*/
|
||||||
public function __construct($record)
|
public function __construct($record)
|
||||||
{
|
{
|
||||||
$this->record = isset($record) ? $record : array();
|
$this->record = $record;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -25,11 +25,7 @@ abstract class AbstractRecord implements \JsonSerializable
|
|||||||
if ($this->__isset($attr)) {
|
if ($this->__isset($attr)) {
|
||||||
return $this->record[$key];
|
return $this->record[$key];
|
||||||
} elseif ($this->validAttribute($attr)) {
|
} elseif ($this->validAttribute($attr)) {
|
||||||
if (preg_match('/^is_/', $key)) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
throw new \RuntimeException("Unknown attribute: $attr");
|
throw new \RuntimeException("Unknown attribute: $attr");
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ namespace GeoIp2\Record;
|
|||||||
*
|
*
|
||||||
* @property int $confidence A value from 0-100 indicating MaxMind's
|
* @property int $confidence A value from 0-100 indicating MaxMind's
|
||||||
* confidence that the city is correct. This attribute is only available
|
* confidence that the city is correct. This attribute is only available
|
||||||
* from the Insights end point.
|
* from the Omni end point.
|
||||||
*
|
*
|
||||||
* @property int $geonameId The GeoName ID for the city. This attribute
|
* @property int $geonameId The GeoName ID for the city. This attribute
|
||||||
* is returned by all end points.
|
* is returned by all end points.
|
||||||
|
@ -9,7 +9,7 @@ namespace GeoIp2\Record;
|
|||||||
*
|
*
|
||||||
* @property int $accuracyRadius The radius in kilometers around the
|
* @property int $accuracyRadius The radius in kilometers around the
|
||||||
* specified location where the IP address is likely to be. This attribute
|
* specified location where the IP address is likely to be. This attribute
|
||||||
* is only available from the Insights end point.
|
* is only available from the Omni end point.
|
||||||
*
|
*
|
||||||
* @property float $latitude The latitude of the location as a floating
|
* @property float $latitude The latitude of the location as a floating
|
||||||
* point number. This attribute is returned by all end points except the
|
* point number. This attribute is returned by all end points except the
|
||||||
|
@ -14,7 +14,7 @@ namespace GeoIp2\Record;
|
|||||||
*
|
*
|
||||||
* @property int $confidence A value from 0-100 indicating MaxMind's
|
* @property int $confidence A value from 0-100 indicating MaxMind's
|
||||||
* confidence that the postal code is correct. This attribute is only
|
* confidence that the postal code is correct. This attribute is only
|
||||||
* available from the Insights end point.
|
* available from the Omni end point.
|
||||||
*/
|
*/
|
||||||
class Postal extends AbstractRecord
|
class Postal extends AbstractRecord
|
||||||
{
|
{
|
||||||
|
@ -7,26 +7,31 @@ namespace GeoIp2\Record;
|
|||||||
*
|
*
|
||||||
* This class contains the country-level data associated with an IP address
|
* This class contains the country-level data associated with an IP address
|
||||||
* for the IP's represented country. The represented country is the country
|
* for the IP's represented country. The represented country is the country
|
||||||
* represented by something like a military base.
|
* represented by something like a military base or embassy.
|
||||||
|
*
|
||||||
|
* This record is returned by all the end points.
|
||||||
*
|
*
|
||||||
* @property int $confidence A value from 0-100 indicating MaxMind's
|
* @property int $confidence A value from 0-100 indicating MaxMind's
|
||||||
* confidence that the country is correct. This attribute is only available
|
* confidence that the country is correct. This attribute is only available
|
||||||
* from the Insights end point.
|
* from the Omni end point.
|
||||||
*
|
*
|
||||||
* @property int $geonameId The GeoName ID for the country.
|
* @property int $geonameId The GeoName ID for the country. This attribute is
|
||||||
|
* returned by all end points.
|
||||||
*
|
*
|
||||||
* @property string $isoCode The {@link http://en.wikipedia.org/wiki/ISO_3166-1
|
* @property string $isoCode The {@link http://en.wikipedia.org/wiki/ISO_3166-1
|
||||||
* two-character ISO 3166-1 alpha code} for the country.
|
* two-character ISO 3166-1 alpha code} for the country. This attribute is
|
||||||
|
* returned by all end points.
|
||||||
*
|
*
|
||||||
* @property string $name The name of the country based on the locales list
|
* @property string $name The name of the country based on the locales list
|
||||||
* passed to the constructor.
|
* passed to the constructor. This attribute is returned by all end points.
|
||||||
*
|
*
|
||||||
* @property array $names An array map where the keys are locale codes and
|
* @property array $names An array map where the keys are locale codes and
|
||||||
* the values are names.
|
* the values are names. This attribute is returned by all end points.
|
||||||
*
|
*
|
||||||
* @property string $type A string indicating the type of entity that is
|
* @property string $type A string indicating the type of entity that is
|
||||||
* representing the country. Currently we only return <code>military</code>
|
* representing the country. Currently we only return <code>military</code>
|
||||||
* but this could expand to include other types in the future.
|
* but this could expand to include other types such as <code>embassy</code>
|
||||||
|
* in the future. Returned by all endpoints.
|
||||||
*/
|
*/
|
||||||
class RepresentedCountry extends Country
|
class RepresentedCountry extends Country
|
||||||
{
|
{
|
||||||
@ -34,7 +39,7 @@ class RepresentedCountry extends Country
|
|||||||
'confidence',
|
'confidence',
|
||||||
'geonameId',
|
'geonameId',
|
||||||
'isoCode',
|
'isoCode',
|
||||||
'names',
|
'namespace',
|
||||||
'type'
|
'type'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ namespace GeoIp2\Record;
|
|||||||
*
|
*
|
||||||
* @property int $confidence This is a value from 0-100 indicating MaxMind's
|
* @property int $confidence This is a value from 0-100 indicating MaxMind's
|
||||||
* confidence that the subdivision is correct. This attribute is only
|
* confidence that the subdivision is correct. This attribute is only
|
||||||
* available from the Insights end point.
|
* available from the Omni end point.
|
||||||
*
|
*
|
||||||
* @property int $geonameId This is a GeoName ID for the subdivision. This
|
* @property int $geonameId This is a GeoName ID for the subdivision. This
|
||||||
* attribute is returned by all end points except Country.
|
* attribute is returned by all end points except Country.
|
||||||
|
@ -11,18 +11,18 @@ namespace GeoIp2\Record;
|
|||||||
* @property int $autonomousSystemNumber The {@link
|
* @property int $autonomousSystemNumber The {@link
|
||||||
* http://en.wikipedia.org/wiki/Autonomous_system_(Internet) autonomous
|
* http://en.wikipedia.org/wiki/Autonomous_system_(Internet) autonomous
|
||||||
* system number} associated with the IP address. This attribute is only
|
* system number} associated with the IP address. This attribute is only
|
||||||
* available from the City and Insights web service end points.
|
* available from the City/ISP/Org and Omni end points.
|
||||||
*
|
*
|
||||||
* @property string $autonomousSystemOrganization The organization
|
* @property string $autonomousSystemOrganization The organization
|
||||||
* associated with the registered {@link
|
* associated with the registered {@link
|
||||||
* http://en.wikipedia.org/wiki/Autonomous_system_(Internet) autonomous
|
* http://en.wikipedia.org/wiki/Autonomous_system_(Internet) autonomous
|
||||||
* system number} for the IP address. This attribute is only available from
|
* system number} for the IP address. This attribute is only available from
|
||||||
* the City and Insights web service end points.
|
* the City/ISP/Org and Omni end points.
|
||||||
*
|
*
|
||||||
* @property string $domain The second level domain associated with the
|
* @property string $domain The second level domain associated with the
|
||||||
* IP address. This will be something like "example.com" or "example.co.uk",
|
* IP address. This will be something like "example.com" or "example.co.uk",
|
||||||
* not "foo.example.com". This attribute is only available from the
|
* not "foo.example.com". This attribute is only available from the
|
||||||
* City and Insights web service end points.
|
* City/ISP/Org and Omni end points.
|
||||||
*
|
*
|
||||||
* @property string $ipAddress The IP address that the data in the model
|
* @property string $ipAddress The IP address that the data in the model
|
||||||
* is for. If you performed a "me" lookup against the web service, this
|
* is for. If you performed a "me" lookup against the web service, this
|
||||||
@ -40,12 +40,12 @@ namespace GeoIp2\Record;
|
|||||||
* end points.
|
* end points.
|
||||||
*
|
*
|
||||||
* @property string $isp The name of the ISP associated with the IP address.
|
* @property string $isp The name of the ISP associated with the IP address.
|
||||||
* This attribute is only available from the City and Insights web service end
|
* This attribute is only available from the City/ISP/Org and Omni end
|
||||||
* points.
|
* points.
|
||||||
*
|
*
|
||||||
* @property string $organization The name of the organization associated
|
* @property string $organization The name of the organization associated
|
||||||
* with the IP address. This attribute is only available from the City and
|
* with the IP address. This attribute is only available from the City/ISP/Org
|
||||||
* Insights web service end points.
|
* and Omni end points.
|
||||||
*
|
*
|
||||||
* @property string $userType <p>The user type associated with the IP
|
* @property string $userType <p>The user type associated with the IP
|
||||||
* address. This can be one of the following values:</p>
|
* address. This can be one of the following values:</p>
|
||||||
@ -66,10 +66,7 @@ namespace GeoIp2\Record;
|
|||||||
* <li>search_engine_spider
|
* <li>search_engine_spider
|
||||||
* <li>traveler
|
* <li>traveler
|
||||||
* </ul>
|
* </ul>
|
||||||
* <p>
|
* <p>This attribute is only available from the Omni end point.</p>
|
||||||
* This attribute is only available from the Insights web service end
|
|
||||||
* point.
|
|
||||||
* </p>
|
|
||||||
*/
|
*/
|
||||||
class Traits extends AbstractRecord
|
class Traits extends AbstractRecord
|
||||||
{
|
{
|
||||||
|
@ -15,10 +15,10 @@ use Guzzle\Http\Exception\ClientErrorResponseException;
|
|||||||
use Guzzle\Http\Exception\ServerErrorResponseException;
|
use Guzzle\Http\Exception\ServerErrorResponseException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides a client API for all the GeoIP2 Precision web service
|
* This class provides a client API for all the GeoIP2 web service's
|
||||||
* end points. The end points are Country, City, and Insights. Each end point
|
* end points. The end points are Country, City, City/ISP/Org, and Omni. Each
|
||||||
* returns a different set of data about an IP address, with Country returning
|
* end point returns a different set of data about an IP address, with Country
|
||||||
* the least data and Insights the most.
|
* returning the least data and Omni the most.
|
||||||
*
|
*
|
||||||
* Each web service end point is represented by a different model class, and
|
* Each web service end point is represented by a different model class, and
|
||||||
* these model classes in turn contain multiple Record classes. The record
|
* these model classes in turn contain multiple Record classes. The record
|
||||||
@ -30,12 +30,13 @@ use Guzzle\Http\Exception\ServerErrorResponseException;
|
|||||||
* The web service may not return any information for an entire record, in
|
* The web service may not return any information for an entire record, in
|
||||||
* which case all of the attributes for that record class will be empty.
|
* which case all of the attributes for that record class will be empty.
|
||||||
*
|
*
|
||||||
* ## Usage ##
|
* **Usage**
|
||||||
*
|
*
|
||||||
* The basic API for this class is the same for all of the web service end
|
* The basic API for this class is the same for all of the web service end
|
||||||
* points. First you create a web service object with your MaxMind `$userId`
|
* points. First you create a web service object with your MaxMind
|
||||||
* and `$licenseKey`, then you call the method corresponding to a specific end
|
* <code>$userId</code> and <code>$licenseKey</code>, then you call the method
|
||||||
* point, passing it the IP address you want to look up.
|
* corresponding to a specific end point, passing it the IP address you want
|
||||||
|
* to look up.
|
||||||
*
|
*
|
||||||
* If the request succeeds, the method call will return a model class for
|
* If the request succeeds, the method call will return a model class for
|
||||||
* the end point you called. This model in turn contains multiple record
|
* the end point you called. This model in turn contains multiple record
|
||||||
@ -51,8 +52,6 @@ class Client implements ProviderInterface
|
|||||||
private $locales;
|
private $locales;
|
||||||
private $host;
|
private $host;
|
||||||
private $guzzleClient;
|
private $guzzleClient;
|
||||||
private $timeout;
|
|
||||||
private $connectTimeout;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@ -64,17 +63,13 @@ class Client implements ProviderInterface
|
|||||||
* @param string $host Optional host parameter
|
* @param string $host Optional host parameter
|
||||||
* @param object $guzzleClient Optional Guzzle client to use (to facilitate
|
* @param object $guzzleClient Optional Guzzle client to use (to facilitate
|
||||||
* unit testing).
|
* unit testing).
|
||||||
* @param string $timeout Total transaction timeout in seconds
|
|
||||||
* @param string $connectTimeout Initial connection timeout in seconds
|
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
$userId,
|
$userId,
|
||||||
$licenseKey,
|
$licenseKey,
|
||||||
$locales = array('en'),
|
$locales = array('en'),
|
||||||
$host = 'geoip.maxmind.com',
|
$host = 'geoip.maxmind.com',
|
||||||
$guzzleClient = null,
|
$guzzleClient = null
|
||||||
$timeout = null,
|
|
||||||
$connectTimeout = null
|
|
||||||
) {
|
) {
|
||||||
$this->userId = $userId;
|
$this->userId = $userId;
|
||||||
$this->licenseKey = $licenseKey;
|
$this->licenseKey = $licenseKey;
|
||||||
@ -82,12 +77,10 @@ class Client implements ProviderInterface
|
|||||||
$this->host = $host;
|
$this->host = $host;
|
||||||
// To enable unit testing
|
// To enable unit testing
|
||||||
$this->guzzleClient = $guzzleClient;
|
$this->guzzleClient = $guzzleClient;
|
||||||
$this->timeout = $timeout;
|
|
||||||
$this->connectTimeout = $connectTimeout;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method calls the GeoIP2 Precision: City endpoint.
|
* This method calls the GeoIP2 City endpoint.
|
||||||
*
|
*
|
||||||
* @param string $ipAddress IPv4 or IPv6 address as a string. If no
|
* @param string $ipAddress IPv4 or IPv6 address as a string. If no
|
||||||
* address is provided, the address that the web service is called
|
* address is provided, the address that the web service is called
|
||||||
@ -119,7 +112,7 @@ class Client implements ProviderInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method calls the GeoIP2 Precision: Country endpoint.
|
* This method calls the GeoIP2 Country endpoint.
|
||||||
*
|
*
|
||||||
* @param string $ipAddress IPv4 or IPv6 address as a string. If no
|
* @param string $ipAddress IPv4 or IPv6 address as a string. If no
|
||||||
* address is provided, the address that the web service is called
|
* address is provided, the address that the web service is called
|
||||||
@ -151,13 +144,13 @@ class Client implements ProviderInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method calls the GeoIP2 Precision: Insights endpoint.
|
* This method calls the GeoIP2 City/ISP/Org endpoint.
|
||||||
*
|
*
|
||||||
* @param string $ipAddress IPv4 or IPv6 address as a string. If no
|
* @param string $ipAddress IPv4 or IPv6 address as a string. If no
|
||||||
* address is provided, the address that the web service is called
|
* address is provided, the address that the web service is called
|
||||||
* from will be used.
|
* from will be used.
|
||||||
*
|
*
|
||||||
* @return \GeoIp2\Model\Insights
|
* @return \GeoIp2\Model\CityIspOrg
|
||||||
*
|
*
|
||||||
* @throws \GeoIp2\Exception\AddressNotFoundException if the address you
|
* @throws \GeoIp2\Exception\AddressNotFoundException if the address you
|
||||||
* provided is not in our database (e.g., a private address).
|
* provided is not in our database (e.g., a private address).
|
||||||
@ -177,9 +170,41 @@ class Client implements ProviderInterface
|
|||||||
* class to the above exceptions. It will be thrown directly if a 200
|
* class to the above exceptions. It will be thrown directly if a 200
|
||||||
* status code is returned but the body is invalid.
|
* status code is returned but the body is invalid.
|
||||||
*/
|
*/
|
||||||
public function insights($ipAddress = 'me')
|
public function cityIspOrg($ipAddress = 'me')
|
||||||
{
|
{
|
||||||
return $this->responseFor('insights', 'Insights', $ipAddress);
|
return $this->responseFor('city_isp_org', 'CityIspOrg', $ipAddress);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method calls the GeoIP2 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
|
||||||
|
*
|
||||||
|
* @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.
|
||||||
|
*/
|
||||||
|
public function omni($ipAddress = 'me')
|
||||||
|
{
|
||||||
|
return $this->responseFor('omni', 'Omni', $ipAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function responseFor($endpoint, $class, $ipAddress)
|
private function responseFor($endpoint, $class, $ipAddress)
|
||||||
@ -188,14 +213,7 @@ class Client implements ProviderInterface
|
|||||||
|
|
||||||
$client = $this->guzzleClient ?
|
$client = $this->guzzleClient ?
|
||||||
$this->guzzleClient : new GuzzleClient();
|
$this->guzzleClient : new GuzzleClient();
|
||||||
$options = array();
|
$request = $client->get($uri, array('Accept' => 'application/json'));
|
||||||
if ($this->timeout !== null) {
|
|
||||||
$options['timeout'] = $this->timeout;
|
|
||||||
}
|
|
||||||
if ($this->connectTimeout !== null) {
|
|
||||||
$options['connect_timeout'] = $this->connectTimeout;
|
|
||||||
}
|
|
||||||
$request = $client->get($uri, array('Accept' => 'application/json'), $options);
|
|
||||||
$request->setAuth($this->userId, $this->licenseKey);
|
$request->setAuth($this->userId, $this->licenseKey);
|
||||||
$this->setUserAgent($request);
|
$this->setUserAgent($request);
|
||||||
|
|
||||||
@ -336,6 +354,6 @@ class Client implements ProviderInterface
|
|||||||
|
|
||||||
private function baseUri()
|
private function baseUri()
|
||||||
{
|
{
|
||||||
return 'https://' . $this->host . '/geoip/v2.1';
|
return 'https://' . $this->host . '/geoip/v2.0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,39 +8,44 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
public function testDefaultLocale()
|
public function testDefaultLocale()
|
||||||
{
|
{
|
||||||
foreach (array('City', 'Country') as $type) {
|
$reader = new Reader('maxmind-db/test-data/GeoIP2-City-Test.mmdb');
|
||||||
$reader = new Reader("maxmind-db/test-data/GeoIP2-$type-Test.mmdb");
|
// Needed for PHP 5.3
|
||||||
$method = lcfirst($type);
|
$that = $this;
|
||||||
|
$this->checkAllMethods(
|
||||||
|
function ($method) use (&$that, &$reader) {
|
||||||
$record = $reader->$method('81.2.69.160');
|
$record = $reader->$method('81.2.69.160');
|
||||||
$this->assertEquals('United Kingdom', $record->country->name);
|
$that->assertEquals('United Kingdom', $record->country->name);
|
||||||
}
|
}
|
||||||
|
);
|
||||||
$reader->close();
|
$reader->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLocaleList()
|
public function testLocaleList()
|
||||||
{
|
{
|
||||||
|
|
||||||
foreach (array('City', 'Country') as $type) {
|
|
||||||
$reader = new Reader(
|
$reader = new Reader(
|
||||||
"maxmind-db/test-data/GeoIP2-$type-Test.mmdb",
|
'maxmind-db/test-data/GeoIP2-City-Test.mmdb',
|
||||||
array('xx', 'ru', 'pt-BR', 'es', 'en')
|
array('xx', 'ru', 'pt-BR', 'es', 'en')
|
||||||
);
|
);
|
||||||
$method = lcfirst($type);
|
$that = $this;
|
||||||
|
$this->checkAllMethods(
|
||||||
|
function ($method) use (&$that, &$reader) {
|
||||||
$record = $reader->$method('81.2.69.160');
|
$record = $reader->$method('81.2.69.160');
|
||||||
$this->assertEquals('Великобритания', $record->country->name);
|
$that->assertEquals('Великобритания', $record->country->name);
|
||||||
}
|
}
|
||||||
|
);
|
||||||
$reader->close();
|
$reader->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHasIpAddress()
|
public function testHasIpAddress()
|
||||||
{
|
{
|
||||||
foreach (array('City', 'Country') as $type) {
|
$reader = new Reader('maxmind-db/test-data/GeoIP2-City-Test.mmdb');
|
||||||
$reader = new Reader("maxmind-db/test-data/GeoIP2-$type-Test.mmdb");
|
$that = $this;
|
||||||
$method = lcfirst($type);
|
$this->checkAllMethods(
|
||||||
|
function ($method) use (&$that, &$reader) {
|
||||||
$record = $reader->$method('81.2.69.160');
|
$record = $reader->$method('81.2.69.160');
|
||||||
$this->assertEquals('81.2.69.160', $record->traits->ipAddress);
|
$that->assertEquals('81.2.69.160', $record->traits->ipAddress);
|
||||||
}
|
}
|
||||||
|
);
|
||||||
$reader->close();
|
$reader->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,28 +60,6 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$reader->close();
|
$reader->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException BadMethodCallException
|
|
||||||
* @expectedExceptionMessage The country method cannot be used to open a GeoIP2-City database
|
|
||||||
*/
|
|
||||||
public function testIncorrectDatabase()
|
|
||||||
{
|
|
||||||
$reader = new Reader('maxmind-db/test-data/GeoIP2-City-Test.mmdb');
|
|
||||||
$reader->country('10.10.10.10');
|
|
||||||
$reader->close();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException BadMethodCallException
|
|
||||||
* @expectedExceptionMessage The domain method cannot be used to open a GeoIP2-City database
|
|
||||||
*/
|
|
||||||
public function testIncorrectDatabaseFlat()
|
|
||||||
{
|
|
||||||
$reader = new Reader('maxmind-db/test-data/GeoIP2-City-Test.mmdb');
|
|
||||||
$reader->domain('10.10.10.10');
|
|
||||||
$reader->close();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException InvalidArgumentException
|
* @expectedException InvalidArgumentException
|
||||||
* @expectedExceptionMessage is not a valid IP address
|
* @expectedExceptionMessage is not a valid IP address
|
||||||
@ -88,67 +71,10 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$reader->close();
|
$reader->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAnonymousIp()
|
public function checkAllMethods($testCb)
|
||||||
{
|
{
|
||||||
$reader = new Reader('maxmind-db/test-data/GeoIP2-Anonymous-IP-Test.mmdb');
|
foreach (array('city', 'cityIspOrg', 'country', 'omni') as $method) {
|
||||||
$ipAddress = '1.2.0.1';
|
$testCb($method);
|
||||||
|
|
||||||
$record = $reader->anonymousIp($ipAddress);
|
|
||||||
$this->assertSame(true, $record->isAnonymous);
|
|
||||||
$this->assertSame(true, $record->isAnonymousVpn);
|
|
||||||
$this->assertSame(false, $record->isHostingProvider);
|
|
||||||
$this->assertSame(false, $record->isPublicProxy);
|
|
||||||
$this->assertSame(false, $record->isTorExitNode);
|
|
||||||
$this->assertEquals($ipAddress, $record->ipAddress);
|
|
||||||
$reader->close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testConnectionType()
|
|
||||||
{
|
|
||||||
$reader = new Reader('maxmind-db/test-data/GeoIP2-Connection-Type-Test.mmdb');
|
|
||||||
$ipAddress = '1.0.1.0';
|
|
||||||
|
|
||||||
$record = $reader->connectionType($ipAddress);
|
|
||||||
$this->assertEquals('Cable/DSL', $record->connectionType);
|
|
||||||
$this->assertEquals($ipAddress, $record->ipAddress);
|
|
||||||
$reader->close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDomain()
|
|
||||||
{
|
|
||||||
$reader = new Reader('maxmind-db/test-data/GeoIP2-Domain-Test.mmdb');
|
|
||||||
|
|
||||||
$ipAddress = '1.2.0.0';
|
|
||||||
$record = $reader->domain($ipAddress);
|
|
||||||
$this->assertEquals('maxmind.com', $record->domain);
|
|
||||||
$this->assertEquals($ipAddress, $record->ipAddress);
|
|
||||||
$reader->close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testIsp()
|
|
||||||
{
|
|
||||||
$reader = new Reader('maxmind-db/test-data/GeoIP2-ISP-Test.mmdb');
|
|
||||||
|
|
||||||
$ipAddress = '1.128.0.0';
|
|
||||||
$record = $reader->isp($ipAddress);
|
|
||||||
$this->assertEquals(1221, $record->autonomousSystemNumber);
|
|
||||||
$this->assertEquals(
|
|
||||||
'Telstra Pty Ltd',
|
|
||||||
$record->autonomousSystemOrganization
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertEquals('Telstra Internet', $record->isp);
|
|
||||||
$this->assertEquals('Telstra Internet', $record->organization);
|
|
||||||
|
|
||||||
$this->assertEquals($ipAddress, $record->ipAddress);
|
|
||||||
$reader->close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testMetadata()
|
|
||||||
{
|
|
||||||
$reader = new Reader('maxmind-db/test-data/GeoIP2-City-Test.mmdb');
|
|
||||||
$this->assertEquals('GeoIP2-City', $reader->metadata()->databaseType);
|
|
||||||
|
|
||||||
$reader->close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
namespace GeoIp2\Test\Model;
|
namespace GeoIp2\Test\Model;
|
||||||
|
|
||||||
use GeoIp2\Model\Insights;
|
use GeoIp2\Model\Omni;
|
||||||
|
|
||||||
class InsightsTest extends \PHPUnit_Framework_TestCase
|
class OmniTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
public function testFull()
|
public function testFull()
|
||||||
@ -62,19 +62,19 @@ class InsightsTest extends \PHPUnit_Framework_TestCase
|
|||||||
'autonomous_system_organization' => 'AS Organization',
|
'autonomous_system_organization' => 'AS Organization',
|
||||||
'domain' => 'example.com',
|
'domain' => 'example.com',
|
||||||
'ip_address' => '1.2.3.4',
|
'ip_address' => '1.2.3.4',
|
||||||
'is_satellite_provider' => true,
|
'is_satellite_provider' => 1,
|
||||||
'isp' => 'Comcast',
|
'isp' => 'Comcast',
|
||||||
'organization' => 'Blorg',
|
'organization' => 'Blorg',
|
||||||
'user_type' => 'college',
|
'user_type' => 'college',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
$model = new Insights($raw, array('en'));
|
$model = new Omni($raw, array('en'));
|
||||||
|
|
||||||
$this->assertInstanceOf(
|
$this->assertInstanceOf(
|
||||||
'GeoIp2\Model\Insights',
|
'GeoIp2\Model\Omni',
|
||||||
$model,
|
$model,
|
||||||
'GeoIp2\Model\Insights object'
|
'GeoIp2\Model\Omni object'
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertInstanceOf(
|
$this->assertInstanceOf(
|
||||||
@ -130,18 +130,6 @@ class InsightsTest extends \PHPUnit_Framework_TestCase
|
|||||||
'$model->traits'
|
'$model->traits'
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertSame(
|
|
||||||
true,
|
|
||||||
$model->traits->isSatelliteProvider,
|
|
||||||
'$model->traits->isSatelliteProvider is true'
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertSame(
|
|
||||||
false,
|
|
||||||
$model->traits->isAnonymousProxy,
|
|
||||||
'$model->traits->isAnonymousProxy is false'
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
22,
|
22,
|
||||||
$model->maxmind->queriesRemaining,
|
$model->maxmind->queriesRemaining,
|
||||||
@ -159,12 +147,12 @@ class InsightsTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$raw = array('traits' => array('ip_address' => '5.6.7.8'));
|
$raw = array('traits' => array('ip_address' => '5.6.7.8'));
|
||||||
|
|
||||||
$model = new Insights($raw, array('en'));
|
$model = new Omni($raw, array('en'));
|
||||||
|
|
||||||
$this->assertInstanceOf(
|
$this->assertInstanceOf(
|
||||||
'GeoIp2\Model\Insights',
|
'GeoIp2\Model\Omni',
|
||||||
$model,
|
$model,
|
||||||
'GeoIp2\Model\Insights object with no data except traits.ipAddress'
|
'GeoIp2\Model\Omni object with no data except traits.ipAddress'
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertInstanceOf(
|
$this->assertInstanceOf(
|
||||||
@ -243,12 +231,12 @@ class InsightsTest extends \PHPUnit_Framework_TestCase
|
|||||||
);
|
);
|
||||||
|
|
||||||
// checking whether there are exceptions with unknown keys
|
// checking whether there are exceptions with unknown keys
|
||||||
$model = new Insights($raw, array('en'));
|
$model = new Omni($raw, array('en'));
|
||||||
|
|
||||||
$this->assertInstanceOf(
|
$this->assertInstanceOf(
|
||||||
'GeoIp2\Model\Insights',
|
'GeoIp2\Model\Omni',
|
||||||
$model,
|
$model,
|
||||||
'no exception when Insights model gets raw data with unknown keys'
|
'no exception when Omni model gets raw data with unknown keys'
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
@ -198,17 +198,16 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testInsights()
|
public function testOmni()
|
||||||
{
|
{
|
||||||
|
$omni = $this->client($this->getResponse('1.2.3.4'))
|
||||||
|
->omni('1.2.3.4');
|
||||||
|
|
||||||
$record = $this->client($this->getResponse('1.2.3.4'))
|
$this->assertInstanceOf('GeoIp2\Model\Omni', $omni);
|
||||||
->insights('1.2.3.4');
|
|
||||||
|
|
||||||
$this->assertInstanceOf('GeoIp2\Model\Insights', $record);
|
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
42,
|
42,
|
||||||
$record->continent->geonameId,
|
$omni->continent->geonameId,
|
||||||
'continent geoname_id is 42'
|
'continent geoname_id is 42'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -226,15 +225,15 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
|||||||
$client = $this->client($this->getResponse('me'));
|
$client = $this->client($this->getResponse('me'));
|
||||||
|
|
||||||
$this->assertInstanceOf(
|
$this->assertInstanceOf(
|
||||||
'GeoIp2\Model\City',
|
'GeoIp2\Model\CityIspOrg',
|
||||||
$client->city('me'),
|
$client->cityIspOrg('me'),
|
||||||
'can set ip parameter to 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.1/country/1.2.3.5 but did not receive a HTTP body.
|
* @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()
|
public function testNoBodyException()
|
||||||
{
|
{
|
||||||
@ -245,7 +244,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.1/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.0/country/2.2.3.5 but could not decode the response as JSON:
|
||||||
*/
|
*/
|
||||||
public function testBadBodyException()
|
public function testBadBodyException()
|
||||||
{
|
{
|
||||||
@ -333,7 +332,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
|||||||
/**
|
/**
|
||||||
* @expectedException GeoIp2\Exception\HttpException
|
* @expectedException GeoIp2\Exception\HttpException
|
||||||
* @expectedExceptionCode 406
|
* @expectedExceptionCode 406
|
||||||
* @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
|
* @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
|
||||||
*/
|
*/
|
||||||
public function test406Exception()
|
public function test406Exception()
|
||||||
{
|
{
|
||||||
@ -419,9 +418,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
|||||||
'abcdef123456',
|
'abcdef123456',
|
||||||
array('en'),
|
array('en'),
|
||||||
'geoip.maxmind.com',
|
'geoip.maxmind.com',
|
||||||
$guzzleClient,
|
$guzzleClient
|
||||||
27,
|
|
||||||
72
|
|
||||||
);
|
);
|
||||||
$client->country('1.2.3.4');
|
$client->country('1.2.3.4');
|
||||||
|
|
||||||
@ -429,7 +426,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
|||||||
$request = $all_requests[0];
|
$request = $all_requests[0];
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'https://geoip.maxmind.com/geoip/v2.1/country/1.2.3.4',
|
'https://geoip.maxmind.com/geoip/v2.0/country/1.2.3.4',
|
||||||
$request->getUrl(),
|
$request->getUrl(),
|
||||||
'got expected URI for Country request'
|
'got expected URI for Country request'
|
||||||
);
|
);
|
||||||
@ -448,21 +445,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertStringMatchesFormat(
|
$this->assertStringMatchesFormat(
|
||||||
'GeoIP2 PHP API (Guzzle%s)',
|
'GeoIP2 PHP API (Guzzle%s)',
|
||||||
$request->getHeader('User-Agent') . '',
|
$request->getHeader('User-Agent') . '',
|
||||||
'request sets Accept header to GeoIP2 PHP API (Guzzle%s)'
|
'request sets Accept header to application/json'
|
||||||
);
|
|
||||||
|
|
||||||
$curlOptions = $request->getCurlOptions();
|
|
||||||
|
|
||||||
$this->assertEquals(
|
|
||||||
'27000',
|
|
||||||
$curlOptions[CURLOPT_TIMEOUT_MS],
|
|
||||||
'request sets Curl Option Timeout to 27 seconds'
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertEquals(
|
|
||||||
'72000',
|
|
||||||
$curlOptions[CURLOPT_CONNECTTIMEOUT_MS],
|
|
||||||
'request sets Curl Option Connect Timeout to 72 seconds'
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -480,10 +463,6 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
|||||||
$locales,
|
$locales,
|
||||||
'geoip.maxmind.com',
|
'geoip.maxmind.com',
|
||||||
$guzzleClient
|
$guzzleClient
|
||||||
// intentionally not specifying the below, to ensure backwards compatibility
|
|
||||||
//,
|
|
||||||
// 1, // optional timeout
|
|
||||||
// 1 // optional connect timeout
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return $client;
|
return $client;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user