19 Commits

Author SHA1 Message Date
Gregory Oschwald
7fa971aef8 Updated .gitignore 2013-10-21 11:15:22 -07:00
Gregory Oschwald
edb6940c74 Updated exception text in test 2013-10-21 11:09:27 -07:00
Gregory Oschwald
57cb77a53c Updated version in example composer.json 2013-10-21 11:04:28 -07:00
Gregory Oschwald
8aedaa5f91 Doc updates 2013-10-21 11:03:02 -07:00
Gregory Oschwald
87f6e2ad6b Require new version of MaxMind DB API 2013-10-21 11:00:02 -07:00
Gregory Oschwald
6bcd0ab21e Removed Get Satisfaction link 2013-10-21 09:10:03 -07:00
Gregory Oschwald
e03b9558a9 Tidying and doc fixes 2013-10-21 06:18:12 -07:00
Gregory Oschwald
234dcaff7c Renamed languages to locales in the code 2013-10-17 12:58:21 -07:00
Gregory Oschwald
b8188bc558 language code -> locale code 2013-10-17 10:28:31 -07:00
Gregory Oschwald
8f16ed6115 Merge branch 'leading-backslash' of github.com:BenMorel/GeoIP2-php into BenMorel-leading-backslash 2013-10-16 10:45:50 -07:00
Gregory Oschwald
8f3331002a Merge branch 'unused-imports' of github.com:BenMorel/GeoIP2-php into BenMorel-unused-imports 2013-10-16 10:43:47 -07:00
Benjamin Morel
b4b0341307 Fixed typo in exception names 2013-10-16 17:33:29 +00:00
Benjamin Morel
ee00329652 Removed unused imports 2013-10-16 17:30:18 +00:00
Benjamin Morel
e8fa9a3a24 Removed the leading backslash on imports 2013-10-16 17:27:40 +00:00
Gregory Oschwald
167433de0c Added iterface for Reader/Client.
It could use a better name.
2013-10-02 06:54:03 -07:00
Gregory Oschwald
c584dbfd6b Added more info to comment 2013-09-19 08:07:24 -07:00
Gregory Oschwald
c642a32b0c Added some comments in examples 2013-09-19 07:52:44 -07:00
Gregory Oschwald
decfda7e90 Added missing documentation on $languages param 2013-08-02 13:34:53 -07:00
Gregory Oschwald
3a560452af Added more detailed examples 2013-08-02 13:32:21 -07:00
23 changed files with 251 additions and 167 deletions

1
.gitignore vendored
View File

@@ -1,5 +1,6 @@
_site
.gh-pages
.idea
composer.lock
composer.phar
phpunit.xml

View File

@@ -1,6 +1,15 @@
CHANGELOG
=========
0.5.0 (2013-10-21)
------------------
* Renamed $languages constructor parameters to $locales for both the Client
and Reader classes.
* Documentation and code clean-up (Ben Morel).
* Added the interface `GeoIp2\ProviderInterface`, which is implemented by both
`\GeoIp2\Database\Reader` and `\GeoIp2\WebService\Client`.
0.4.0 (2013-07-16)
------------------

View File

