32 Commits

Author SHA1 Message Date
Gregory Oschwald
b45b3c1ed5 Updated alpha note 2013-05-29 07:41:24 -07:00
Gregory Oschwald
3431141943 Updated for 0.2.0 2013-05-29 07:40:18 -07:00
Gregory Oschwald
c90fe87d3d CWD fix 2013-05-24 19:37:10 -07:00
Gregory Oschwald
1c256e1e64 Updated release script for new templates 2013-05-24 19:35:47 -07:00
Gregory Oschwald
1d294bd473 Hopefully a fix for uncommited files 2013-05-24 14:30:51 -07:00
Gregory Oschwald
9a9a1e86b2 Added missing styling 2013-05-24 14:25:57 -07:00
Gregory Oschwald
893c715047 Updated markdown. Remove author. 2013-05-24 14:16:43 -07:00
Gregory Oschwald
f99ac351ab Updated apigen flags 2013-05-24 13:38:58 -07:00
Gregory Oschwald
4d9957ccf5 Create a version file 2013-05-24 13:27:37 -07:00
Gregory Oschwald
3a382f0d26 Updated release script 2013-05-24 13:12:45 -07:00
Gregory Oschwald
c4867ef7c7 Updated release script 2013-05-24 12:58:17 -07:00
Gregory Oschwald
bfb8de7ffa Fixed typo 2013-05-24 12:05:52 -07:00
Gregory Oschwald
e38c46950f Added a basic release script 2013-05-24 12:04:06 -07:00
Gregory Oschwald
7f81643a98 Updated .gitignore 2013-05-24 11:21:48 -07:00
Gregory Oschwald
750c23fb5c Fixed space issue 2013-05-21 13:56:00 -07:00
Gregory Oschwald
e0baddaec0 Added queriesRemaining 2013-05-21 13:46:11 -07:00
Gregory Oschwald
89f1bbdb65 Switched continent_code to code 2013-05-21 13:28:37 -07:00
Gregory Oschwald
559e62a30c Added alpha notice 2013-05-21 12:34:10 -07:00
Gregory Oschwald
b179e29ee7 Rename GenericException to GeoIP2Exception 2013-05-20 15:42:52 -07:00
Gregory Oschwald
73d6f15823 Get rid of references to "Precision" 2013-05-20 15:38:21 -07:00
Gregory Oschwald
2c23be78fe Try --prefer-source to see if reduces Travis errors 2013-05-20 14:13:45 -07:00
Gregory Oschwald
5eda52e1db Add test for city call 2013-05-20 13:47:17 -07:00
Gregory Oschwald
b383cf82b3 Run composer in no interaction mode 2013-05-20 13:38:12 -07:00
Gregory Oschwald
0f76a28527 Update composer if it is old. 2013-05-20 13:31:06 -07:00
Gregory Oschwald
2b1ec4abbe Install with --dev for Coveralls 2013-05-20 13:25:25 -07:00
Gregory Oschwald
ef618d06c1 Fixed broken unit test 2013-05-20 13:18:05 -07:00
Gregory Oschwald
aeba497703 Added a very basic omni test as we didn't cover it previously 2013-05-20 13:15:25 -07:00
Gregory Oschwald
57f6af0bfd Using local composer didn't work 2013-05-20 13:10:46 -07:00
Gregory Oschwald
fd1231e5f8 Updates for Coveralls. Also always installing a local composer as the Travis one is giving us issues 2013-05-20 12:50:10 -07:00
Gregory Oschwald
b077a3cda7 Try Coveralls 2013-05-20 12:42:18 -07:00
Gregory Oschwald
04629e039b Added missing isSatelliteProvider 2013-05-20 11:37:32 -07:00
Gregory Oschwald
f44db25129 Fixed typo 2013-05-20 11:03:38 -07:00
22 changed files with 233 additions and 72 deletions

3
.gitignore vendored
View File

@@ -1,4 +1,5 @@
bin/ _site
.gh-pages
composer.lock composer.lock
composer.phar composer.phar
phpunit.xml phpunit.xml

View File

