Overview

Namespaces

  • GeoIP2
    • Exception
    • Model
    • Record
    • WebService
  • PHP

Classes

  • Client
  • Overview
  • Namespace
  • Class
  • Tree
  • Download

Class Client

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 point returns a different set of data about an IP address, with Country returning the least data and Omni the most.

Each web service end point is represented by a different model class, and these model classes in turn contain multiple Record classes. The record classes have attributes which contain data about the IP address.

If the web service does not return a particular piece of data for an IP address, the associated attribute is not populated.

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.

Usage

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 <span class="php-var">$userId</span> and <span class="php-var">$licenseKey</span>, then you call the method 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 the end point you called. This model in turn contains multiple record classes, each of which represents part of the data returned by the web service.

If the request fails, the client class throws an exception.

Exceptions

For details on the possible errors returned by the web service itself, see the GeoIP2 web service docs.

If the web service returns an explicit error document, this is thrown as a GeoIP2\Exception\WebServiceException. If some other sort of transport error occurs, this is thrown as a GeoIP2\Exception\HttpException. The difference is that the web service error includes an error message and error code delivered by the web service. The latter is thrown when some sort of unanticipated error occurs, such as the web service returning a 500 or an invalid error document.

If the web service returns any status code besides 200, 4xx, or 5xx, this also becomes a GeoIP2\Exception\HttpException.

Finally, if the web service returns a 200 but the body is invalid, the client throws a GeoIP2\Exception\GeoIP2Exception.

Namespace: GeoIP2\WebService
Located at GeoIP2/WebService/Client.php
Methods summary
public
# __construct( integer $userId, string $licenseKey, array $languages = array('en'), string $host = 'geoip.maxmind.com', object $guzzleClient = null )

Constructor.

Constructor.

Parameters

$userId
integer
$userId Your MaxMind user ID
$licenseKey
string
$licenseKey Your MaxMind license key
$languages
array
$languages List of language codes to use in name property from most preferred to least preferred.
$host
string
$host Optional host parameter
$guzzleClient
object
$guzzleClient Optional Guzzle client to use (to facilitate unit testing).
public GeoIP2\Model\City
# city( string $ipAddress = 'me' )

This method calls the GeoIP2 City endpoint.

This method calls the GeoIP2 City endpoint.

Parameters

$ipAddress
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.

Returns

GeoIP2\Model\City

Throws

GeoIP2\Exception\GeoIP2Exception
if there was a generic error processing your request.
GeoIP2\Exception\HttpException
if there was an HTTP transport error.
GeoIP2\Exception\WebServiceException
if an error was returned by MaxMind's GeoIP2 web service.
public GeoIP2\Model\Country
# country( string $ipAddress = 'me' )

This method calls the GeoIP2 Country endpoint.

This method calls the GeoIP2 Country endpoint.

Parameters

$ipAddress
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.

Returns

GeoIP2\Model\Country

Throws

GeoIP2\Exception\GeoIP2Exception
if there was a generic error processing your request.
GeoIP2\Exception\HttpException
if there was an HTTP transport error.
GeoIP2\Exception\WebServiceException
if an error was returned by MaxMind's GeoIP2 web service.
public GeoIP2\Model\CityIspOrg
# cityIspOrg( string $ipAddress = 'me' )

This method calls the GeoIP2 City/ISP/Org endpoint.

This method calls the GeoIP2 City/ISP/Org endpoint.

Parameters

$ipAddress
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.

Returns

GeoIP2\Model\CityIspOrg

Throws

GeoIP2\Exception\GeoIP2Exception
if there was a generic error processing your request.
GeoIP2\Exception\HttpException
if there was an HTTP transport error.
GeoIP2\Exception\WebServiceException
if an error was returned by MaxMind's GeoIP2 web service.
public GeoIP2\Model\Omni
# omni( string $ipAddress = 'me' )

This method calls the GeoIP2 Omni endpoint.

This method calls the GeoIP2 Omni endpoint.

Parameters

$ipAddress
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.

Returns

GeoIP2\Model\Omni

Throws

GeoIP2\Exception\GeoIP2Exception
if there was a generic error processing your request.
GeoIP2\Exception\HttpException
if there was an HTTP transport error.
GeoIP2\Exception\WebServiceException
if an error was returned by MaxMind's GeoIP2 web service.
GeoIP2 PHP API v0.1.1 API documentation generated by ApiGen 2.8.0