This class provides a client API for all the GeoIP2 Precision web service
end points. The end points are Country, City, and Insights. Each end point
returns a different set of data about an IP address, with Country returning
the least data and Insights 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 $userId
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 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.
Methods summary
public
|
#
__construct( integer $userId, string $licenseKey, array $locales = array('en'), string $host = 'geoip.maxmind.com', object $guzzleClient = null )
Constructor.
Parameters
- $userId
- Your MaxMind user ID
- $licenseKey
- Your MaxMind license key
- $locales
- <p>List of locale codes to use in name property
from most preferred to least preferred.</p>
- $host
- Optional host parameter
- $guzzleClient
- <p>Optional Guzzle client to use (to facilitate
unit testing).</p>
|
public
GeoIp2\Model\City
|
#
city( string $ipAddress = 'me' )
This method calls the GeoIP2 Precision: City endpoint.
This method calls the GeoIP2 Precision: City endpoint.
Parameters
- $ipAddress
- <p>IPv4 or IPv6 address as a string. If no
address is provided, the address that the web service is called
from will be used.</p>
Returns
Throws
GeoIp2\Exception\AddressNotFoundException if the address you
provided is not in our database (e.g., a private address).
GeoIp2\Exception\AuthenticationException if there is a problem
with the user ID or license key that you provided.
GeoIp2\Exception\OutOfQueriesException if your account is out
of queries.
GeoIp2\Exception\InvalidRequestException} if your request was
received by the web service but is invalid for some other reason.
This may indicate an issue with this API. Please report the error to
MaxMind.
GeoIp2\Exception\HttpException if an unexpected HTTP error
code or message was returned. This could indicate a problem with the
connection between your server and the web service or that the web
service returned an invalid document or 500 error code.
GeoIp2\Exception\GeoIp2Exception This serves as the parent
class to the above exceptions. It will be thrown directly if a 200
status code is returned but the body is invalid.
Implementation of
|
public
GeoIp2\Model\Country
|
#
country( string $ipAddress = 'me' )
This method calls the GeoIP2 Precision: Country endpoint.
This method calls the GeoIP2 Precision: Country endpoint.
Parameters
- $ipAddress
- <p>IPv4 or IPv6 address as a string. If no
address is provided, the address that the web service is called
from will be used.</p>
Returns
Throws
GeoIp2\Exception\AddressNotFoundException if the address you
provided is not in our database (e.g., a private address).
GeoIp2\Exception\AuthenticationException if there is a problem
with the user ID or license key that you provided.
GeoIp2\Exception\OutOfQueriesException if your account is out
of queries.
GeoIp2\Exception\InvalidRequestException} if your request was
received by the web service but is invalid for some other reason.
This may indicate an issue with this API. Please report the error to
MaxMind.
GeoIp2\Exception\HttpException if an unexpected HTTP error
code or message was returned. This could indicate a problem with the
connection between your server and the web service or that the web
service returned an invalid document or 500 error code.
GeoIp2\Exception\GeoIp2Exception This serves as the parent
class to the above exceptions. It will be thrown directly if a 200
status code is returned but the body is invalid.
Implementation of
|
public
GeoIp2\Model\Insights
|
#
insights( string $ipAddress = 'me' )
This method calls the GeoIP2 Precision: Insights endpoint.
This method calls the GeoIP2 Precision: Insights endpoint.
Parameters
- $ipAddress
- <p>IPv4 or IPv6 address as a string. If no
address is provided, the address that the web service is called
from will be used.</p>
Returns
Throws
GeoIp2\Exception\AddressNotFoundException if the address you
provided is not in our database (e.g., a private address).
GeoIp2\Exception\AuthenticationException if there is a problem
with the user ID or license key that you provided.
GeoIp2\Exception\OutOfQueriesException if your account is out
of queries.
GeoIp2\Exception\InvalidRequestException} if your request was
received by the web service but is invalid for some other reason.
This may indicate an issue with this API. Please report the error to
MaxMind.
GeoIp2\Exception\HttpException if an unexpected HTTP error
code or message was returned. This could indicate a problem with the
connection between your server and the web service or that the web
service returned an invalid document or 500 error code.
GeoIp2\Exception\GeoIp2Exception This serves as the parent
class to the above exceptions. It will be thrown directly if a 200
status code is returned but the body is invalid.
|