@@ -8,9 +8,6 @@ release, which will be numbered 2.0.0.
You may find information on the GeoIP2 beta release process on [our
website](http://www.maxmind.com/en/geoip2_beta).
To provide feedback or get support during the beta, please see the
[MaxMind Customer Community](https://getsatisfaction.com/maxmind).
## Description ##
This distribution provides an API for the [GeoIP2 web services]
@@ -28,7 +25,7 @@ To do this, add `geoip2/geoip2` to your `composer.json` file.
```json
{
"require": {
"geoip2/geoip2": "0.4.*"
"geoip2/geoip2": "0.5.*"
}
}
```
@@ -55,6 +52,16 @@ You can autoload all dependencies by adding this to your code:
```
require 'vendor/autoload.php';
```
### Optional C Extension ###
The [MaxMind DB API](https://github.com/maxmind/MaxMind-DB-Reader-php)
includes an optional C extension that you may install to dramatically increase
the performance of lookups in GeoIP2 or GeoLite2 databases. To install, please
follow the instructions included with that API.
The extension has no effect on web-service lookups.
## Database Reader ##
### Usage ###
@@ -79,11 +86,30 @@ See the API documentation for more details.
```php
<?php
require_once 'vendor/autoload.php';
use \GeoIp2\Database\Reader;
use GeoIp2\Database\Reader;
// This creates the Reader object, which should be reused across
// lookups.
$reader = new Reader('/usr/local/share/GeoIP/GeoIP2-City.mmdb');
// Replace "city" with the appropriate method for your database, e.g.,
// "country".
$record = $reader->city('128.101.101.101');
print($record->country->isoCode . "\n"); // 'US'
print($record->country->name . "\n"); // 'United States'
print($record->country->names['zh-CN'] . "\n"); // '美国'
print($record->mostSpecificSubdivision->name . "\n"); // 'Minnesota'
print($record->mostSpecificSubdivision->isoCode . "\n"); // 'MN'
print($record->city->name . "\n"); // 'Minneapolis'
print($record->postal->code . "\n"); // '55455'
print($record->location->latitude . "\n"); // 44.9733
print($record->location->longitude . "\n"); // -93.2323
$reader = new Reader('/usr/local/share/GeoIP2/GeoIP2-City.mmdb');
$record = $reader->city('24.24.24.24');
print($record->country->isoCode);
```
## Web Service Client ##
@@ -108,11 +134,31 @@ See the API documentation for more details.
```php
<?php
require_once 'vendor/autoload.php';
use \GeoIp2\WebService\Client;
use GeoIp2\WebService\Client;
// This creates a Client object that can be reused across requests.
// Replace "42" with your user ID and "license_key" with your license
// key.
$client = new Client(42, 'abcdef123456');
$omni = $client->omni('24.24.24.24');
print($omni->country->isoCode);
// Replace "city" with the method corresponding to the web service that
// you are using, e.g., "country", "cityIspOrg", "omni".
$record = $client->city('128.101.101.101');
print($record->country->isoCode . "\n"); // 'US'
print($record->country->name . "\n"); // 'United States'
print($record->country->names['zh-CN'] . "\n"); // '美国'
print($record->mostSpecificSubdivision->name . "\n"); // 'Minnesota'
print($record->mostSpecificSubdivision->isoCode . "\n"); // 'MN'
print($record->city->name . "\n"); // 'Minneapolis'
print($record->postal->code . "\n"); // '55455'
print($record->location->latitude . "\n"); // 44.9733
print($record->location->longitude . "\n"); // -93.2323
```
### What data is returned? ###

View File

@@ -14,7 +14,7 @@
],
"require": {
"guzzle/guzzle": "3.*",
"maxmind-db/reader": "0.1.*",
"maxmind-db/reader": "0.2.*",
"php": ">=5.3.1"
},
"require-dev": {

View File

@@ -3,10 +3,7 @@
namespace GeoIp2\Database;
use GeoIp2\Exception\AddressNotFoundException;
use GeoIp2\Model\City;
use GeoIp2\Model\CityIspOrg;
use GeoIp2\Model\Country;
use GeoIp2\Model\Omni;
use GeoIp2\ProviderInterface;
use MaxMind\Db\Reader as DbReader;
/**
@@ -17,7 +14,7 @@ use MaxMind\Db\Reader as DbReader;
* 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
* create a reader object, specifying a file name. You then call the method
@@ -38,24 +35,26 @@ use MaxMind\Db\Reader as DbReader;
* will be thrown.
*
*/
class Reader
class Reader implements ProviderInterface
{
private $dbReader;
private $languages;
private $locales;
/**
* Constructor.
*
* @param string $filename The path to the GeoIP2 database file.
* @param array $locales List of locale codes to use in name property
* from most preferred to least preferred.
* @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
* is corrupt or invalid
*/
public function __construct(
$filename,
$languages = array('en')
$locales = array('en')
) {
$this->dbReader = new DbReader($filename);
$this->languages = $languages;
$this->locales = $locales;
}
/**
@@ -137,7 +136,7 @@ class Reader
$record['traits']['ip_address'] = $ipAddress;
$class = "GeoIp2\\Model\\" . $class;
return new $class($record, $this->languages);
return new $class($record, $this->locales);
}
/**

View File

@@ -17,7 +17,7 @@ class HttpException extends GeoIp2Exception
$message,
$httpStatus,
$uri,
Exception $previous = null
\Exception $previous = null
) {
$this->uri = $uri;
parent::__construct($message, $httpStatus, $previous);

View File

@@ -18,7 +18,7 @@ class InvalidRequestException extends HttpException
$error,
$httpStatus,
$uri,
Exception $previous = null
\Exception $previous = null
) {
$this->error = $error;
parent::__construct($message, $httpStatus, $uri, $previous);

View File

@@ -74,18 +74,18 @@ class City extends Country
/**
* @ignore
*/
public function __construct($raw, $languages)
public function __construct($raw, $locales)
{
parent::__construct($raw, $languages);
parent::__construct($raw, $locales);
$this->city = new \GeoIp2\Record\City($this->get('city'), $languages);
$this->city = new \GeoIp2\Record\City($this->get('city'), $locales);
$this->location = new \GeoIp2\Record\Location($this->get('location'));
$this->postal = new \GeoIp2\Record\Postal($this->get('postal'));
$this->createSubdivisions($raw, $languages);
$this->createSubdivisions($raw, $locales);
}
private function createSubdivisions($raw, $languages)
private function createSubdivisions($raw, $locales)
{
if (!isset($raw['subdivisions'])) {
return;
@@ -94,7 +94,7 @@ class City extends Country
foreach ($raw['subdivisions'] as $sub) {
array_push(
$this->subdivisions,
new \GeoIp2\Record\Subdivision($sub, $languages)
new \GeoIp2\Record\Subdivision($sub, $locales)
);
}
}
@@ -113,8 +113,8 @@ class City extends Country
private function mostSpecificSubdivision()
{
return empty($this->subdivisions)?
new \GeoIp2\Record\Subdivision(array(), $this->languages):
return empty($this->subdivisions) ?
new \GeoIp2\Record\Subdivision(array(), $this->locales) :
end($this->subdivisions);
}
}

View File

@@ -37,7 +37,7 @@ class Country
{
private $continent;
private $country;
private $languages;
private $locales;
private $maxmind;
private $registeredCountry;
private $representedCountry;
@@ -47,30 +47,30 @@ class Country
/**
* @ignore
*/
public function __construct($raw, $languages)
public function __construct($raw, $locales)
{
$this->raw = $raw;
$this->continent = new \GeoIp2\Record\Continent(
$this->get('continent'),
$languages
$locales
);
$this->country = new \GeoIp2\Record\Country(
$this->get('country'),
$languages
$locales
);
$this->maxmind = new \GeoIp2\Record\MaxMind($this->get('maxmind'));
$this->registeredCountry = new \GeoIp2\Record\Country(
$this->get('registered_country'),
$languages
$locales
);
$this->representedCountry = new \GeoIp2\Record\RepresentedCountry(
$this->get('represented_country'),
$languages
$locales
);
$this->traits = new \GeoIp2\Record\Traits($this->get('traits'));
$this->languages = $languages;
$this->locales = $locales;
}
/**
@@ -84,7 +84,7 @@ class Country
/**
* @ignore
*/
public function __get ($attr)
public function __get($attr)
{
if ($attr != "instance" && isset($this->$attr)) {
return $this->$attr;

View File

@@ -0,0 +1,34 @@
<?php
namespace GeoIp2;
interface ProviderInterface
{
/**
* @param ipAddress
* IPv4 or IPv6 address to lookup.
* @return \GeoIp2\Model\Country A Country model for the requested IP address.
*/
public function country($ipAddress);
/**
* @param ipAddress
* IPv4 or IPv6 address to lookup.
* @return \GeoIp2\Model\City A City model for the requested IP address.
*/
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);
}

View File

@@ -4,14 +4,14 @@ namespace GeoIp2\Record;
abstract class AbstractPlaceRecord extends AbstractRecord
{
private $languages;
private $locales;
/**
* @ignore
*/
public function __construct($record, $languages)
public function __construct($record, $locales)
{
$this->languages = $languages;
$this->locales = $locales;
parent::__construct($record);
}
@@ -29,9 +29,9 @@ abstract class AbstractPlaceRecord extends AbstractRecord
private function name()
{
foreach ($this->languages as $language) {
if (isset($this->names[$language])) {
return $this->names[$language];
foreach ($this->locales as $locale) {
if (isset($this->names[$locale])) {
return $this->names[$locale];
}
}
}

View File

@@ -14,10 +14,10 @@ namespace GeoIp2\Record;
* @property int $geonameId The GeoName ID for the city. This attribute
* is returned by all end points.
*
* @property string $name The name of the city based on the languages list
* @property string $name The name of the city based on the locales list
* passed to the constructor. This attribute is returned by all end points.
*
* @property array $names A array map where the keys are language codes
* @property array $names A array map where the keys are locale codes
* and the values are names. This attribute is returned by all end points.
*/
class City extends AbstractPlaceRecord

View File

@@ -14,10 +14,10 @@ namespace GeoIp2\Record;
* is returned by all end points.
*
* @property string $name Returns the name of the continent based on the
* languages list passed to the constructor. This attribute is returned by
* locales list passed to the constructor. This attribute is returned by
* all end points.
*
* @property array $names An array map where the keys are language codes
* @property array $names An array map where the keys are locale codes
* and the values are names. This attribute is returned by all end points.
*/
class Continent extends AbstractPlaceRecord

View File

@@ -18,10 +18,10 @@ namespace GeoIp2\Record;
* 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 languages list
* @property string $name The name of the country based on the locales list
* passed to the constructor. This attribute is returned by all end points.
*
* @property array $names An array map where the keys are language codes and
* @property array $names An array map where the keys are locale codes and
* the values are names. This attribute is returned by all end points.
*/
class Country extends AbstractPlaceRecord

View File

@@ -22,10 +22,10 @@ namespace GeoIp2\Record;
* 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 languages list
* @property string $name The name of the country based on the locales list
* passed to the constructor. This attribute is returned by all end points.
*
* @property array $names An array map where the keys are language codes and
* @property array $names An array map where the keys are locale codes and
* the values are names. This attribute is returned by all end points.
*
* @property string $type A string indicating the type of entity that is

View File

@@ -20,14 +20,14 @@ namespace GeoIp2\Record;
* http://en.wikipedia.org/wiki/ISO_3166-2 ISO 3166-2 code}. This attribute
* is returned by all end points except Country.
*
* @property string $name The name of the subdivision based on the languages
* @property string $name The name of the subdivision based on the locales
* list passed to the constructor. This attribute is returned by all end
* points except Country.
*
* @property array $names An array map where the keys are language codes and
* @property array $names An array map where the keys are locale codes and
* the values are names. This attribute is returned by all end points except
* Country.
*/
*/
class Subdivision extends AbstractPlaceRecord
{
/**

View File

@@ -2,18 +2,15 @@
namespace GeoIp2\WebService;
use GeoIp2\Exception\GeoIp2Exception;
use GeoIp2\Exception\HttpException;
use GeoIp2\Exception\AddressNotFoundException;
use GeoIp2\Exception\AuthenticationException;
use GeoIp2\Exception\GeoIp2Exception;
use GeoIp2\Exception\HttpException;
use GeoIp2\Exception\InvalidRequestException;
use GeoIp2\Exception\OutOfQueriesException;
use GeoIp2\Model\City;
use GeoIp2\Model\CityIspOrg;
use GeoIp2\Model\Country;
use GeoIp2\Model\Omni;
use Guzzle\Http\Client as GuzzleClient;
use GeoIp2\ProviderInterface;
use Guzzle\Common\Exception\RuntimeException;
use Guzzle\Http\Client as GuzzleClient;
use Guzzle\Http\Exception\ClientErrorResponseException;
use Guzzle\Http\Exception\ServerErrorResponseException;
@@ -48,20 +45,20 @@ use Guzzle\Http\Exception\ServerErrorResponseException;
*
* If the request fails, the client class throws an exception.
*/
class Client
class Client implements ProviderInterface
{
private $userId;
private $licenseKey;
private $languages;
private $locales;
private $host;
private $guzzleClient;
/**
* Constructor.
*
* @param int $userId Your MaxMind user ID
* @param int $userId Your MaxMind user ID
* @param string $licenseKey Your MaxMind license key
* @param array $languages List of language codes to use in name property
* @param array $locales List of locale codes to use in name property
* from most preferred to least preferred.
* @param string $host Optional host parameter
* @param object $guzzleClient Optional Guzzle client to use (to facilitate
@@ -70,13 +67,13 @@ class Client
public function __construct(
$userId,
$licenseKey,
$languages = array('en'),
$locales = array('en'),
$host = 'geoip.maxmind.com',
$guzzleClient = null
) {
$this->userId = $userId;
$this->licenseKey = $licenseKey;
$this->languages = $languages;
$this->locales = $locales;
$this->host = $host;
// To enable unit testing
$this->guzzleClient = $guzzleClient;
@@ -95,7 +92,7 @@ class Client
* 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\QutOfQueriesException if your account is out
* @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.
@@ -127,7 +124,7 @@ class Client
* 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\QutOfQueriesException if your account is out
* @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.
@@ -159,7 +156,7 @@ class Client
* 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\QutOfQueriesException if your account is out
* @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.
@@ -191,7 +188,7 @@ class Client
* 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\QutOfQueriesException if your account is out
* @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.
@@ -231,7 +228,7 @@ class Client
if ($response && $response->isSuccessful()) {
$body = $this->handleSuccess($response, $uri);
$class = "GeoIp2\\Model\\" . $class;
return new $class($body, $this->languages);
return new $class($body, $this->locales);
} else {
$this->handleNon200($response, $uri);
}
@@ -261,8 +258,6 @@ class Client
{
$status = $response->getStatusCode();
$body = array();
if ($response->getContentLength() > 0) {
if (strstr($response->getContentType(), 'json')) {
try {

View File

@@ -6,7 +6,7 @@ use GeoIp2\Database\Reader;
class ReaderTest extends \PHPUnit_Framework_TestCase
{
public function testDefaultLanguage()
public function testDefaultLocale()
{
$reader = new Reader('maxmind-db/test-data/GeoIP2-City-Test.mmdb');
// Needed for PHP 5.3
@@ -20,7 +20,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
$reader->close();
}
public function testLanguageList()
public function testLocaleList()
{
$reader = new Reader(
'maxmind-db/test-data/GeoIP2-City-Test.mmdb',
@@ -62,7 +62,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
/**
* @expectedException InvalidArgumentException
* @expectedExceptionMessage invalid is not a valid IP address
* @expectedExceptionMessage is not a valid IP address
*/
public function testInvalidAddress()
{

View File

@@ -9,19 +9,19 @@ class CountryTest extends \PHPUnit_Framework_TestCase
private $raw = array(
'continent' => array(
'code' => 'NA',
'code' => 'NA',
'geoname_id' => 42,
'names' => array( 'en' => 'North America' ),
'names' => array('en' => 'North America'),
),
'country' => array(
'geoname_id' => 1,
'iso_code' => 'US',
'names' => array( 'en' => 'United States of America' ),
'iso_code' => 'US',
'names' => array('en' => 'United States of America'),
),
'registered_country' => array(
'geoname_id' => 2,
'iso_code' => 'CA',
'names' => array( 'en' => 'Canada' ),
'iso_code' => 'CA',
'names' => array('en' => 'Canada'),
),
'traits' => array(
'ip_address' => '1.2.3.4',
@@ -30,12 +30,12 @@ class CountryTest extends \PHPUnit_Framework_TestCase
private $model;
public function setUp ()
public function setUp()
{
$this->model = new Country($this->raw, array('en'));
}
public function testObjects ()
public function testObjects()
{
$this->assertInstanceOf(
'GeoIp2\Model\Country',
@@ -80,7 +80,7 @@ class CountryTest extends \PHPUnit_Framework_TestCase
);
$this->assertEquals(
array( 'en' => 'North America' ),
array('en' => 'North America'),
$this->model->continent->names,
'continent names'
);
@@ -104,7 +104,7 @@ class CountryTest extends \PHPUnit_Framework_TestCase
);
$this->assertEquals(
array( 'en' => 'United States of America' ),
array('en' => 'United States of America'),
$this->model->country->names,
'country name'
);
@@ -134,7 +134,7 @@ class CountryTest extends \PHPUnit_Framework_TestCase
);
$this->assertEquals(
array( 'en' => 'Canada' ),
array('en' => 'Canada'),
$this->model->registeredCountry->names,
'registered_country names'
);
@@ -145,7 +145,7 @@ class CountryTest extends \PHPUnit_Framework_TestCase
'registered_country name is Canada'
);
foreach (array( 'isAnonymousProxy', 'isSatelliteProvider' ) as $meth) {
foreach (array('isAnonymousProxy', 'isSatelliteProvider') as $meth) {
$this->assertEquals(
0,
$this->model->traits->$meth,

View File

@@ -7,31 +7,31 @@ use GeoIp2\Model\Country;
class NameTest extends \PHPUnit_Framework_TestCase
{
public $raw = array(
'continent' => array(
'code' => 'NA',
'geoname_id' => 42,
'names' => array(
'en' => 'North America',
'zh-CN' => '北美洲',
),
'continent' => array(
'code' => 'NA',
'geoname_id' => 42,
'names' => array(
'en' => 'North America',
'zh-CN' => '北美洲',
),
'country' => array(
'geoname_id' => 1,
'iso_code' => 'US',
'names' => array(
'en' => 'United States of America',
'ru' => 'объединяет государства',
'zh-CN' => '美国',
),
),
'country' => array(
'geoname_id' => 1,
'iso_code' => 'US',
'names' => array(
'en' => 'United States of America',
'ru' => 'объединяет государства',
'zh-CN' => '美国',
),
'traits' => array(
'ip_address' => '1.2.3.4',
),
);
),
'traits' => array(
'ip_address' => '1.2.3.4',
),
);
public function testFallback()
{
$model = new Country($this->raw, array( 'ru', 'zh-CN', 'en' ));
$model = new Country($this->raw, array('ru', 'zh-CN', 'en'));
$this->assertEquals(
'北美洲',

View File

@@ -14,58 +14,58 @@ class OmniTest extends \PHPUnit_Framework_TestCase
'city' => array(
'confidence' => 76,
'geoname_id' => 9876,
'names' => array( 'en' => 'Minneapolis' ),
'names' => array('en' => 'Minneapolis'),
),
'continent' => array(
'code' => 'NA',
'code' => 'NA',
'geoname_id' => 42,
'names' => array( 'en' => 'North America' ),
'names' => array('en' => 'North America'),
),
'country' => array(
'confidence' => 99,
'geoname_id' => 1,
'iso_code' => 'US',
'names' => array( 'en' => 'United States of America' ),
'iso_code' => 'US',
'names' => array('en' => 'United States of America'),
),
'location' => array(
'accuracy_radius' => 1500,
'latitude' => 44.98,
'longitude' => 93.2636,
'metro_code' => 765,
'postal_code' => '55401',
'accuracy_radius' => 1500,
'latitude' => 44.98,
'longitude' => 93.2636,
'metro_code' => 765,
'postal_code' => '55401',
'postal_confidence' => 33,
'time_zone' => 'America/Chicago',
'time_zone' => 'America/Chicago',
),
'maxmind' => array(
'queries_remaining' => 22,
),
'registered_country' => array(
'geoname_id' => 2,
'iso_code' => 'CA',
'names' => array( 'en' => 'Canada' ),
'iso_code' => 'CA',
'names' => array('en' => 'Canada'),
),
'represented_country' => array(
'geoname_id' => 3,
'iso_code' => 'GB',
'names' => array( 'en' => 'United Kingdom' ),
'iso_code' => 'GB',
'names' => array('en' => 'United Kingdom'),
),
'subdivisions' => array(
array(
'confidence' => 88,
'geoname_id' => 574635,
'iso_code' => 'MN',
'names' => array( 'en' => 'Minnesota' ),
'iso_code' => 'MN',
'names' => array('en' => 'Minnesota'),
)
),
'traits' => array(
'autonomous_system_number' => 1234,
'autonomous_system_number' => 1234,
'autonomous_system_organization' => 'AS Organization',
'domain' => 'example.com',
'ip_address' => '1.2.3.4',
'is_satellite_provider' => 1,
'isp' => 'Comcast',
'organization' => 'Blorg',
'user_type' => 'college',
'domain' => 'example.com',
'ip_address' => '1.2.3.4',
'is_satellite_provider' => 1,
'isp' => 'Comcast',
'organization' => 'Blorg',
'user_type' => 'college',
),
);
@@ -145,7 +145,7 @@ class OmniTest extends \PHPUnit_Framework_TestCase
public function testEmptyObjects()
{
$raw = array( 'traits' => array( 'ip_address' => '5.6.7.8' ) );
$raw = array('traits' => array('ip_address' => '5.6.7.8'));
$model = new Omni($raw, array('en'));
@@ -220,14 +220,14 @@ class OmniTest extends \PHPUnit_Framework_TestCase
public function testUnknown()
{
$raw = array(
'new_top_level' => array( 'foo' => 42 ),
'city' => array(
'new_top_level' => array('foo' => 42),
'city' => array(
'confidence' => 76,
'geoname_id_id' => 9876,
'names' => array( 'en' => 'Minneapolis' ),
'geoname_id_id' => 9876,
'names' => array('en' => 'Minneapolis'),
'population' => 50,
),
'traits' => array( 'ip_address' => '5.6.7.8' )
'traits' => array('ip_address' => '5.6.7.8')
);
// checking whether there are exceptions with unknown keys

View File

@@ -13,14 +13,14 @@ class ClientTest extends \PHPUnit_Framework_TestCase
private $country
= array(
'continent' => array(
'code' => 'NA',
'code' => 'NA',
'geoname_id' => 42,
'names' => array( 'en' => 'North America' ),
'names' => array('en' => 'North America'),
),
'country' => array(
'geoname_id' => 1,
'iso_code' => 'US',
'names' => array( 'en' => 'United States of America' ),
'iso_code' => 'US',
'names' => array('en' => 'United States of America'),
),
'maxmind' => array('queries_remaining' => 11),
'traits' => array(
@@ -44,11 +44,11 @@ class ClientTest extends \PHPUnit_Framework_TestCase
),
'1.2.3.5' => $this->response('country', 200),
'2.2.3.5' => $this->response('country', 200, 'bad body'),
'1.2.3.6'=> $this->response(
'1.2.3.6' => $this->response(
'error',
400,
array(
'code' => 'IP_ADDRESS_INVALID',
'code' => 'IP_ADDRESS_INVALID',
'error' => 'The value "1.2.3" is not a valid ip address'
)
),
@@ -59,7 +59,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
'1.2.3.8' => $this->response(
'error',
400,
array( 'weird' => 42 )
array('weird' => 42)
),
'1.2.3.9' => $this->response(
'error',
@@ -82,51 +82,51 @@ class ClientTest extends \PHPUnit_Framework_TestCase
null,
'text/plain'
),
'1.2.3.13'=> $this->response(
'1.2.3.13' => $this->response(
'error',
404,
array(
'code' => 'IP_ADDRESS_NOT_FOUND',
'code' => 'IP_ADDRESS_NOT_FOUND',
'error' => 'The address "1.2.3.13" is not in our database.'
)
),
'1.2.3.14'=> $this->response(
'1.2.3.14' => $this->response(
'error',
400,
array(
'code' => 'IP_ADDRESS_RESERVED',
'code' => 'IP_ADDRESS_RESERVED',
'error' => 'The address "1.2.3.14" is a private address.'
)
),
'1.2.3.15'=> $this->response(
'1.2.3.15' => $this->response(
'error',
401,
array(
'code' => 'AUTHORIZATION_INVALID',
'code' => 'AUTHORIZATION_INVALID',
'error' => 'A user ID and license key are required to use this service'
)
),
'1.2.3.16'=> $this->response(
'1.2.3.16' => $this->response(
'error',
401,
array(
'code' => 'LICENSE_KEY_REQUIRED',
'code' => 'LICENSE_KEY_REQUIRED',
'error' => 'A license key is required to use this service'
)
),
'1.2.3.17'=> $this->response(
'1.2.3.17' => $this->response(
'error',
401,
array(
'code' => 'USER_ID_REQUIRED',
'code' => 'USER_ID_REQUIRED',
'error' => 'A user ID is required to use this service'
)
),
'1.2.3.18'=> $this->response(
'1.2.3.18' => $this->response(
'error',
402,
array(
'code' => 'OUT_OF_QUERIES',
'code' => 'OUT_OF_QUERIES',
'error' => 'The license key you have provided is out of queries.'
)
),
@@ -178,7 +178,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
);
$this->assertEquals(
array( 'en' => 'United States of America' ),
array('en' => 'United States of America'),
$country->country->names,
'country names'
);
@@ -450,7 +450,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
}
private function client($response, $languages = array('en'))
private function client($response, $locales = array('en'))
{
$plugin = new MockPlugin();
$plugin->addResponse($response);
@@ -460,7 +460,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$client = new Client(
42,
'abcdef123456',
$languages,
$locales,
'geoip.maxmind.com',
$guzzleClient
);
@@ -478,7 +478,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$headers = array();
if ($contentType) {
$headers['Content-Type'] = $contentType;
} elseif ($status == 200 || ( $status >= 400 && $status < 500 )) {
} elseif ($status == 200 || ($status >= 400 && $status < 500)) {
$headers['Content-Type'] = 'application/vnd.maxmind.com-'
. $endpoint . '+json; charset=UTF-8; version=1.0;';
}
@@ -486,7 +486,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
if ($bad) {
$body = '{ invalid: }';
} elseif (is_array($body)) {
$body = json_encode($body);
$body = json_encode($body);
}
$headers['Content-Length'] = strlen($body);

View File

@@ -1,6 +1,6 @@
<?php
if (!$loader = @include __DIR__.'/../vendor/autoload.php') {
if (!$loader = @include __DIR__ . '/../vendor/autoload.php') {
die('Project dependencies missing');
}