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 database specific methods.
+
+
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.
Model class for the data returned by GeoIP2 City web service and database.
+
+
The only difference between the City and Insights model classes is which
+fields in each record may be populated. See
+http://dev.maxmind.com/geoip/geoip2/web-services more details.
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.
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.
Model class for the data returned by GeoIP2 Country web service and database.
+
+
The only difference between the City and Insights model classes is which
+fields in each record may be populated. See
+http://dev.maxmind.com/geoip/geoip2/web-services more details.
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.
Model class for the data returned by GeoIP2 Precision: Insights web service.
+
+
The only difference between the City and Insights model classes is which
+fields in each record may be populated. See
+http://dev.maxmind.com/geoip/geoip2/web-services more details.
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.
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.
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 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.
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.
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.
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 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.
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.
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.
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.
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.
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.
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.
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 database specific methods.
+ 12: *
+ 13: * ## Usage ##
+ 14: *
+ 15: * The basic API for this class is the same for every database. First, you
+ 16: * create a reader object, specifying a file name. You then call the method
+ 17: * corresponding to the specific database, passing it the IP address you want
+ 18: * to look up.
+ 19: *
+ 20: * If the request succeeds, the method call will return a model class for
+ 21: * the method you called. This model in turn contains multiple record classes,
+ 22: * each of which represents part of the data returned by the database. If
+ 23: * the database does not contain the requested information, the attributes
+ 24: * on the record class will have a `null` value.
+ 25: *
+ 26: * If the address is not in the database, an
+ 27: * {@link \GeoIp2\Exception\AddressNotFoundException} exception will be
+ 28: * thrown. If an invalid IP address is passed to one of the methods, a
+ 29: * SPL {@link \InvalidArgumentException} will be thrown. If the database is
+ 30: * corrupt or invalid, a {@link \MaxMind\Db\Reader\InvalidDatabaseException}
+ 31: * will be thrown.
+ 32: *
+ 33: */
+ 34: classReaderimplements ProviderInterface
+ 35: {
+ 36: private$dbReader;
+ 37: private$locales;
+ 38:
+ 39: /**
+ 40: * Constructor.
+ 41: *
+ 42: * @param string $filename The path to the GeoIP2 database file.
+ 43: * @param array $locales List of locale codes to use in name property
+ 44: * from most preferred to least preferred.
+ 45: * @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
+ 46: * is corrupt or invalid
+ 47: */
+ 48: publicfunction__construct(
+ 49: $filename,
+ 50: $locales = array('en')
+ 51: ) {
+ 52: $this->dbReader = new DbReader($filename);
+ 53: $this->locales = $locales;
+ 54: }
+ 55:
+ 56: /**
+ 57: * This method returns a GeoIP2 City model.
+ 58: *
+ 59: * @param string $ipAddress IPv4 or IPv6 address as a string.
+ 60: *
+ 61: * @return \GeoIp2\Model\City
+ 62: *
+ 63: * @throws \GeoIp2\Exception\AddressNotFoundException if the address is
+ 64: * not in the database.
+ 65: * @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
+ 66: * is corrupt or invalid
+ 67: */
+ 68: publicfunctioncity($ipAddress)
+ 69: {
+ 70: return$this->modelFor('City', 'City', $ipAddress);
+ 71: }
+ 72:
+ 73: /**
+ 74: * This method returns a GeoIP2 Country model.
+ 75: *
+ 76: * @param string $ipAddress IPv4 or IPv6 address as a string.
+ 77: *
+ 78: * @return \GeoIp2\Model\Country
+ 79: *
+ 80: * @throws \GeoIp2\Exception\AddressNotFoundException if the address is
+ 81: * not in the database.
+ 82: * @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
+ 83: * is corrupt or invalid
+ 84: */
+ 85: publicfunctioncountry($ipAddress)
+ 86: {
+ 87: return$this->modelFor('Country', 'Country', $ipAddress);
+ 88: }
+ 89:
+ 90: /**
+ 91: * This method returns a GeoIP2 Anonymous IP model.
+ 92: *
+ 93: * @param string $ipAddress IPv4 or IPv6 address as a string.
+ 94: *
+ 95: * @return \GeoIp2\Model\AnonymousIp
+ 96: *
+ 97: * @throws \GeoIp2\Exception\AddressNotFoundException if the address is
+ 98: * not in the database.
+ 99: * @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
+100: * is corrupt or invalid
+101: */
+102: publicfunctionanonymousIp($ipAddress)
+103: {
+104: return$this->flatModelFor(
+105: 'AnonymousIp',
+106: 'GeoIP2-Anonymous-IP',
+107: $ipAddress
+108: );
+109: }
+110:
+111: /**
+112: * This method returns a GeoIP2 Connection Type model.
+113: *
+114: * @param string $ipAddress IPv4 or IPv6 address as a string.
+115: *
+116: * @return \GeoIp2\Model\ConnectionType
+117: *
+118: * @throws \GeoIp2\Exception\AddressNotFoundException if the address is
+119: * not in the database.
+120: * @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
+121: * is corrupt or invalid
+122: */
+123: publicfunctionconnectionType($ipAddress)
+124: {
+125: return$this->flatModelFor(
+126: 'ConnectionType',
+127: 'GeoIP2-Connection-Type',
+128: $ipAddress
+129: );
+130: }
+131:
+132: /**
+133: * This method returns a GeoIP2 Domain model.
+134: *
+135: * @param string $ipAddress IPv4 or IPv6 address as a string.
+136: *
+137: * @return \GeoIp2\Model\Domain
+138: *
+139: * @throws \GeoIp2\Exception\AddressNotFoundException if the address is
+140: * not in the database.
+141: * @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
+142: * is corrupt or invalid
+143: */
+144: publicfunctiondomain($ipAddress)
+145: {
+146: return$this->flatModelFor(
+147: 'Domain',
+148: 'GeoIP2-Domain',
+149: $ipAddress
+150: );
+151: }
+152:
+153: /**
+154: * This method returns a GeoIP2 ISP model.
+155: *
+156: * @param string $ipAddress IPv4 or IPv6 address as a string.
+157: *
+158: * @return \GeoIp2\Model\Isp
+159: *
+160: * @throws \GeoIp2\Exception\AddressNotFoundException if the address is
+161: * not in the database.
+162: * @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
+163: * is corrupt or invalid
+164: */
+165: publicfunctionisp($ipAddress)
+166: {
+167: return$this->flatModelFor(
+168: 'Isp',
+169: 'GeoIP2-ISP',
+170: $ipAddress
+171: );
+172: }
+173:
+174: privatefunctionmodelFor($class, $type, $ipAddress)
+175: {
+176: $record = $this->getRecord($class, $type, $ipAddress);
+177:
+178: $record['traits']['ip_address'] = $ipAddress;
+179: $class = "GeoIp2\\Model\\" . $class;
+180:
+181: returnnew$class($record, $this->locales);
+182: }
+183:
+184: privatefunctionflatModelFor($class, $type, $ipAddress)
+185: {
+186: $record = $this->getRecord($class, $type, $ipAddress);
+187:
+188: $record['ip_address'] = $ipAddress;
+189: $class = "GeoIp2\\Model\\" . $class;
+190:
+191: returnnew$class($record);
+192: }
+193:
+194: privatefunctiongetRecord($class, $type, $ipAddress)
+195: {
+196: if (strpos($this->metadata()->databaseType, $type) === false) {
+197: $method = lcfirst($class);
+198: thrownew \BadMethodCallException(
+199: "The $method method cannot be used to open a "
+200: . $this->metadata()->databaseType . " database"
+201: );
+202: }
+203: $record = $this->dbReader->get($ipAddress);
+204: if ($record === null) {
+205: thrownew AddressNotFoundException(
+206: "The address $ipAddress is not in the database."
+207: );
+208: }
+209: return$record;
+210: }
+211:
+212: /**
+213: * @throws \InvalidArgumentException if arguments are passed to the method.
+214: * @throws \BadMethodCallException if the database has been closed.
+215: * @return \MaxMind\Db\Reader\Metadata object for the database.
+216: */
+217: publicfunctionmetadata()
+218: {
+219: return$this->dbReader->metadata();
+220: }
+221:
+222: /**
+223: * Closes the GeoIP2 database and returns the resources to the system.
+224: */
+225: publicfunctionclose()
+226: {
+227: $this->dbReader->close();
+228: }
+229: }
+230:
1: <?php
+ 2:
+ 3: namespace GeoIp2\Model;
+ 4:
+ 5: /**
+ 6: * This class provides the GeoIP2 Anonymous IP model.
+ 7: *
+ 8: * @property boolean $isAnonymous This is true if the IP address belongs to
+ 9: * any sort of anonymous network.
+10: *
+11: * @property boolean $isAnonymousVpn This is true if the IP address belongs to
+12: * an anonymous VPN system.
+13: *
+14: * @property boolean $isHostingProvider This is true if the IP address belongs
+15: * to a hosting provider.
+16: *
+17: * @property boolean $isPublicProxy This is true if the IP address belongs to
+18: * a public proxy.
+19: *
+20: * @property boolean $isTorExitNode This is true if the IP address is a Tor
+21: * exit node.
+22: *
+23: * @property string $ipAddress The IP address that the data in the model is
+24: * for.
+25: *
+26: */
+27: classAnonymousIpextends AbstractModel
+28: {
+29: protected$isAnonymous;
+30: protected$isAnonymousVpn;
+31: protected$isHostingProvider;
+32: protected$isPublicProxy;
+33: protected$isTorExitNode;
+34: protected$ipAddress;
+35:
+36: /**
+37: * @ignore
+38: */
+39: publicfunction__construct($raw)
+40: {
+41: parent::__construct($raw);
+42:
+43: $this->isAnonymous = $this->get('is_anonymous');
+44: $this->isAnonymousVpn = $this->get('is_anonymous_vpn');
+45: $this->isHostingProvider = $this->get('is_hosting_provider');
+46: $this->isPublicProxy = $this->get('is_public_proxy');
+47: $this->isTorExitNode = $this->get('is_tor_exit_node');
+48: $this->ipAddress = $this->get('ip_address');
+49: }
+50: }
+51:
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 `$userId`
+ 37: * and `$licenseKey`, then you call the method corresponding to a specific end
+ 38: * point, passing it the IP address you want to look up.
+ 39: *
+ 40: * If the request succeeds, the method call will return a model class for
+ 41: * the end point you called. This model in turn contains multiple record
+ 42: * classes, each of which represents part of the data returned by the web
+ 43: * service.
+ 44: *
+ 45: * If the request fails, the client class throws an exception.
+ 46: */
+ 47: classClientimplements ProviderInterface
+ 48: {
+ 49: private$userId;
+ 50: private$licenseKey;
+ 51: private$locales;
+ 52: private$host;
+ 53: private$guzzleClient;
+ 54:
+ 55: /**
+ 56: * Constructor.
+ 57: *
+ 58: * @param int $userId Your MaxMind user ID
+ 59: * @param string $licenseKey Your MaxMind license key
+ 60: * @param array $locales List of locale codes to use in name property
+ 61: * from most preferred to least preferred.
+ 62: * @param string $host Optional host parameter
+ 63: * @param object $guzzleClient Optional Guzzle client to use (to facilitate
+ 64: * unit testing).
+ 65: */
+ 66: publicfunction__construct(
+ 67: $userId,
+ 68: $licenseKey,
+ 69: $locales = array('en'),
+ 70: $host = 'geoip.maxmind.com',
+ 71: $guzzleClient = null
+ 72: ) {
+ 73: $this->userId = $userId;
+ 74: $this->licenseKey = $licenseKey;
+ 75: $this->locales = $locales;
+ 76: $this->host = $host;
+ 77: // To enable unit testing
+ 78: $this->guzzleClient = $guzzleClient;
+ 79: }
+ 80:
+ 81: /**
+ 82: * This method calls the GeoIP2 Precision: City endpoint.
+ 83: *
+ 84: * @param string $ipAddress IPv4 or IPv6 address as a string. If no
+ 85: * address is provided, the address that the web service is called
+ 86: * from will be used.
+ 87: *
+ 88: * @return \GeoIp2\Model\City
+ 89: *
+ 90: * @throws \GeoIp2\Exception\AddressNotFoundException if the address you
+ 91: * provided is not in our database (e.g., a private address).
+ 92: * @throws \GeoIp2\Exception\AuthenticationException if there is a problem
+ 93: * with the user ID or license key that you provided.
+ 94: * @throws \GeoIp2\Exception\OutOfQueriesException if your account is out
+ 95: * of queries.
+ 96: * @throws \GeoIp2\Exception\InvalidRequestException} if your request was
+ 97: * received by the web service but is invalid for some other reason.
+ 98: * This may indicate an issue with this API. Please report the error to
+ 99: * MaxMind.
+100: * @throws \GeoIp2\Exception\HttpException if an unexpected HTTP error
+101: * code or message was returned. This could indicate a problem with the
+102: * connection between your server and the web service or that the web
+103: * service returned an invalid document or 500 error code.
+104: * @throws \GeoIp2\Exception\GeoIp2Exception This serves as the parent
+105: * class to the above exceptions. It will be thrown directly if a 200
+106: * status code is returned but the body is invalid.
+107: */
+108: publicfunctioncity($ipAddress = 'me')
+109: {
+110: return$this->responseFor('city', 'City', $ipAddress);
+111: }
+112:
+113: /**
+114: * This method calls the GeoIP2 Precision: Country endpoint.
+115: *
+116: * @param string $ipAddress IPv4 or IPv6 address as a string. If no
+117: * address is provided, the address that the web service is called
+118: * from will be used.
+119: *
+120: * @return \GeoIp2\Model\Country
+121: *
+122: * @throws \GeoIp2\Exception\AddressNotFoundException if the address you
+123: * provided is not in our database (e.g., a private address).
+124: * @throws \GeoIp2\Exception\AuthenticationException if there is a problem
+125: * with the user ID or license key that you provided.
+126: * @throws \GeoIp2\Exception\OutOfQueriesException if your account is out
+127: * of queries.
+128: * @throws \GeoIp2\Exception\InvalidRequestException} if your request was
+129: * received by the web service but is invalid for some other reason.
+130: * This may indicate an issue with this API. Please report the error to
+131: * MaxMind.
+132: * @throws \GeoIp2\Exception\HttpException if an unexpected HTTP error
+133: * code or message was returned. This could indicate a problem with the
+134: * connection between your server and the web service or that the web
+135: * service returned an invalid document or 500 error code.
+136: * @throws \GeoIp2\Exception\GeoIp2Exception This serves as the parent
+137: * class to the above exceptions. It will be thrown directly if a 200
+138: * status code is returned but the body is invalid.
+139: */
+140: publicfunctioncountry($ipAddress = 'me')
+141: {
+142: return$this->responseFor('country', 'Country', $ipAddress);
+143: }
+144:
+145: /**
+146: * This method calls the GeoIP2 Precision: Insights endpoint.
+147: *
+148: * @param string $ipAddress IPv4 or IPv6 address as a string. If no
+149: * address is provided, the address that the web service is called
+150: * from will be used.
+151: *
+152: * @return \GeoIp2\Model\Insights
+153: *
+154: * @throws \GeoIp2\Exception\AddressNotFoundException if the address you
+155: * provided is not in our database (e.g., a private address).
+156: * @throws \GeoIp2\Exception\AuthenticationException if there is a problem
+157: * with the user ID or license key that you provided.
+158: * @throws \GeoIp2\Exception\OutOfQueriesException if your account is out
+159: * of queries.
+160: * @throws \GeoIp2\Exception\InvalidRequestException} if your request was
+161: * received by the web service but is invalid for some other reason.
+162: * This may indicate an issue with this API. Please report the error to
+163: * MaxMind.
+164: * @throws \GeoIp2\Exception\HttpException if an unexpected HTTP error
+165: * code or message was returned. This could indicate a problem with the
+166: * connection between your server and the web service or that the web
+167: * service returned an invalid document or 500 error code.
+168: * @throws \GeoIp2\Exception\GeoIp2Exception This serves as the parent
+169: * class to the above exceptions. It will be thrown directly if a 200
+170: * status code is returned but the body is invalid.
+171: */
+172: publicfunctioninsights($ipAddress = 'me')
+173: {
+174: return$this->responseFor('insights', 'Insights', $ipAddress);
+175: }
+176:
+177: privatefunctionresponseFor($endpoint, $class, $ipAddress)
+178: {
+179: $uri = implode('/', array($this->baseUri(), $endpoint, $ipAddress));
+180:
+181: $client = $this->guzzleClient ?
+182: $this->guzzleClient : new GuzzleClient();
+183: $request = $client->get($uri, array('Accept' => 'application/json'));
+184: $request->setAuth($this->userId, $this->licenseKey);
+185: $this->setUserAgent($request);
+186:
+187: try {
+188: $response = $request->send();
+189: } catch (ClientErrorResponseException $e) {
+190: $this->handle4xx($e->getResponse(), $uri);
+191: } catch (ServerErrorResponseException $e) {
+192: $this->handle5xx($e->getResponse(), $uri);
+193: }
+194:
+195: if ($response && $response->isSuccessful()) {
+196: $body = $this->handleSuccess($response, $uri);
+197: $class = "GeoIp2\\Model\\" . $class;
+198: returnnew$class($body, $this->locales);
+199: } else {
+200: $this->handleNon200($response, $uri);
+201: }
+202: }
+203:
+204: privatefunctionhandleSuccess($response, $uri)
+205: {
+206: if ($response->getContentLength() == 0) {
+207: thrownew GeoIp2Exception(
+208: "Received a 200 response for $uri but did not " .
+209: "receive a HTTP body."
+210: );
+211: }
+212:
+213: try {
+214: return$response->json();
+215: } catch (RuntimeException $e) {
+216: thrownew GeoIp2Exception(
+217: "Received a 200 response for $uri but could not decode " .
+218: "the response as JSON: " . $e->getMessage()
+219: );
+220:
+221: }
+222: }
+223:
+224: privatefunctionhandle4xx($response, $uri)
+225: {
+226: $status = $response->getStatusCode();
+227:
+228: if ($response->getContentLength() > 0) {
+229: if (strstr($response->getContentType(), 'json')) {
+230: try {
+231: $body = $response->json();
+232: if (!isset($body['code']) || !isset($body['error'])) {
+233: thrownew GeoIp2Exception(
+234: 'Response contains JSON but it does not specify ' .
+235: 'code or error keys: ' . $response->getBody()
+236: );
+237: }
+238: } catch (RuntimeException $e) {
+239: thrownew HttpException(
+240: "Received a $status error for $uri but it did not " .
+241: "include the expected JSON body: " .
+242: $e->getMessage(),
+243: $status,
+244: $uri
+245: );
+246: }
+247: } else {
+248: thrownew HttpException(
+249: "Received a $status error for $uri with the " .
+250: "following body: " . $response->getBody(),
+251: $status,
+252: $uri
+253: );
+254: }
+255: } else {
+256: thrownew HttpException(
+257: "Received a $status error for $uri with no body",
+258: $status,
+259: $uri
+260: );
+261: }
+262: $this->handleWebServiceError(
+263: $body['error'],
+264: $body['code'],
+265: $status,
+266: $uri
+267: );
+268: }
+269:
+270: privatefunctionhandleWebServiceError($message, $code, $status, $uri)
+271: {
+272: switch ($code) {
+273: case'IP_ADDRESS_NOT_FOUND':
+274: case'IP_ADDRESS_RESERVED':
+275: thrownew AddressNotFoundException($message);
+276: case'AUTHORIZATION_INVALID':
+277: case'LICENSE_KEY_REQUIRED':
+278: case'USER_ID_REQUIRED':
+279: thrownew AuthenticationException($message);
+280: case'OUT_OF_QUERIES':
+281: thrownew OutOfQueriesException($message);
+282: default:
+283: thrownew InvalidRequestException(
+284: $message,
+285: $code,
+286: $status,
+287: $uri
+288: );
+289: }
+290: }
+291:
+292: privatefunctionhandle5xx($response, $uri)
+293: {
+294: $status = $response->getStatusCode();
+295:
+296: thrownew HttpException(
+297: "Received a server error ($status) for $uri",
+298: $status,
+299: $uri
+300: );
+301: }
+302:
+303: privatefunctionhandleNon200($response, $uri)
+304: {
+305: $status = $response->getStatusCode();
+306:
+307: thrownew HttpException(
+308: "Received a very surprising HTTP status " .
+309: "($status) for $uri",
+310: $status,
+311: $uri
+312: );
+313: }
+314:
+315: privatefunctionsetUserAgent($request)
+316: {
+317: $userAgent = $request->getHeader('User-Agent');
+318: $userAgent = "GeoIP2 PHP API ($userAgent)";
+319: $request->setHeader('User-Agent', $userAgent);
+320: }
+321:
+322: privatefunctionbaseUri()
+323: {
+324: return'https://' . $this->host . '/geoip/v2.1';
+325: }
+326: }
+327: