Client
in package
implements
ProviderInterface
This class provides a client API for all the GeoIP2 web services.
The services are Country, City Plus, and Insights. Each service returns a different set of data about an IP address, with Country returning the least data and Insights the most.
Each web service 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 $accountId
and $licenseKey
, 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 service 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.
Table of Contents
Interfaces
Constants
- VERSION = 'v3.1.0'
Methods
- __construct() : mixed
- Constructor.
- city() : City
- This method calls the City Plus service.
- country() : Country
- This method calls the Country service.
- insights() : Insights
- This method calls the Insights service. Insights is only supported by the GeoIP2 web service. The GeoLite2 web service does not support it.
Constants
VERSION
public
mixed
VERSION
= 'v3.1.0'
Methods
__construct()
Constructor.
public
__construct(int $accountId, string $licenseKey[, array<int, string> $locales = ['en'] ][, array<string, mixed> $options = [] ]) : mixed
Parameters
- $accountId : int
-
your MaxMind account ID
- $licenseKey : string
-
your MaxMind license key
- $locales : array<int, string> = ['en']
-
list of locale codes to use in name property from most preferred to least preferred
- $options : array<string, mixed> = []
-
array of options. Valid options include:
-
host
- The host to use when querying the web service. To query the GeoLite2 web service instead of the GeoIP2 web service, set the host togeolite.info
. To query the Sandbox GeoIP2 web service instead of the production GeoIP2 web service, set the host tosandbox.maxmind.com
. The sandbox allows you to experiment with the API without affecting your production data. -
timeout
- Timeout in seconds. -
connectTimeout
- Initial connection timeout in seconds. -
proxy
- The HTTP proxy to use. May include a schema, port, username, and password, e.g.,http://username:password@127.0.0.1:10
.
-
city()
This method calls the City Plus service.
public
city([string $ipAddress = 'me' ]) : City
Parameters
- $ipAddress : string = 'me'
-
IPv4 or IPv6 address as a string. If no address is provided, the address that the web service is called from will be used.
Tags
Return values
City —a City model for the requested IP address
country()
This method calls the Country service.
public
country([string $ipAddress = 'me' ]) : Country
Parameters
- $ipAddress : string = 'me'
-
IPv4 or IPv6 address as a string. If no address is provided, the address that the web service is called from will be used.
Tags
Return values
Country —a Country model for the requested IP address
insights()
This method calls the Insights service. Insights is only supported by the GeoIP2 web service. The GeoLite2 web service does not support it.
public
insights([string $ipAddress = 'me' ]) : Insights
Parameters
- $ipAddress : string = 'me'
-
IPv4 or IPv6 address as a string. If no address is provided, the address that the web service is called from will be used.