Corrected example. Cleaned up doc a bit.

This commit is contained in:
Gregory Oschwald 2013-05-10 12:32:02 -07:00
parent ee6d3b4b27
commit 1d07dccc73

View File

@ -3,33 +3,79 @@
## 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/precision). (as documented at 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 ##
**Note: package not yet uploaded**
### Define Your Dependencies ###
We recommend installing this package with [Composer](http://getcomposer.org/).
To do this, add ```NOT UPLOADED YET``` to your ```composer.json``` file.
```json
{
"require": {
"NOT YET UPLOADED": "1.0.*"
}
}
```
### Install Composer ###
Run in your project root:
```
curl -s http://getcomposer.org/installer | php
```
### Install Depdendencies ###
Run in your project root:
```
php composer.phar install
```
### Require Autoloader ###
You can autoload all dependencies by adding this to your code:
```
require 'vendor/autoload.php';
```
## Usage ## ## Usage ##
The basic API for this class is the same for all of the web service end To use this API, you must create a new ``\GeoIP2\Webservice\Client``
points. First you create a web service client object with your MaxMind object with your ``userId`` and ``licenseKey``, then you call the method
``userId`` and ``licenseKey``, then you call the method corresponding to corresponding to a specific end point, passing it the IP address you want to
a specific end point, passing it the IP address you want to look up. look up.
If the request succeeds, the method call will return a model class for the end 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 classes, each of point you called. This model in turn contains multiple record classes, each of
which represents part of the data returned by the web service. which represents part of the data returned by the web service.
See the API documentation for more details.
## Example ## ## Example ##
>>> use \GeoIP2\Webservice\Client; ```php
>>> $client = new Client(42, 'abcdef123456'); <?php
>>> $omni = $client.omni('24.24.24.24'); require_once 'vendor/autoload.php';
>>> $country = $omni.country; use \GeoIP2\Webservice\Client;
>>> echo $country.isoCode;
$client = new Client(42, 'abcdef123456');
$omni = $client->omni('24.24.24.24');
echo $omni->country->isoCode;
```
## Exceptions ## ## Exceptions ##
@ -61,18 +107,18 @@ 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/precision for details on what data each end See http://dev.maxmind.com/geoip/geoip2/web-services for details on what data
point may return. each end point may return.
The only piece of data which is always returned is the :py:attr:`ip_address` The only piece of data which is always returned is the ```ipAddress```
attribute in the :py:class:`geoip2.records.Traits` record. attribute in the ``GeoIP2\Record\Traits`` record.
Every record class attribute has a corresponding predicate method so you can Every record class attribute has a corresponding predicate method so you can
check to see if the attribute is set. 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
databases with data on geographical features around the world, including databases with data on geographical features around the world, including
populated places. They offer both free and paid premium data. Each populated places. They offer both free and paid premium data. Each
feature is unique identified by a ```geonameId```, which is an integer. feature is unique identified by a ```geonameId```, which is an integer.
@ -117,7 +163,7 @@ details.
This code requires PHP 5.3 or greater. Older versions of PHP are not This code requires PHP 5.3 or greater. Older versions of PHP are not
supported. supported.
This library also relies on the Guzze HTTP client, http://guzzlephp.org/ This library also relies on the [Guzze HTTP client](http://guzzlephp.org/).
## Contributing ## ## Contributing ##
@ -126,7 +172,7 @@ PSR-2 style guidelines. Please include unit tests whenever possible.
## Author ## ## Author ##
Gregory Oschwald <goschwald@maxmind.com> [Gregory Oschwald](mailto:goschwald@maxmind.com)
## Copyright and License ## ## Copyright and License ##