@@ -7,13 +7,17 @@ php:
before_install: before_install:
- composer self-update - composer self-update
- composer install - composer install --dev -n --prefer-source
- pyrus install pear/PHP_CodeSniffer - pyrus install pear/PHP_CodeSniffer
- phpenv rehash - phpenv rehash
script: script:
- mkdir -p build/logs
- phpcs --standard=PSR2 src/ - phpcs --standard=PSR2 src/
- phpunit - phpunit -c phpunit.xml.dist
after_script:
- php vendor/bin/coveralls
notifications: notifications:
email: email:

View File

@@ -1,6 +1,16 @@
CHANGELOG CHANGELOG
========= =========
0.2.0 (2013-05-29)
------------------
* `GenericException` was renamed to `GeoIP2Exception`.
* We now support more languages. The new languages are de, es, fr, and pt-BR.
* The REST API now returns a record with data about your account. There is
a new geoip.records.MaxMind class for this data.
* The `continentCode` attribute on `Continent` was renamed to `code`.
* Documentation updates.
0.1.1 (2013-05-14) 0.1.1 (2013-05-14)
------------------ ------------------

View File

@@ -1,15 +1,19 @@
# GeoIP2 PHP API # # GeoIP2 PHP API #
**NOTE**: This is an alpha release. The API may change before the final
production release. The first production release will have the version
number 2.0.0.
## Description ## ## Description ##
Currently, this distribution provides an API for the GeoIP2 web services Currently, this distribution provides an API for the [GeoIP2 web services]
(as documented at http://dev.maxmind.com/geoip/geoip2/web-services). (http://dev.maxmind.com/geoip/geoip2/web-services).
In the future, this distribution will also provide the same API for the In the future, this distribution will also provide the same API for the
GeoIP2 downloadable databases. These databases have not yet been GeoIP2 downloadable databases. These databases have not yet been
released as a downloadable product. released as a downloadable product.
See GeoIP2\WebService\Client for details on the web service client See ``GeoIP2\WebService\Client`` for details on the web service client
API. API.
## Installation ## ## Installation ##
@@ -78,8 +82,8 @@ echo $omni->country->isoCode;
## Exceptions ## ## Exceptions ##
For details on the possible errors returned by the web service itself, see For details on the possible errors returned by the web service itself, see
http://dev.maxmind.com/geoip2/geoip/web-services for the GeoIP2 web service the
docs. [GeoIP2 web service docs](http://dev.maxmind.com/geoip2/geoip/web-service).
If the web service returns an explicit error document, this is thrown as a If the web service returns an explicit error document, this is thrown as a
```\GeoIP2\Exception\WebServiceException```. If some other sort of transport ```\GeoIP2\Exception\WebServiceException```. If some other sort of transport
@@ -93,7 +97,7 @@ If the web service returns any status code besides 200, 4xx, or 5xx, this also
becomes a ```\GeoIP2\Exception\HttpException```. becomes a ```\GeoIP2\Exception\HttpException```.
Finally, if the web service returns a 200 but the body is invalid, the client Finally, if the web service returns a 200 but the body is invalid, the client
throws a ```\GeoIP2\Exception\GenericException```. throws a ```\GeoIP2\Exception\GeoIP2Exception```.
## What data is returned? ## ## What data is returned? ##
@@ -105,8 +109,9 @@ piece of data for any given IP address.
Because of these factors, it is possible for any end point to return a record 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 http://dev.maxmind.com/geoip/geoip2/web-services for details on what data See the
each end point may return. [GeoIP2 web service docs](http://dev.maxmind.com/geoip/geoip2/web-services)
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.
@@ -132,11 +137,11 @@ the GeoNames premium data set.
## Reporting data problems ## ## Reporting data problems ##
If the problem you find is that an IP address is incorrectly mapped, If the problem you find is that an IP address is incorrectly mapped,
please submit your correction to MaxMind at please
http://www.maxmind.com/en/correction. [submit your correction to MaxMind](http://www.maxmind.com/en/correction).
If you find some other sort of mistake, like an incorrect spelling, If you find some other sort of mistake, like an incorrect spelling,
please check the GeoNames site (http://www.geonames.org/) first. Once please check the [GeoNames site](http://www.geonames.org/) first. Once
you've searched for a place and found it on the GeoNames map view, there you've searched for a place and found it on the GeoNames map view, there
are a number of links you can use to correct data ("move", "edit", are a number of links you can use to correct data ("move", "edit",
"alternate names", etc.). Once the correction is part of the GeoNames "alternate names", etc.). Once the correction is part of the GeoNames
@@ -144,17 +149,17 @@ data set, it will be automatically incorporated into future MaxMind
releases. releases.
If you are a paying MaxMind customer and you're not sure where to submit If you are a paying MaxMind customer and you're not sure where to submit
a correction, please contact MaxMind support at a correction, please
http://www.maxmind.com/en/support for help. [contact MaxMind support](http://www.maxmind.com/en/support) for help.
## Other Support ## ## Other Support ##
Please report all issues with this code using the GitHub issue tracker Please report all issues with this code using the
at https://github.com/maxmind/GeoIP2-php/issues [GitHub issue tracker](https://github.com/maxmind/GeoIP2-php/issues).
If you are having an issue with a MaxMind service that is not specific If you are having an issue with a MaxMind service that is not specific
to the client API please see http://www.maxmind.com/en/support for to the client API, please see
details. [our support page](http://www.maxmind.com/en/support).
## Requirements ## ## Requirements ##
@@ -172,10 +177,6 @@ PSR-2 style guidelines. Please include unit tests whenever possible.
The GeoIP2 PHP API uses [Semantic Versioning](http://semver.org/). The GeoIP2 PHP API uses [Semantic Versioning](http://semver.org/).
## Author ##
[Gregory Oschwald](mailto:goschwald@maxmind.com)
## Copyright and License ## ## Copyright and License ##
This software is Copyright (c) 2013 by MaxMind, Inc. This software is Copyright (c) 2013 by MaxMind, Inc.

63
bin/release.sh Executable file
View 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 $TAG
git push
git push --tags

View File

@@ -17,7 +17,8 @@
"php": ">=5.3.1" "php": ">=5.3.1"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "3.7.*" "phpunit/phpunit": "3.7.*",
"satooshi/php-coveralls": "dev-master"
}, },
"autoload": { "autoload": {
"psr-0": { "GeoIP2": "src/" } "psr-0": { "GeoIP2": "src/" }

View File

@@ -12,4 +12,9 @@
<directory suffix=".php">./src/GeoIP2/</directory> <directory suffix=".php">./src/GeoIP2/</directory>
</whitelist> </whitelist>
</filter> </filter>
<logging>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
</phpunit> </phpunit>

View File

@@ -5,6 +5,6 @@ namespace GeoIP2\Exception;
/** /**
* This class represents a generic error. * This class represents a generic error.
*/ */
class GenericException extends \Exception class GeoIP2Exception extends \Exception
{ {
} }

View File

@@ -6,7 +6,7 @@ namespace GeoIP2\Exception;
* This class represents an HTTP transport error. * This class represents an HTTP transport error.
*/ */
class HttpException extends GenericException class HttpException extends GeoIP2Exception
{ {
/** /**
* The URI queried * The URI queried

View File

@@ -3,7 +3,7 @@
namespace GeoIP2\Exception; namespace GeoIP2\Exception;
/** /**
* This class represents an error returned by MaxMind's GeoIP2 Precision * This class represents an error returned by MaxMind's GeoIP2
* web service. * web service.
*/ */
class WebServiceException extends HttpException class WebServiceException extends HttpException

View File

@@ -3,14 +3,14 @@
namespace GeoIP2\Model; namespace GeoIP2\Model;
/** /**
* This class provides a model for the data returned by the GeoIP2 Precision * This class provides a model for the data returned by the GeoIP2
* City end point. * City end point.
* *
* The only difference between the City, City/ISP/Org, and Omni model * The only difference between the City, City/ISP/Org, and Omni model
* classes is which 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 Country data for the requested IP * @property \GeoIP2\Record\City $city City data for the requested IP
* address. * address.
* *
* @property \GeoIP2\Record\Continent $continent Continent data for the * @property \GeoIP2\Record\Continent $continent Continent data for the
@@ -23,6 +23,9 @@ namespace GeoIP2\Model;
* @property \GeoIP2\Record\Location $location Location data for the * @property \GeoIP2\Record\Location $location Location data for the
* requested IP address. * requested IP address.
* *
* @property \GeoIP2\Record\MaxMind $maxmind Data related to your MaxMind
* account.
*
* @property \GeoIP2\Record\Country $registeredCountry Registered country * @property \GeoIP2\Record\Country $registeredCountry Registered country
* data for the requested IP address. This record represents the country * data for the requested IP address. This record represents the country
* where the ISP has registered a given IP block in and may differ from the * where the ISP has registered a given IP block in and may differ from the

View File

@@ -3,14 +3,14 @@
namespace GeoIP2\Model; namespace GeoIP2\Model;
/** /**
* This class provides a model for the data returned by the GeoIP2 Precision * This class provides a model for the data returned by the GeoIP2
* City/ISP/Org end point. * City/ISP/Org end point.
* *
* The only difference between the City, City/ISP/Org, and Omni model * The only difference between the City, City/ISP/Org, and Omni model
* classes is which 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 Country data for the requested IP * @property \GeoIP2\Record\City $city City data for the requested IP
* address. * address.
* *
* @property \GeoIP2\Record\Continent $continent Continent data for the * @property \GeoIP2\Record\Continent $continent Continent data for the
@@ -23,6 +23,9 @@ namespace GeoIP2\Model;
* @property \GeoIP2\Record\Location $location Location data for the * @property \GeoIP2\Record\Location $location Location data for the
* requested IP address. * requested IP address.
* *
* @property \GeoIP2\Record\MaxMind $maxmind Data related to your MaxMind
* account.
*
* @property \GeoIP2\Record\Country $registeredCountry Registered country * @property \GeoIP2\Record\Country $registeredCountry Registered country
* data for the requested IP address. This record represents the country * data for the requested IP address. This record represents the country
* where the ISP has registered a given IP block in and may differ from the * where the ISP has registered a given IP block in and may differ from the

View File

@@ -17,6 +17,9 @@ namespace GeoIP2\Model;
* IP address. This object represents the country where MaxMind believes the * IP address. This object represents the country where MaxMind believes the
* end user is located. * end user is located.
* *
* @property \GeoIP2\Record\MaxMind $maxmind Data related to your MaxMind
* account.
*
* @property \GeoIP2\Record\Country $registeredCountry Registered country * @property \GeoIP2\Record\Country $registeredCountry Registered country
* data for the requested IP address. This record represents the country * data for the requested IP address. This record represents the country
* where the ISP has registered a given IP block in and may differ from the * where the ISP has registered a given IP block in and may differ from the
@@ -35,6 +38,7 @@ class Country
private $continent; private $continent;
private $country; private $country;
private $languages; private $languages;
private $maxmind;
private $registeredCountry; private $registeredCountry;
private $representedCountry; private $representedCountry;
private $traits; private $traits;
@@ -55,6 +59,7 @@ class Country
$this->get('country'), $this->get('country'),
$languages $languages
); );
$this->maxmind = new \GeoIP2\Record\MaxMind($this->get('maxmind'));
$this->registeredCountry = new \GeoIP2\Record\Country( $this->registeredCountry = new \GeoIP2\Record\Country(
$this->get('registered_country'), $this->get('registered_country'),
$languages $languages

View File

@@ -3,14 +3,14 @@
namespace GeoIP2\Model; namespace GeoIP2\Model;
/** /**
* This class provides a model for the data returned by the GeoIP2 Precision * This class provides a model for the data returned by the GeoIP2
* Omni end point. * Omni end point.
* *
* The only difference between the City, City/ISP/Org, and Omni model * The only difference between the City, City/ISP/Org, and Omni model
* classes is which 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 Country data for the requested IP * @property \GeoIP2\Record\City $city City data for the requested IP
* address. * address.
* *
* @property \GeoIP2\Record\Continent $continent Continent data for the * @property \GeoIP2\Record\Continent $continent Continent data for the
@@ -23,6 +23,9 @@ namespace GeoIP2\Model;
* @property \GeoIP2\Record\Location $location Location data for the * @property \GeoIP2\Record\Location $location Location data for the
* requested IP address. * requested IP address.
* *
* @property \GeoIP2\Record\MaxMind $maxmind Data related to your MaxMind
* account.
*
* @property \GeoIP2\Record\Country $registeredCountry Registered country * @property \GeoIP2\Record\Country $registeredCountry Registered country
* data for the requested IP address. This record represents the country * data for the requested IP address. This record represents the country
* where the ISP has registered a given IP block in and may differ from the * where the ISP has registered a given IP block in and may differ from the

View File

@@ -7,9 +7,8 @@ namespace GeoIP2\Record;
* *
* This record is returned by all the end points. * This record is returned by all the end points.
* *
* @property string $continentCode A two character continent code * @property string $code A two character continent code like "NA" (North
* like "NA" (North America) or "OC" (Oceania). This attribute is returned * America) or "OC" (Oceania). This attribute is returned by all end points.
* by all end points.
* *
* @property int $geonameId The GeoName ID for the continent. This attribute * @property int $geonameId The GeoName ID for the continent. This attribute
* is returned by all end points. * is returned by all end points.
@@ -27,7 +26,7 @@ class Continent extends AbstractPlaceRecord
* @ignore * @ignore
*/ */
protected $validAttributes = array( protected $validAttributes = array(
'continentCode', 'code',
'geonameId', 'geonameId',
'names' 'names'
); );

View File

@@ -0,0 +1,19 @@
<?php
namespace GeoIP2\Record;
/**
* Contains data about your account.
*
* This record is returned by all the end points.
*
* @property int $queriesRemaining The number of remaining queries you have
* for the end point you are calling.
*/
class MaxMind extends AbstractRecord
{
/**
* @ignore
*/
protected $validAttributes = array('queriesRemaining');
}

View File

@@ -35,6 +35,10 @@ namespace GeoIP2\Record;
* anonymous proxy. See {@link http://dev.maxmind.com/faq/geoip#anonproxy} * anonymous proxy. See {@link http://dev.maxmind.com/faq/geoip#anonproxy}
* for further details. This attribute is returned by all end points. * for further details. This attribute is returned by all end points.
* *
* @property boolean $isSatelliteProvider This is true if the IP belongs
* to a satellite Internet provider. This attribute is returned by all
* end points.
*
* @property string $isp The name of the ISP associated the IP address. * @property string $isp The name of the ISP associated the IP address.
* This attribute is only available from the City/ISP/Org and Omni end * This attribute is only available from the City/ISP/Org and Omni end
* points. * points.

View File

@@ -2,7 +2,7 @@
namespace GeoIP2\WebService; namespace GeoIP2\WebService;
use GeoIP2\Exception\GenericException; use GeoIP2\Exception\GeoIP2Exception;
use GeoIP2\Exception\HttpException; use GeoIP2\Exception\HttpException;
use GeoIP2\Exception\WebServiceException; use GeoIP2\Exception\WebServiceException;
use GeoIP2\Model\City; use GeoIP2\Model\City;
@@ -15,7 +15,7 @@ use Guzzle\Http\Exception\ClientErrorResponseException;
use Guzzle\Http\Exception\ServerErrorResponseException; use Guzzle\Http\Exception\ServerErrorResponseException;
/** /**
* This class provides a client API for all the GeoIP Precision web service's * This class provides a client API for all the GeoIP2 web service's
* end points. The end points are Country, City, City/ISP/Org, and Omni. Each * end points. The end points are Country, City, City/ISP/Org, and Omni. Each
* end point returns a different set of data about an IP address, with Country * end point returns a different set of data about an IP address, with Country
* returning the least data and Omni the most. * returning the least data and Omni the most.
@@ -63,7 +63,7 @@ use Guzzle\Http\Exception\ServerErrorResponseException;
* also becomes a {@link \GeoIP2\Exception\HttpException}. * also becomes a {@link \GeoIP2\Exception\HttpException}.
* *
* Finally, if the web service returns a 200 but the body is invalid, the * Finally, if the web service returns a 200 but the body is invalid, the
* client throws a {@link \GeoIP2\Exception\GenericException}. * client throws a {@link \GeoIP2\Exception\GeoIP2Exception}.
*/ */
class Client class Client
{ {
@@ -100,7 +100,7 @@ class Client
} }
/** /**
* 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
@@ -108,7 +108,7 @@ class Client
* *
* @return \GeoIP2\Model\City * @return \GeoIP2\Model\City
* *
* @throws \GeoIP2\Exception\GenericException if there was a generic * @throws \GeoIP2\Exception\GeoIP2Exception if there was a generic
* error processing your request. * error processing your request.
* @throws \GeoIP2\Exception\HttpException if there was an HTTP transport * @throws \GeoIP2\Exception\HttpException if there was an HTTP transport
* error. * error.
@@ -129,7 +129,7 @@ class Client
* *
* @return \GeoIP2\Model\Country * @return \GeoIP2\Model\Country
* *
* @throws \GeoIP2\Exception\GenericException if there was a generic * @throws \GeoIP2\Exception\GeoIP2Exception if there was a generic
* error processing your request. * error processing your request.
* @throws \GeoIP2\Exception\HttpException if there was an HTTP transport * @throws \GeoIP2\Exception\HttpException if there was an HTTP transport
* error. * error.
@@ -142,7 +142,7 @@ class Client
} }
/** /**
* This method calls the GeoIP2 Precision City/ISP/Org 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
@@ -150,7 +150,7 @@ class Client
* *
* @return \GeoIP2\Model\CityIspOrg * @return \GeoIP2\Model\CityIspOrg
* *
* @throws \GeoIP2\Exception\GenericException if there was a generic * @throws \GeoIP2\Exception\GeoIP2Exception if there was a generic
* error processing your request. * error processing your request.
* @throws \GeoIP2\Exception\HttpException if there was an HTTP transport * @throws \GeoIP2\Exception\HttpException if there was an HTTP transport
* error. * error.
@@ -163,7 +163,7 @@ class Client
} }
/** /**
* This method calls the GeoIP2 Precision Omni endpoint. * This method calls the GeoIP2 Omni 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
@@ -171,7 +171,7 @@ class Client
* *
* @return \GeoIP2\Model\Omni * @return \GeoIP2\Model\Omni
* *
* @throws \GeoIP2\Exception\GenericException if there was a generic * @throws \GeoIP2\Exception\GeoIP2Exception if there was a generic
* error processing your request. * error processing your request.
* @throws \GeoIP2\Exception\HttpException if there was an HTTP transport * @throws \GeoIP2\Exception\HttpException if there was an HTTP transport
* error. * error.
@@ -216,7 +216,7 @@ class Client
private function handleSuccess($response, $uri) private function handleSuccess($response, $uri)
{ {
if ($response->getContentLength() == 0) { if ($response->getContentLength() == 0) {
throw new GenericException( throw new GeoIP2Exception(
"Received a 200 response for $uri but did not " . "Received a 200 response for $uri but did not " .
"receive a HTTP body." "receive a HTTP body."
); );
@@ -225,7 +225,7 @@ class Client
try { try {
return $response->json(); return $response->json();
} catch (RuntimeException $e) { } catch (RuntimeException $e) {
throw new GenericException( throw new GeoIP2Exception(
"Received a 200 response for $uri but could not decode " . "Received a 200 response for $uri but could not decode " .
"the response as JSON: " . $e->getMessage() "the response as JSON: " . $e->getMessage()
); );
@@ -244,7 +244,7 @@ class Client
try { try {
$body = $response->json(); $body = $response->json();
if (!isset($body['code']) || !isset($body['error'])) { if (!isset($body['code']) || !isset($body['error'])) {
throw new GenericException( throw new GeoIP2Exception(
'Response contains JSON but it does not specify ' . 'Response contains JSON but it does not specify ' .
'code or error keys: ' . $response->getBody() 'code or error keys: ' . $response->getBody()
); );

View File

@@ -9,7 +9,7 @@ class CountryTest extends \PHPUnit_Framework_TestCase
private $raw = array( private $raw = array(
'continent' => array( 'continent' => array(
'continent_code' => 'NA', 'code' => 'NA',
'geoname_id' => 42, 'geoname_id' => 42,
'names' => array( 'en' => 'North America' ), 'names' => array( 'en' => 'North America' ),
), ),
@@ -75,8 +75,8 @@ class CountryTest extends \PHPUnit_Framework_TestCase
$this->assertEquals( $this->assertEquals(
'NA', 'NA',
$this->model->continent->continentCode, $this->model->continent->code,
'continent continent_code is NA' 'continent code is NA'
); );
$this->assertEquals( $this->assertEquals(

View File

@@ -8,7 +8,7 @@ class NameTest extends \PHPUnit_Framework_TestCase
{ {
public $raw = array( public $raw = array(
'continent' => array( 'continent' => array(
'continent_code' => 'NA', 'code' => 'NA',
'geoname_id' => 42, 'geoname_id' => 42,
'names' => array( 'names' => array(
'en' => 'North America', 'en' => 'North America',

View File

@@ -17,7 +17,7 @@ class OmniTest extends \PHPUnit_Framework_TestCase
'names' => array( 'en' => 'Minneapolis' ), 'names' => array( 'en' => 'Minneapolis' ),
), ),
'continent' => array( 'continent' => array(
'continent_code' => 'NA', 'code' => 'NA',
'geoname_id' => 42, 'geoname_id' => 42,
'names' => array( 'en' => 'North America' ), 'names' => array( 'en' => 'North America' ),
), ),
@@ -36,6 +36,9 @@ class OmniTest extends \PHPUnit_Framework_TestCase
'postal_confidence' => 33, 'postal_confidence' => 33,
'time_zone' => 'America/Chicago', 'time_zone' => 'America/Chicago',
), ),
'maxmind' => array(
'queries_remaining' => 22,
),
'registered_country' => array( 'registered_country' => array(
'geoname_id' => 2, 'geoname_id' => 2,
'iso_code' => 'CA', 'iso_code' => 'CA',
@@ -127,6 +130,12 @@ class OmniTest extends \PHPUnit_Framework_TestCase
'$model->traits' '$model->traits'
); );
$this->assertEquals(
22,
$model->maxmind->queriesRemaining,
'queriesRemaining is correct'
);
$this->assertEquals( $this->assertEquals(
$raw, $raw,
$model->raw, $model->raw,

View File

@@ -13,7 +13,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
private $country private $country
= array( = array(
'continent' => array( 'continent' => array(
'continent_code' => 'NA', 'code' => 'NA',
'geoname_id' => 42, 'geoname_id' => 42,
'names' => array( 'en' => 'North America' ), 'names' => array( 'en' => 'North America' ),
), ),
@@ -22,6 +22,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
'iso_code' => 'US', 'iso_code' => 'US',
'names' => array( 'en' => 'United States of America' ), 'names' => array( 'en' => 'United States of America' ),
), ),
'maxmind' => array('queries_remaining' => 11),
'traits' => array( 'traits' => array(
'ip_address' => '1.2.3.4', 'ip_address' => '1.2.3.4',
), ),
@@ -100,8 +101,8 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$this->assertEquals( $this->assertEquals(
'NA', 'NA',
$country->continent->continentCode, $country->continent->code,
'continent continent_code is NA' 'continent code is NA'
); );
$this->assertEquals( $this->assertEquals(
@@ -139,6 +140,36 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$country->country->name, $country->country->name,
'country name is United States of America' 'country name is United States of America'
); );
$this->assertEquals(
11,
$country->maxmind->queriesRemaining,
'queriesRemaining is correct'
);
}
public function testOmni()
{
$omni = $this->client($this->getResponse('1.2.3.4'))
->omni('1.2.3.4');
$this->assertInstanceOf('GeoIP2\Model\Omni', $omni);
$this->assertEquals(
42,
$omni->continent->geonameId,
'continent geoname_id is 42'
);
}
public function testCity()
{
$city = $this->client($this->getResponse('1.2.3.4'))
->city('1.2.3.4');
$this->assertInstanceOf('GeoIP2\Model\City', $city);
} }
public function testMe() public function testMe()
@@ -153,7 +184,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* @expectedException GeoIP2\Exception\GenericException * @expectedException GeoIP2\Exception\GeoIP2Exception
* @expectedExceptionMessage Received a 200 response for https://geoip.maxmind.com/geoip/v2.0/country/1.2.3.5 but did not receive a HTTP body. * @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()
@@ -164,7 +195,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* @expectedException GeoIP2\Exception\GenericException * @expectedException GeoIP2\Exception\GeoIP2Exception
* @expectedExceptionMessage Received a 200 response for https://geoip.maxmind.com/geoip/v2.0/country/2.2.3.5 but could not decode the response as JSON: * @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()
@@ -201,7 +232,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* @expectedException GeoIP2\Exception\GenericException * @expectedException GeoIP2\Exception\GeoIP2Exception
* @expectedExceptionMessage Response contains JSON but it does not specify code or error keys * @expectedExceptionMessage Response contains JSON but it does not specify code or error keys
*/ */
public function testWeirdErrorBodyIPException() public function testWeirdErrorBodyIPException()