You have probably clicked on a link that is outdated and points to a page that does not exist any more or you have made an typing error in the address.
+
To continue please try to find requested page in the menu, take a look at the tree view of the whole project or use search field on the top.
Instances of this class provide a reader for the GeoIP2 database format. IP
+addresses can be looked up using the country and city
+methods. We also provide cityIspOrg and omni methods
+to ease compatibility with the web service client, although we may offer the
+ability to specify additional databases to replicate these web services in the
+future (e.g., the ISP/Org database).
+
+
Usage
+
+
The basic API for this class is the same for every database. First, you
+create a reader object, specifying a file name. You then call the method
+corresponding to the specific database, passing it the IP address you want to
+look up.
+
+
If the request succeeds, the method call will return a model class for the
+method you called. This model in turn contains multiple record classes, each of
+which represents part of the data returned by the database. If the database does
+not contain the requested information, the attributes on the record class will
+have a null value.
+
+
If the address is not in the database, an GeoIp2\Exception\AddressNotFoundException exception will be thrown. If an
+invalid IP address is passed to one of the methods, a SPL InvalidArgumentException will be thrown. If the database is corrupt or
+invalid, a \MaxMind\Db\Reader\InvalidDatabaseException will be
+thrown.
+ GeoIp2\Exception\AddressNotFoundException if the address is not in the database.
+ MaxMind\Db\Reader\InvalidDatabaseException if the database is corrupt or invalid
+
+ GeoIp2\Exception\AddressNotFoundException if the address is not in the database.
+ MaxMind\Db\Reader\InvalidDatabaseException if the database is corrupt or invalid
+
Registered country data for the requested IP address. This record represents
+the country where the ISP has registered a given IP block and may differ from
+the user's country.
+
+
+
+
+
+
Registered country data for the requested IP address. This record represents
+the country where the ISP has registered a given IP block and may differ from
+the user's country.
Represented country data for the requested IP address. The represented
+country is used for things like military bases. It is only present when the
+represented country differs from the country.
+
+
+
+
+
+
Represented country data for the requested IP address. The represented
+country is used for things like military bases. It is only present when the
+represented country differs from the country.
An array of GeoIp2\Record\Subdivision objects representing the
+country subdivisions for the requested IP address. The number and type of
+subdivisions varies by country, but a subdivision is typically a state,
+province, county, etc. Subdivisions are ordered from most general (largest) to
+most specific (smallest). If the response did not contain any subdivisions, this
+method returns an empty array.
+
+
+
+
+
+
An array of GeoIp2\Record\Subdivision objects representing the
+country subdivisions for the requested IP address. The number and type of
+subdivisions varies by country, but a subdivision is typically a state,
+province, county, etc. Subdivisions are ordered from most general (largest) to
+most specific (smallest). If the response did not contain any subdivisions, this
+method returns an empty array.
An object representing the most specific subdivision returned. If the
+response did not contain any subdivisions, this method returns an empty GeoIp2\Record\Subdivision object.
+
+
+
+
+
+
An object representing the most specific subdivision returned. If the
+response did not contain any subdivisions, this method returns an empty GeoIp2\Record\Subdivision object.
Registered country data for the requested IP address. This record represents
+the country where the ISP has registered a given IP block and may differ from
+the user's country.
+
+
+
+
+
+
Registered country data for the requested IP address. This record represents
+the country where the ISP has registered a given IP block and may differ from
+the user's country.
Represented country data for the requested IP address. The represented
+country is used for things like military bases. It is only present when the
+represented country differs from the country.
+
+
+
+
+
+
Represented country data for the requested IP address. The represented
+country is used for things like military bases. It is only present when the
+represented country differs from the country.
Registered country data for the requested IP address. This record represents
+the country where the ISP has registered a given IP block and may differ from
+the user's country.
+
+
+
+
+
+
Registered country data for the requested IP address. This record represents
+the country where the ISP has registered a given IP block and may differ from
+the user's country.
Represented country data for the requested IP address. The represented
+country is used for things like military bases. It is only present when the
+represented country differs from the country.
+
+
+
+
+
+
Represented country data for the requested IP address. The represented
+country is used for things like military bases. It is only present when the
+represented country differs from the country.
An array of GeoIp2\Record\Subdivision objects representing the
+country subdivisions for the requested IP address. The number and type of
+subdivisions varies by country, but a subdivision is typically a state,
+province, county, etc. Subdivisions are ordered from most general (largest) to
+most specific (smallest). If the response did not contain any subdivisions, this
+method returns an empty array.
+
+
+
+
+
+
An array of GeoIp2\Record\Subdivision objects representing the
+country subdivisions for the requested IP address. The number and type of
+subdivisions varies by country, but a subdivision is typically a state,
+province, county, etc. Subdivisions are ordered from most general (largest) to
+most specific (smallest). If the response did not contain any subdivisions, this
+method returns an empty array.
An object representing the most specific subdivision returned. If the
+response did not contain any subdivisions, this method returns an empty GeoIp2\Record\Subdivision object.
+
+
+
+
+
+
An object representing the most specific subdivision returned. If the
+response did not contain any subdivisions, this method returns an empty GeoIp2\Record\Subdivision object.
The radius in kilometers around the specified location where the IP address
+is likely to be. This attribute is only available from the Insights end
+point.
+
+
+
+
+
+
The radius in kilometers around the specified location where the IP address
+is likely to be. This attribute is only available from the Insights end
+point.
The metro code of the location if the location is in the US. MaxMind returns
+the same metro codes as the Google AdWords API. This attribute is returned by all end points except the
+Country end point.
+
+
+
+
+
+
The metro code of the location if the location is in the US. MaxMind returns
+the same metro codes as the Google AdWords API. This attribute is returned by all end points except the
+Country end point.
The time zone associated with location, as specified by the IANA
+Time Zone Database, e.g., "America/New_York". This attribute is returned by all
+end points except the Country end point.
+
+
+
+
+
+
The time zone associated with location, as specified by the IANA
+Time Zone Database, e.g., "America/New_York". This attribute is returned by all
+end points except the Country end point.
The postal code of the location. Postal codes are not available for all
+countries. In some countries, this will only contain part of the postal code.
+This attribute is returned by all end points except the Country end point.
+
+
+
+
+
+
The postal code of the location. Postal codes are not available for all
+countries. In some countries, this will only contain part of the postal code.
+This attribute is returned by all end points except the Country end point.
Contains data for the represented country associated with an IP address
+
+
This class contains the country-level data associated with an IP address for
+the IP's represented country. The represented country is the country represented
+by something like a military base.
A string indicating the type of entity that is representing the country.
+Currently we only return military but this could expand to include
+other types in the future.
+
+
+
+
+
+
A string indicating the type of entity that is representing the country.
+Currently we only return military but this could expand to include
+other types in the future.
This is a value from 0-100 indicating MaxMind's confidence that the
+subdivision is correct. This attribute is only available from the Insights end
+point.
+
+
+
+
+
+
This is a value from 0-100 indicating MaxMind's confidence that the
+subdivision is correct. This attribute is only available from the Insights end
+point.
This is a string up to three characters long contain the subdivision portion
+of the ISO 3166-2 code. This attribute is returned by all end points except
+Country.
+
+
+
+
+
+
This is a string up to three characters long contain the subdivision portion
+of the ISO 3166-2 code. This attribute is returned by all end points except
+Country.
The organization associated with the registered autonomous system number for the IP address. This attribute is only available
+from the City and Insights web service end points.
+
+
+
+
+
+
The organization associated with the registered autonomous system number for the IP address. This attribute is only available
+from the City and Insights web service end points.
The second level domain associated with the IP address. This will be
+something like "example.com" or "example.co.uk", not "foo.example.com". This
+attribute is only available from the City and Insights web service end
+points.
+
+
+
+
+
+
The second level domain associated with the IP address. This will be
+something like "example.com" or "example.co.uk", not "foo.example.com". This
+attribute is only available from the City and Insights web service end
+points.
The IP address that the data in the model is for. If you performed a "me"
+lookup against the web service, this will be the externally routable IP address
+for the system the code is running on. If the system is behind a NAT, this may
+differ from the IP address locally assigned to it. This attribute is returned by
+all end points.
+
+
+
+
+
+
The IP address that the data in the model is for. If you performed a "me"
+lookup against the web service, this will be the externally routable IP address
+for the system the code is running on. If the system is behind a NAT, this may
+differ from the IP address locally assigned to it. This attribute is returned by
+all end points.
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.
+ 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.
+
+ 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.
+
+ 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.
+
Instances of this class provide a reader for the GeoIP2 database format. IP
+addresses can be looked up using the country and city
+methods. We also provide cityIspOrg and omni methods
+to ease compatibility with the web service client, although we may offer the
+ability to specify additional databases to replicate these web services in the
+future (e.g., the ISP/Org database).
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.
a",n=d.getElementsByTagName("*")||[],r=d.getElementsByTagName("a")[0],!r||!r.style||!n.length)return t;s=a.createElement("select"),u=s.appendChild(a.createElement("option")),o=d.getElementsByTagName("input")[0],r.style.cssText="top:1px;float:left;opacity:.5",t.getSetAttribute="t"!==d.className,t.leadingWhitespace=3===d.firstChild.nodeType,t.tbody=!d.getElementsByTagName("tbody").length,t.htmlSerialize=!!d.getElementsByTagName("link").length,t.style=/top/.test(r.getAttribute("style")),t.hrefNormalized="/a"===r.getAttribute("href"),t.opacity=/^0.5/.test(r.style.opacity),t.cssFloat=!!r.style.cssFloat,t.checkOn=!!o.value,t.optSelected=u.selected,t.enctype=!!a.createElement("form").enctype,t.html5Clone="<:nav>"!==a.createElement("nav").cloneNode(!0).outerHTML,t.inlineBlockNeedsLayout=!1,t.shrinkWrapBlocks=!1,t.pixelPosition=!1,t.deleteExpando=!0,t.noCloneEvent=!0,t.reliableMarginRight=!0,t.boxSizingReliable=!0,o.checked=!0,t.noCloneChecked=o.cloneNode(!0).checked,s.disabled=!0,t.optDisabled=!u.disabled;try{delete d.test}catch(h){t.deleteExpando=!1}o=a.createElement("input"),o.setAttribute("value",""),t.input=""===o.getAttribute("value"),o.value="t",o.setAttribute("type","radio"),t.radioValue="t"===o.value,o.setAttribute("checked","t"),o.setAttribute("name","t"),l=a.createDocumentFragment(),l.appendChild(o),t.appendChecked=o.checked,t.checkClone=l.cloneNode(!0).cloneNode(!0).lastChild.checked,d.attachEvent&&(d.attachEvent("onclick",function(){t.noCloneEvent=!1}),d.cloneNode(!0).click());for(f in{submit:!0,change:!0,focusin:!0})d.setAttribute(c="on"+f,"t"),t[f+"Bubbles"]=c in e||d.attributes[c].expando===!1;d.style.backgroundClip="content-box",d.cloneNode(!0).style.backgroundClip="",t.clearCloneStyle="content-box"===d.style.backgroundClip;for(f in x(t))break;return t.ownLast="0"!==f,x(function(){var n,r,o,s="padding:0;margin:0;border:0;display:block;box-sizing:content-box;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;",l=a.getElementsByTagName("body")[0];l&&(n=a.createElement("div"),n.style.cssText="border:0;width:0;height:0;position:absolute;top:0;left:-9999px;margin-top:1px",l.appendChild(n).appendChild(d),d.innerHTML="
1: <?php
+ 2:
+ 3: namespace GeoIp2\Database;
+ 4:
+ 5: use GeoIp2\Exception\AddressNotFoundException;
+ 6: use GeoIp2\ProviderInterface;
+ 7: use MaxMind\Db\Reader as DbReader;
+ 8:
+ 9: /**
+ 10: * Instances of this class provide a reader for the GeoIP2 database format.
+ 11: * IP addresses can be looked up using the <code>country</code>
+ 12: * and <code>city</code> methods. We also provide <code>cityIspOrg</code>
+ 13: * and <code>omni</code> methods to ease compatibility with the web service
+ 14: * client, although we may offer the ability to specify additional databases
+ 15: * to replicate these web services in the future (e.g., the ISP/Org database).
+ 16: *
+ 17: * **Usage**
+ 18: *
+ 19: * The basic API for this class is the same for every database. First, you
+ 20: * create a reader object, specifying a file name. You then call the method
+ 21: * corresponding to the specific database, passing it the IP address you want
+ 22: * to look up.
+ 23: *
+ 24: * If the request succeeds, the method call will return a model class for
+ 25: * the method you called. This model in turn contains multiple record classes,
+ 26: * each of which represents part of the data returned by the database. If
+ 27: * the database does not contain the requested information, the attributes
+ 28: * on the record class will have a <code>null</code> value.
+ 29: *
+ 30: * If the address is not in the database, an
+ 31: * {@link \GeoIp2\Exception\AddressNotFoundException} exception will be
+ 32: * thrown. If an invalid IP address is passed to one of the methods, a
+ 33: * SPL {@link \InvalidArgumentException} will be thrown. If the database is
+ 34: * corrupt or invalid, a {@link \MaxMind\Db\Reader\InvalidDatabaseException}
+ 35: * will be thrown.
+ 36: *
+ 37: */
+ 38: classReaderimplements ProviderInterface
+ 39: {
+ 40: private$dbReader;
+ 41: private$locales;
+ 42:
+ 43: /**
+ 44: * Constructor.
+ 45: *
+ 46: * @param string $filename The path to the GeoIP2 database file.
+ 47: * @param array $locales List of locale codes to use in name property
+ 48: * from most preferred to least preferred.
+ 49: * @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
+ 50: * is corrupt or invalid
+ 51: */
+ 52: publicfunction__construct(
+ 53: $filename,
+ 54: $locales = array('en')
+ 55: ) {
+ 56: $this->dbReader = new DbReader($filename);
+ 57: $this->locales = $locales;
+ 58: }
+ 59:
+ 60: /**
+ 61: * This method returns a GeoIP2 City model.
+ 62: *
+ 63: * @param string $ipAddress IPv4 or IPv6 address as a string.
+ 64: *
+ 65: * @return \GeoIp2\Model\City
+ 66: *
+ 67: * @throws \GeoIp2\Exception\AddressNotFoundException if the address is
+ 68: * not in the database.
+ 69: * @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
+ 70: * is corrupt or invalid
+ 71: */
+ 72: publicfunctioncity($ipAddress)
+ 73: {
+ 74: return$this->modelFor('City', 'City', $ipAddress);
+ 75: }
+ 76:
+ 77: /**
+ 78: * This method returns a GeoIP2 Country model.
+ 79: *
+ 80: * @param string $ipAddress IPv4 or IPv6 address as a string.
+ 81: *
+ 82: * @return \GeoIp2\Model\Country
+ 83: *
+ 84: * @throws \GeoIp2\Exception\AddressNotFoundException if the address is
+ 85: * not in the database.
+ 86: * @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
+ 87: * is corrupt or invalid
+ 88: */
+ 89: publicfunctioncountry($ipAddress)
+ 90: {
+ 91: return$this->modelFor('Country', 'Country', $ipAddress);
+ 92: }
+ 93:
+ 94: publicfunctionconnectionType($ipAddress)
+ 95: {
+ 96: return$this->flatModelFor(
+ 97: 'ConnectionType',
+ 98: 'GeoIP2-Connection-Type',
+ 99: $ipAddress
+100: );
+101: }
+102:
+103: publicfunctiondomain($ipAddress)
+104: {
+105: return$this->flatModelFor(
+106: 'Domain',
+107: 'GeoIP2-Domain',
+108: $ipAddress
+109: );
+110: }
+111:
+112: publicfunctionisp($ipAddress)
+113: {
+114: return$this->flatModelFor(
+115: 'Isp',
+116: 'GeoIP2-ISP',
+117: $ipAddress
+118: );
+119: }
+120:
+121: privatefunctionmodelFor($class, $type, $ipAddress)
+122: {
+123: $record = $this->getRecord($class, $type, $ipAddress);
+124:
+125: $record['traits']['ip_address'] = $ipAddress;
+126: $class = "GeoIp2\\Model\\" . $class;
+127:
+128: returnnew$class($record, $this->locales);
+129: }
+130:
+131: privatefunctionflatModelFor($class, $type, $ipAddress)
+132: {
+133: $record = $this->getRecord($class, $type, $ipAddress);
+134:
+135: $record['ip_address'] = $ipAddress;
+136: $class = "GeoIp2\\Model\\" . $class;
+137:
+138: returnnew$class($record);
+139: }
+140:
+141: privatefunctiongetRecord($class, $type, $ipAddress)
+142: {
+143: if (strpos($this->metadata()->databaseType, $type) === false) {
+144: $method = lcfirst($class);
+145: thrownew \BadMethodCallException(
+146: "The $method method cannot be used to open a "
+147: . $this->metadata()->databaseType . " database"
+148: );
+149: }
+150: $record = $this->dbReader->get($ipAddress);
+151: if ($record === null) {
+152: thrownew AddressNotFoundException(
+153: "The address $ipAddress is not in the database."
+154: );
+155: }
+156: return$record;
+157: }
+158:
+159: /**
+160: * @throws \InvalidArgumentException if arguments are passed to the method.
+161: * @throws \BadMethodCallException if the database has been closed.
+162: * @return \MaxMind\Db\Reader\Metadata object for the database.
+163: */
+164: publicfunctionmetadata()
+165: {
+166: return$this->dbReader->metadata();
+167: }
+168:
+169: /**
+170: * Closes the GeoIP2 database and returns the resources to the system.
+171: */
+172: publicfunctionclose()
+173: {
+174: $this->dbReader->close();
+175: }
+176: }
+177:
1: <?php
+ 2:
+ 3: namespace GeoIp2\Model;
+ 4:
+ 5: /**
+ 6: * Model class for the data returned by GeoIP2 City web service and database.
+ 7: *
+ 8: * The only difference between the City and Insights model classes is which
+ 9: * fields in each record may be populated. See
+ 10: * http://dev.maxmind.com/geoip/geoip2/web-services more details.
+ 11: *
+ 12: * @property \GeoIp2\Record\City $city City data for the requested IP
+ 13: * address.
+ 14: *
+ 15: * @property \GeoIp2\Record\Continent $continent Continent data for the
+ 16: * requested IP address.
+ 17: *
+ 18: * @property \GeoIp2\Record\Country $country Country data for the requested
+ 19: * IP address. This object represents the country where MaxMind believes the
+ 20: * end user is located.
+ 21: *
+ 22: * @property \GeoIp2\Record\Location $location Location data for the
+ 23: * requested IP address.
+ 24: *
+ 25: * @property \GeoIp2\Record\MaxMind $maxmind Data related to your MaxMind
+ 26: * account.
+ 27: *
+ 28: * @property \GeoIp2\Record\Country $registeredCountry Registered country
+ 29: * data for the requested IP address. This record represents the country
+ 30: * where the ISP has registered a given IP block and may differ from the
+ 31: * user's country.
+ 32: *
+ 33: * @property \GeoIp2\Record\RepresentedCountry $representedCountry
+ 34: * Represented country data for the requested IP address. The represented
+ 35: * country is used for things like military bases. It is only present when
+ 36: * the represented country differs from the country.
+ 37: *
+ 38: * @property array $subdivisions An array of {@link \GeoIp2\Record\Subdivision}
+ 39: * objects representing the country subdivisions for the requested IP
+ 40: * address. The number and type of subdivisions varies by country, but a
+ 41: * subdivision is typically a state, province, county, etc. Subdivisions
+ 42: * are ordered from most general (largest) to most specific (smallest).
+ 43: * If the response did not contain any subdivisions, this method returns
+ 44: * an empty array.
+ 45: *
+ 46: * @property \GeoIp2\Record\Subdivision $mostSpecificSubdivision An object
+ 47: * representing the most specific subdivision returned. If the response
+ 48: * did not contain any subdivisions, this method returns an empty
+ 49: * {@link \GeoIp2\Record\Subdivision} object.
+ 50: *
+ 51: * @property \GeoIp2\Record\Traits $traits Data for the traits of the
+ 52: * requested IP address.
+ 53: */
+ 54: classCityextends Country
+ 55: {
+ 56: /**
+ 57: * @ignore
+ 58: */
+ 59: protected$city;
+ 60: /**
+ 61: * @ignore
+ 62: */
+ 63: protected$location;
+ 64: /**
+ 65: * @ignore
+ 66: */
+ 67: protected$postal;
+ 68: /**
+ 69: * @ignore
+ 70: */
+ 71: protected$subdivisions = array();
+ 72:
+ 73: /**
+ 74: * @ignore
+ 75: */
+ 76: publicfunction__construct($raw, $locales = array('en'))
+ 77: {
+ 78: parent::__construct($raw, $locales);
+ 79:
+ 80: $this->city = new \GeoIp2\Record\City($this->get('city'), $locales);
+ 81: $this->location = new \GeoIp2\Record\Location($this->get('location'));
+ 82: $this->postal = new \GeoIp2\Record\Postal($this->get('postal'));
+ 83:
+ 84: $this->createSubdivisions($raw, $locales);
+ 85: }
+ 86:
+ 87: privatefunctioncreateSubdivisions($raw, $locales)
+ 88: {
+ 89: if (!isset($raw['subdivisions'])) {
+ 90: return;
+ 91: }
+ 92:
+ 93: foreach ($raw['subdivisions'] as$sub) {
+ 94: array_push(
+ 95: $this->subdivisions,
+ 96: new \GeoIp2\Record\Subdivision($sub, $locales)
+ 97: );
+ 98: }
+ 99: }
+100:
+101: /**
+102: * @ignore
+103: */
+104: publicfunction__get($attr)
+105: {
+106: if ($attr == 'mostSpecificSubdivision') {
+107: return$this->$attr();
+108: } else {
+109: return parent::__get($attr);
+110: }
+111: }
+112:
+113: privatefunctionmostSpecificSubdivision()
+114: {
+115: returnempty($this->subdivisions) ?
+116: new \GeoIp2\Record\Subdivision(array(), $this->locales) :
+117: end($this->subdivisions);
+118: }
+119: }
+120:
1: <?php
+ 2:
+ 3: namespace GeoIp2\Model;
+ 4:
+ 5: /**
+ 6: * Model class for the data returned by GeoIP2 Country web service and database.
+ 7: *
+ 8: * The only difference between the City and Insights model classes is which
+ 9: * fields in each record may be populated. See
+10: * http://dev.maxmind.com/geoip/geoip2/web-services more details.
+11: *
+12: * @property \GeoIp2\Record\Continent $continent Continent data for the
+13: * requested IP address.
+14: *
+15: * @property \GeoIp2\Record\Country $country Country data for the requested
+16: * IP address. This object represents the country where MaxMind believes the
+17: * end user is located.
+18: *
+19: * @property \GeoIp2\Record\MaxMind $maxmind Data related to your MaxMind
+20: * account.
+21: *
+22: * @property \GeoIp2\Record\Country $registeredCountry Registered country
+23: * data for the requested IP address. This record represents the country
+24: * where the ISP has registered a given IP block and may differ from the
+25: * user's country.
+26: *
+27: * @property \GeoIp2\Record\RepresentedCountry $representedCountry
+28: * Represented country data for the requested IP address. The represented
+29: * country is used for things like military bases. It is only present when
+30: * the represented country differs from the country.
+31: *
+32: * @property \GeoIp2\Record\Traits $traits Data for the traits of the
+33: * requested IP address.
+34: */
+35: classCountryextends AbstractModel
+36: {
+37: protected$continent;
+38: protected$country;
+39: protected$locales;
+40: protected$maxmind;
+41: protected$registeredCountry;
+42: protected$representedCountry;
+43: protected$traits;
+44:
+45: /**
+46: * @ignore
+47: */
+48: publicfunction__construct($raw, $locales = array('en'))
+49: {
+50: parent::__construct($raw);
+51:
+52: $this->continent = new \GeoIp2\Record\Continent(
+53: $this->get('continent'),
+54: $locales
+55: );
+56: $this->country = new \GeoIp2\Record\Country(
+57: $this->get('country'),
+58: $locales
+59: );
+60: $this->maxmind = new \GeoIp2\Record\MaxMind($this->get('maxmind'));
+61: $this->registeredCountry = new \GeoIp2\Record\Country(
+62: $this->get('registered_country'),
+63: $locales
+64: );
+65: $this->representedCountry = new \GeoIp2\Record\RepresentedCountry(
+66: $this->get('represented_country'),
+67: $locales
+68: );
+69: $this->traits = new \GeoIp2\Record\Traits($this->get('traits'));
+70:
+71: $this->locales = $locales;
+72: }
+73: }
+74:
1: <?php
+ 2:
+ 3: namespace GeoIp2\Model;
+ 4:
+ 5: /**
+ 6: * Model class for the data returned by GeoIP2 Precision: Insights web service.
+ 7: *
+ 8: * The only difference between the City and Insights model classes is which
+ 9: * fields in each record may be populated. See
+10: * http://dev.maxmind.com/geoip/geoip2/web-services more details.
+11: *
+12: * @property \GeoIp2\Record\City $city City data for the requested IP
+13: * address.
+14: *
+15: * @property \GeoIp2\Record\Continent $continent Continent data for the
+16: * requested IP address.
+17: *
+18: * @property \GeoIp2\Record\Country $country Country data for the requested
+19: * IP address. This object represents the country where MaxMind believes the
+20: * end user is located.
+21: *
+22: * @property \GeoIp2\Record\Location $location Location data for the
+23: * requested IP address.
+24: *
+25: * @property \GeoIp2\Record\MaxMind $maxmind Data related to your MaxMind
+26: * account.
+27: *
+28: * @property \GeoIp2\Record\Country $registeredCountry Registered country
+29: * data for the requested IP address. This record represents the country
+30: * where the ISP has registered a given IP block and may differ from the
+31: * user's country.
+32: *
+33: * @property \GeoIp2\Record\RepresentedCountry $representedCountry
+34: * Represented country data for the requested IP address. The represented
+35: * country is used for things like military bases. It is only present when
+36: * the represented country differs from the country.
+37: *
+38: * @property array $subdivisions An array of {@link \GeoIp2\Record\Subdivision}
+39: * objects representing the country subdivisions for the requested IP
+40: * address. The number and type of subdivisions varies by country, but a
+41: * subdivision is typically a state, province, county, etc. Subdivisions
+42: * are ordered from most general (largest) to most specific (smallest).
+43: * If the response did not contain any subdivisions, this method returns
+44: * an empty array.
+45: *
+46: * @property \GeoIp2\Record\Subdivision $mostSpecificSubdivision An object
+47: * representing the most specific subdivision returned. If the response
+48: * did not contain any subdivisions, this method returns an empty
+49: * {@link \GeoIp2\Record\Subdivision} object.
+50: *
+51: * @property \GeoIp2\Record\Traits $traits Data for the traits of the
+52: * requested IP address.
+53: */
+54: classInsightsextends City
+55: {
+56: }
+57:
1: <?php
+ 2:
+ 3: namespace GeoIp2\Model;
+ 4:
+ 5: /**
+ 6: * This class provides the GeoIP2 Connection-Type model.
+ 7: *
+ 8: * @property integer $autonomousSystemNumber The autonomous system number
+ 9: * associated with the IP address.
+10: *
+11: * @property string $autonomousSystemOrganization The organization associated
+12: * with the registered autonomous system number for the IP address.
+13: *
+14: * @property string $isp The name of the ISP associated with the IP address.
+15: *
+16: * @property string $organization The name of the organization associated with
+17: * the IP address.
+18: *
+19: * @property string $ipAddress The IP address that the data in the model is
+20: * for.
+21: *
+22: */
+23: classIspextends AbstractModel
+24: {
+25: protected$autonomousSystemNumber;
+26: protected$autonomousSystemOrganization;
+27: protected$isp;
+28: protected$organization;
+29: protected$ipAddress;
+30:
+31: /**
+32: * @ignore
+33: */
+34: publicfunction__construct($raw)
+35: {
+36: parent::__construct($raw);
+37: $this->autonomousSystemNumber = $this->get('autonomous_system_number');
+38: $this->autonomousSystemOrganization =
+39: $this->get('autonomous_system_organization');
+40: $this->isp = $this->get('isp');
+41: $this->organization = $this->get('organization');
+42:
+43: $this->ipAddress = $this->get('ip_address');
+44: }
+45: }
+46:
1: <?php
+ 2:
+ 3: namespace GeoIp2\Record;
+ 4:
+ 5: /**
+ 6: * City-level data associated with an IP address.
+ 7: *
+ 8: * This record is returned by all the end points except the Country end point.
+ 9: *
+10: * @property int $confidence A value from 0-100 indicating MaxMind's
+11: * confidence that the city is correct. This attribute is only available
+12: * from the Insights end point.
+13: *
+14: * @property int $geonameId The GeoName ID for the city. This attribute
+15: * is returned by all end points.
+16: *
+17: * @property string $name The name of the city based on the locales list
+18: * passed to the constructor. This attribute is returned by all end points.
+19: *
+20: * @property array $names A array map where the keys are locale codes
+21: * and the values are names. This attribute is returned by all end points.
+22: */
+23: classCityextends AbstractPlaceRecord
+24: {
+25: /**
+26: * @ignore
+27: */
+28: protected$validAttributes = array('confidence', 'geonameId', 'names');
+29: }
+30:
1: <?php
+ 2:
+ 3: namespace GeoIp2\Record;
+ 4:
+ 5: /**
+ 6: * Contains data for the continent record associated with an IP address
+ 7: *
+ 8: * This record is returned by all the end points.
+ 9: *
+10: * @property string $code A two character continent code like "NA" (North
+11: * America) or "OC" (Oceania). This attribute is returned by all end points.
+12: *
+13: * @property int $geonameId The GeoName ID for the continent. This attribute
+14: * is returned by all end points.
+15: *
+16: * @property string $name Returns the name of the continent based on the
+17: * locales list passed to the constructor. This attribute is returned by
+18: * all end points.
+19: *
+20: * @property array $names An array map where the keys are locale codes
+21: * and the values are names. This attribute is returned by all end points.
+22: */
+23: classContinentextends AbstractPlaceRecord
+24: {
+25: /**
+26: * @ignore
+27: */
+28: protected$validAttributes = array(
+29: 'code',
+30: 'geonameId',
+31: 'names'
+32: );
+33: }
+34:
1: <?php
+ 2:
+ 3: namespace GeoIp2\Record;
+ 4:
+ 5: /**
+ 6: * Contains data for the country record associated with an IP address
+ 7: *
+ 8: * This record is returned by all the end points.
+ 9: *
+10: * @property int $confidence A value from 0-100 indicating MaxMind's
+11: * confidence that the country is correct. This attribute is only available
+12: * from the Omni end point.
+13: *
+14: * @property int $geonameId The GeoName ID for the country. This attribute is
+15: * returned by all end points.
+16: *
+17: * @property string $isoCode The {@link http://en.wikipedia.org/wiki/ISO_3166-1
+18: * two-character ISO 3166-1 alpha code} for the country. This attribute is
+19: * returned by all end points.
+20: *
+21: * @property string $name The name of the country based on the locales list
+22: * passed to the constructor. This attribute is returned by all end points.
+23: *
+24: * @property array $names An array map where the keys are locale codes and
+25: * the values are names. This attribute is returned by all end points.
+26: */
+27: classCountryextends AbstractPlaceRecord
+28: {
+29: /**
+30: * @ignore
+31: */
+32: protected$validAttributes = array(
+33: 'confidence',
+34: 'geonameId',
+35: 'isoCode',
+36: 'names'
+37: );
+38: }
+39:
1: <?php
+ 2:
+ 3: namespace GeoIp2\Record;
+ 4:
+ 5: /**
+ 6: * Contains data for the location record associated with an IP address
+ 7: *
+ 8: * This record is returned by all the end points except the Country end point.
+ 9: *
+10: * @property int $accuracyRadius The radius in kilometers around the
+11: * specified location where the IP address is likely to be. This attribute
+12: * is only available from the Insights end point.
+13: *
+14: * @property float $latitude The latitude of the location as a floating
+15: * point number. This attribute is returned by all end points except the
+16: * Country end point.
+17: *
+18: * @property float $longitude The longitude of the location as a
+19: * floating point number. This attribute is returned by all end points
+20: * except the Country end point.
+21: *
+22: * @property int $metroCode The metro code of the location if the location
+23: * is in the US. MaxMind returns the same metro codes as the
+24: * {@link
+25: * https://developers.google.com/adwords/api/docs/appendix/cities-DMAregions
+26: * Google AdWords API}. This attribute is returned by all end points except
+27: * the Country end point.
+28: *
+29: * @property string $timeZone The time zone associated with location, as
+30: * specified by the {@link http://www.iana.org/time-zones IANA Time Zone
+31: * Database}, e.g., "America/New_York". This attribute is returned by all
+32: * end points except the Country end point.
+33: */
+34: classLocationextends AbstractRecord
+35: {
+36: /**
+37: * @ignore
+38: */
+39: protected$validAttributes = array(
+40: 'accuracyRadius',
+41: 'latitude',
+42: 'longitude',
+43: 'metroCode',
+44: 'postalCode',
+45: 'postalConfidence',
+46: 'timeZone'
+47: );
+48: }
+49:
1: <?php
+ 2:
+ 3: namespace GeoIp2\Record;
+ 4:
+ 5: /**
+ 6: * Contains data about your account.
+ 7: *
+ 8: * This record is returned by all the end points.
+ 9: *
+10: * @property int $queriesRemaining The number of remaining queries you have
+11: * for the end point you are calling.
+12: */
+13: classMaxMindextends AbstractRecord
+14: {
+15: /**
+16: * @ignore
+17: */
+18: protected$validAttributes = array('queriesRemaining');
+19: }
+20:
1: <?php
+ 2:
+ 3: namespace GeoIp2\Record;
+ 4:
+ 5: /**
+ 6: * Contains data for the postal record associated with an IP address
+ 7: *
+ 8: * This record is returned by all the end points except the Country end point.
+ 9: *
+10: * @property string $code The postal code of the location. Postal codes are
+11: * not available for all countries. In some countries, this will only contain
+12: * part of the postal code. This attribute is returned by all end points
+13: * except the Country end point.
+14: *
+15: * @property int $confidence A value from 0-100 indicating MaxMind's
+16: * confidence that the postal code is correct. This attribute is only
+17: * available from the Insights end point.
+18: */
+19: classPostalextends AbstractRecord
+20: {
+21: /**
+22: * @ignore
+23: */
+24: protected$validAttributes = array('code', 'confidence');
+25: }
+26:
1: <?php
+ 2:
+ 3: namespace GeoIp2\Record;
+ 4:
+ 5: /**
+ 6: * Contains data for the represented country associated with an IP address
+ 7: *
+ 8: * This class contains the country-level data associated with an IP address
+ 9: * for the IP's represented country. The represented country is the country
+10: * represented by something like a military base.
+11: *
+12: * @property int $confidence A value from 0-100 indicating MaxMind's
+13: * confidence that the country is correct. This attribute is only available
+14: * from the Insights end point.
+15: *
+16: * @property int $geonameId The GeoName ID for the country.
+17: *
+18: * @property string $isoCode The {@link http://en.wikipedia.org/wiki/ISO_3166-1
+19: * two-character ISO 3166-1 alpha code} for the country.
+20: *
+21: * @property string $name The name of the country based on the locales list
+22: * passed to the constructor.
+23: *
+24: * @property array $names An array map where the keys are locale codes and
+25: * the values are names.
+26: *
+27: * @property string $type A string indicating the type of entity that is
+28: * representing the country. Currently we only return <code>military</code>
+29: * but this could expand to include other types in the future.
+30: */
+31: classRepresentedCountryextends Country
+32: {
+33: protected$validAttributes = array(
+34: 'confidence',
+35: 'geonameId',
+36: 'isoCode',
+37: 'names',
+38: 'type'
+39: );
+40: }
+41:
1: <?php
+ 2:
+ 3: namespace GeoIp2\Record;
+ 4:
+ 5: /**
+ 6: *
+ 7: * Contains data for the subdivisions associated with an IP address
+ 8: *
+ 9: * This record is returned by all the end points except the Country end point.
+10: *
+11: * @property int $confidence This is a value from 0-100 indicating MaxMind's
+12: * confidence that the subdivision is correct. This attribute is only
+13: * available from the Insights end point.
+14: *
+15: * @property int $geonameId This is a GeoName ID for the subdivision. This
+16: * attribute is returned by all end points except Country.
+17: *
+18: * @property string $isoCode This is a string up to three characters long
+19: * contain the subdivision portion of the {@link
+20: * http://en.wikipedia.org/wiki/ISO_3166-2 ISO 3166-2 code}. This attribute
+21: * is returned by all end points except Country.
+22: *
+23: * @property string $name The name of the subdivision based on the locales
+24: * list passed to the constructor. This attribute is returned by all end
+25: * points except Country.
+26: *
+27: * @property array $names An array map where the keys are locale codes and
+28: * the values are names. This attribute is returned by all end points except
+29: * Country.
+30: */
+31: classSubdivisionextends AbstractPlaceRecord
+32: {
+33: /**
+34: * @ignore
+35: */
+36: protected$validAttributes = array(
+37: 'confidence',
+38: 'geonameId',
+39: 'isoCode',
+40: 'names'
+41: );
+42: }
+43:
1: <?php
+ 2:
+ 3: namespace GeoIp2\Record;
+ 4:
+ 5: /**
+ 6: *
+ 7: * Contains data for the traits record associated with an IP address
+ 8: *
+ 9: * This record is returned by all the end points.
+10: *
+11: * @property int $autonomousSystemNumber The {@link
+12: * http://en.wikipedia.org/wiki/Autonomous_system_(Internet) autonomous
+13: * system number} associated with the IP address. This attribute is only
+14: * available from the City and Insights web service end points.
+15: *
+16: * @property string $autonomousSystemOrganization The organization
+17: * associated with the registered {@link
+18: * http://en.wikipedia.org/wiki/Autonomous_system_(Internet) autonomous
+19: * system number} for the IP address. This attribute is only available from
+20: * the City and Insights web service end points.
+21: *
+22: * @property string $domain The second level domain associated with the
+23: * IP address. This will be something like "example.com" or "example.co.uk",
+24: * not "foo.example.com". This attribute is only available from the
+25: * City and Insights web service end points.
+26: *
+27: * @property string $ipAddress The IP address that the data in the model
+28: * is for. If you performed a "me" lookup against the web service, this
+29: * will be the externally routable IP address for the system the code is
+30: * running on. If the system is behind a NAT, this may differ from the IP
+31: * address locally assigned to it. This attribute is returned by all end
+32: * points.
+33: *
+34: * @property boolean $isAnonymousProxy This is true if the IP is an
+35: * anonymous proxy. See {@link http://dev.maxmind.com/faq/geoip#anonproxy}
+36: * for further details. This attribute is returned by all end points.
+37: *
+38: * @property boolean $isSatelliteProvider This is true if the IP belongs
+39: * to a satellite Internet provider. This attribute is returned by all
+40: * end points.
+41: *
+42: * @property string $isp The name of the ISP associated with the IP address.
+43: * This attribute is only available from the City and Insights web service end
+44: * points.
+45: *
+46: * @property string $organization The name of the organization associated
+47: * with the IP address. This attribute is only available from the City and
+48: * Insights web service end points.
+49: *
+50: * @property string $userType <p>The user type associated with the IP
+51: * address. This can be one of the following values:</p>
+52: * <ul>
+53: * <li>business
+54: * <li>cafe
+55: * <li>cellular
+56: * <li>college
+57: * <li>content_delivery_network
+58: * <li>dialup
+59: * <li>government
+60: * <li>hosting
+61: * <li>library
+62: * <li>military
+63: * <li>residential
+64: * <li>router
+65: * <li>school
+66: * <li>search_engine_spider
+67: * <li>traveler
+68: * </ul>
+69: * <p>
+70: * This attribute is only available from the Insights web service end
+71: * point.
+72: * </p>
+73: */
+74: classTraitsextends AbstractRecord
+75: {
+76: /**
+77: * @ignore
+78: */
+79: protected$validAttributes = array(
+80: 'autonomousSystemNumber',
+81: 'autonomousSystemOrganization',
+82: 'domain',
+83: 'isAnonymousProxy',
+84: 'isSatelliteProvider',
+85: 'isp',
+86: 'ipAddress',
+87: 'organization',
+88: 'userType'
+89: );
+90: }
+91:
1: <?php
+ 2:
+ 3: namespace GeoIp2\WebService;
+ 4:
+ 5: use GeoIp2\Exception\AddressNotFoundException;
+ 6: use GeoIp2\Exception\AuthenticationException;
+ 7: use GeoIp2\Exception\GeoIp2Exception;
+ 8: use GeoIp2\Exception\HttpException;
+ 9: use GeoIp2\Exception\InvalidRequestException;
+ 10: use GeoIp2\Exception\OutOfQueriesException;
+ 11: use GeoIp2\ProviderInterface;
+ 12: use Guzzle\Common\Exception\RuntimeException;
+ 13: use Guzzle\Http\Client as GuzzleClient;
+ 14: use Guzzle\Http\Exception\ClientErrorResponseException;
+ 15: use Guzzle\Http\Exception\ServerErrorResponseException;
+ 16:
+ 17: /**
+ 18: * This class provides a client API for all the GeoIP2 Precision web service
+ 19: * end points. The end points are Country, City, and Insights. Each end point
+ 20: * returns a different set of data about an IP address, with Country returning
+ 21: * the least data and Insights the most.
+ 22: *
+ 23: * Each web service end point is represented by a different model class, and
+ 24: * these model classes in turn contain multiple Record classes. The record
+ 25: * classes have attributes which contain data about the IP address.
+ 26: *
+ 27: * If the web service does not return a particular piece of data for an IP
+ 28: * address, the associated attribute is not populated.
+ 29: *
+ 30: * The web service may not return any information for an entire record, in
+ 31: * which case all of the attributes for that record class will be empty.
+ 32: *
+ 33: * **Usage**
+ 34: *
+ 35: * The basic API for this class is the same for all of the web service end
+ 36: * points. First you create a web service object with your MaxMind
+ 37: * <code>$userId</code> and <code>$licenseKey</code>, then you call the method
+ 38: * corresponding to a specific end point, passing it the IP address you want
+ 39: * to look up.
+ 40: *
+ 41: * If the request succeeds, the method call will return a model class for
+ 42: * the end point you called. This model in turn contains multiple record
+ 43: * classes, each of which represents part of the data returned by the web
+ 44: * service.
+ 45: *
+ 46: * If the request fails, the client class throws an exception.
+ 47: */
+ 48: classClientimplements ProviderInterface
+ 49: {
+ 50: private$userId;
+ 51: private$licenseKey;
+ 52: private$locales;
+ 53: private$host;
+ 54: private$guzzleClient;
+ 55:
+ 56: /**
+ 57: * Constructor.
+ 58: *
+ 59: * @param int $userId Your MaxMind user ID
+ 60: * @param string $licenseKey Your MaxMind license key
+ 61: * @param array $locales List of locale codes to use in name property
+ 62: * from most preferred to least preferred.
+ 63: * @param string $host Optional host parameter
+ 64: * @param object $guzzleClient Optional Guzzle client to use (to facilitate
+ 65: * unit testing).
+ 66: */
+ 67: publicfunction__construct(
+ 68: $userId,
+ 69: $licenseKey,
+ 70: $locales = array('en'),
+ 71: $host = 'geoip.maxmind.com',
+ 72: $guzzleClient = null
+ 73: ) {
+ 74: $this->userId = $userId;
+ 75: $this->licenseKey = $licenseKey;
+ 76: $this->locales = $locales;
+ 77: $this->host = $host;
+ 78: // To enable unit testing
+ 79: $this->guzzleClient = $guzzleClient;
+ 80: }
+ 81:
+ 82: /**
+ 83: * This method calls the GeoIP2 Precision: City endpoint.
+ 84: *
+ 85: * @param string $ipAddress IPv4 or IPv6 address as a string. If no
+ 86: * address is provided, the address that the web service is called
+ 87: * from will be used.
+ 88: *
+ 89: * @return \GeoIp2\Model\City
+ 90: *
+ 91: * @throws \GeoIp2\Exception\AddressNotFoundException if the address you
+ 92: * provided is not in our database (e.g., a private address).
+ 93: * @throws \GeoIp2\Exception\AuthenticationException if there is a problem
+ 94: * with the user ID or license key that you provided.
+ 95: * @throws \GeoIp2\Exception\OutOfQueriesException if your account is out
+ 96: * of queries.
+ 97: * @throws \GeoIp2\Exception\InvalidRequestException} if your request was
+ 98: * received by the web service but is invalid for some other reason.
+ 99: * This may indicate an issue with this API. Please report the error to
+100: * MaxMind.
+101: * @throws \GeoIp2\Exception\HttpException if an unexpected HTTP error
+102: * code or message was returned. This could indicate a problem with the
+103: * connection between your server and the web service or that the web
+104: * service returned an invalid document or 500 error code.
+105: * @throws \GeoIp2\Exception\GeoIp2Exception This serves as the parent
+106: * class to the above exceptions. It will be thrown directly if a 200
+107: * status code is returned but the body is invalid.
+108: */
+109: publicfunctioncity($ipAddress = 'me')
+110: {
+111: return$this->responseFor('city', 'City', $ipAddress);
+112: }
+113:
+114: /**
+115: * This method calls the GeoIP2 Precision: Country endpoint.
+116: *
+117: * @param string $ipAddress IPv4 or IPv6 address as a string. If no
+118: * address is provided, the address that the web service is called
+119: * from will be used.
+120: *
+121: * @return \GeoIp2\Model\Country
+122: *
+123: * @throws \GeoIp2\Exception\AddressNotFoundException if the address you
+124: * provided is not in our database (e.g., a private address).
+125: * @throws \GeoIp2\Exception\AuthenticationException if there is a problem
+126: * with the user ID or license key that you provided.
+127: * @throws \GeoIp2\Exception\OutOfQueriesException if your account is out
+128: * of queries.
+129: * @throws \GeoIp2\Exception\InvalidRequestException} if your request was
+130: * received by the web service but is invalid for some other reason.
+131: * This may indicate an issue with this API. Please report the error to
+132: * MaxMind.
+133: * @throws \GeoIp2\Exception\HttpException if an unexpected HTTP error
+134: * code or message was returned. This could indicate a problem with the
+135: * connection between your server and the web service or that the web
+136: * service returned an invalid document or 500 error code.
+137: * @throws \GeoIp2\Exception\GeoIp2Exception This serves as the parent
+138: * class to the above exceptions. It will be thrown directly if a 200
+139: * status code is returned but the body is invalid.
+140: */
+141: publicfunctioncountry($ipAddress = 'me')
+142: {
+143: return$this->responseFor('country', 'Country', $ipAddress);
+144: }
+145:
+146: /**
+147: * This method calls the GeoIP2 Precision: Insights endpoint.
+148: *
+149: * @param string $ipAddress IPv4 or IPv6 address as a string. If no
+150: * address is provided, the address that the web service is called
+151: * from will be used.
+152: *
+153: * @return \GeoIp2\Model\Insights
+154: *
+155: * @throws \GeoIp2\Exception\AddressNotFoundException if the address you
+156: * provided is not in our database (e.g., a private address).
+157: * @throws \GeoIp2\Exception\AuthenticationException if there is a problem
+158: * with the user ID or license key that you provided.
+159: * @throws \GeoIp2\Exception\OutOfQueriesException if your account is out
+160: * of queries.
+161: * @throws \GeoIp2\Exception\InvalidRequestException} if your request was
+162: * received by the web service but is invalid for some other reason.
+163: * This may indicate an issue with this API. Please report the error to
+164: * MaxMind.
+165: * @throws \GeoIp2\Exception\HttpException if an unexpected HTTP error
+166: * code or message was returned. This could indicate a problem with the
+167: * connection between your server and the web service or that the web
+168: * service returned an invalid document or 500 error code.
+169: * @throws \GeoIp2\Exception\GeoIp2Exception This serves as the parent
+170: * class to the above exceptions. It will be thrown directly if a 200
+171: * status code is returned but the body is invalid.
+172: */
+173: publicfunctioninsights($ipAddress = 'me')
+174: {
+175: return$this->responseFor('insights', 'Insights', $ipAddress);
+176: }
+177:
+178: privatefunctionresponseFor($endpoint, $class, $ipAddress)
+179: {
+180: $uri = implode('/', array($this->baseUri(), $endpoint, $ipAddress));
+181:
+182: $client = $this->guzzleClient ?
+183: $this->guzzleClient : new GuzzleClient();
+184: $request = $client->get($uri, array('Accept' => 'application/json'));
+185: $request->setAuth($this->userId, $this->licenseKey);
+186: $this->setUserAgent($request);
+187:
+188: try {
+189: $response = $request->send();
+190: } catch (ClientErrorResponseException $e) {
+191: $this->handle4xx($e->getResponse(), $uri);
+192: } catch (ServerErrorResponseException $e) {
+193: $this->handle5xx($e->getResponse(), $uri);
+194: }
+195:
+196: if ($response && $response->isSuccessful()) {
+197: $body = $this->handleSuccess($response, $uri);
+198: $class = "GeoIp2\\Model\\" . $class;
+199: returnnew$class($body, $this->locales);
+200: } else {
+201: $this->handleNon200($response, $uri);
+202: }
+203: }
+204:
+205: privatefunctionhandleSuccess($response, $uri)
+206: {
+207: if ($response->getContentLength() == 0) {
+208: thrownew GeoIp2Exception(
+209: "Received a 200 response for $uri but did not " .
+210: "receive a HTTP body."
+211: );
+212: }
+213:
+214: try {
+215: return$response->json();
+216: } catch (RuntimeException $e) {
+217: thrownew GeoIp2Exception(
+218: "Received a 200 response for $uri but could not decode " .
+219: "the response as JSON: " . $e->getMessage()
+220: );
+221:
+222: }
+223: }
+224:
+225: privatefunctionhandle4xx($response, $uri)
+226: {
+227: $status = $response->getStatusCode();
+228:
+229: if ($response->getContentLength() > 0) {
+230: if (strstr($response->getContentType(), 'json')) {
+231: try {
+232: $body = $response->json();
+233: if (!isset($body['code']) || !isset($body['error'])) {
+234: thrownew GeoIp2Exception(
+235: 'Response contains JSON but it does not specify ' .
+236: 'code or error keys: ' . $response->getBody()
+237: );
+238: }
+239: } catch (RuntimeException $e) {
+240: thrownew HttpException(
+241: "Received a $status error for $uri but it did not " .
+242: "include the expected JSON body: " .
+243: $e->getMessage(),
+244: $status,
+245: $uri
+246: );
+247: }
+248: } else {
+249: thrownew HttpException(
+250: "Received a $status error for $uri with the " .
+251: "following body: " . $response->getBody(),
+252: $status,
+253: $uri
+254: );
+255: }
+256: } else {
+257: thrownew HttpException(
+258: "Received a $status error for $uri with no body",
+259: $status,
+260: $uri
+261: );
+262: }
+263: $this->handleWebServiceError(
+264: $body['error'],
+265: $body['code'],
+266: $status,
+267: $uri
+268: );
+269: }
+270:
+271: privatefunctionhandleWebServiceError($message, $code, $status, $uri)
+272: {
+273: switch ($code) {
+274: case'IP_ADDRESS_NOT_FOUND':
+275: case'IP_ADDRESS_RESERVED':
+276: thrownew AddressNotFoundException($message);
+277: case'AUTHORIZATION_INVALID':
+278: case'LICENSE_KEY_REQUIRED':
+279: case'USER_ID_REQUIRED':
+280: thrownew AuthenticationException($message);
+281: case'OUT_OF_QUERIES':
+282: thrownew OutOfQueriesException($message);
+283: default:
+284: thrownew InvalidRequestException(
+285: $message,
+286: $code,
+287: $status,
+288: $uri
+289: );
+290: }
+291: }
+292:
+293: privatefunctionhandle5xx($response, $uri)
+294: {
+295: $status = $response->getStatusCode();
+296:
+297: thrownew HttpException(
+298: "Received a server error ($status) for $uri",
+299: $status,
+300: $uri
+301: );
+302: }
+303:
+304: privatefunctionhandleNon200($response, $uri)
+305: {
+306: $status = $response->getStatusCode();
+307:
+308: thrownew HttpException(
+309: "Received a very surprising HTTP status " .
+310: "($status) for $uri",
+311: $status,
+312: $uri
+313: );
+314: }
+315:
+316: privatefunctionsetUserAgent($request)
+317: {
+318: $userAgent = $request->getHeader('User-Agent');
+319: $userAgent = "GeoIP2 PHP API ($userAgent)";
+320: $request->setHeader('User-Agent', $userAgent);
+321: }
+322:
+323: privatefunctionbaseUri()
+324: {
+325: return'https://' . $this->host . '/geoip/v2.1';
+326: }
+327: }
+328:
+
+
+
+
diff --git a/index.md b/index.md
index 34819c1..d8e8024 100644
--- a/index.md
+++ b/index.md
@@ -2,7 +2,7 @@
layout: default
title: MaxMind GeoIP2 PHP API
language: php
-version: v0.8.1
+version: v0.9.0
---
# GeoIP2 PHP API #
@@ -33,7 +33,7 @@ You should now have the file `composer.phar` in your project directory.
Run in your project root:
```
-php composer.phar require geoip2/geoip2:~0.8.1
+php composer.phar require geoip2/geoip2:~0.9.0
```
You should now have the files `composer.json` and `composer.lock` as well as