Skip to content

Commit 073e3dc

Browse files
committed
Document how to use the GeoLite2 web service
1 parent 6e9443a commit 073e3dc

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

README.md

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ You should now have the file `composer.phar` in your project directory.
2626

2727
Run in your project root:
2828

29-
```
29+
```sh
3030
php composer.phar require geoip2/geoip2:~2.0
3131
```
3232

@@ -265,13 +265,33 @@ print($record->network . "\n"); // '128.101.101.101/32'
265265
### Usage ###
266266

267267
To use this API, you must create a new `\GeoIp2\WebService\Client`
268-
object with your `$accountId` and `$licenseKey`, then you call the method
269-
corresponding to a specific end point, passing it the IP address you want to
270-
look up.
268+
object with your `$accountId` and `$licenseKey`:
269+
270+
```php
271+
$client = new Client(42, 'abcdef123456');
272+
```
273+
274+
You may also call the constructor with additional arguments. The third argument
275+
specifies the language preferences when using the `->name` method on the model
276+
classes that this client creates. The fourth argument is additional options
277+
such as `host` and `timeout`.
278+
279+
For instance, to call the GeoLite2 web service instead of GeoIP2 Precision:
280+
281+
```php
282+
$client = new Client(42, 'abcdef123456', ['en'], ['host' => 'geolite.info']);
283+
```
284+
285+
After creating the client, you may now call the method corresponding to a
286+
specific endpoint with the IP address to look up, e.g.:
287+
288+
```php
289+
$record = $client->city('128.101.101.101');
290+
```
271291

272-
If the request succeeds, the method call will return a model class for the end
273-
point you called. This model in turn contains multiple record classes, each of
274-
which represents part of the data returned by the web service.
292+
If the request succeeds, the method call will return a model class for the
293+
endpoint you called. This model in turn contains multiple record classes, each
294+
of which represents part of the data returned by the web service.
275295

276296
If there is an error, a structured exception is thrown.
277297

@@ -286,7 +306,8 @@ use GeoIp2\WebService\Client;
286306

287307
// This creates a Client object that can be reused across requests.
288308
// Replace "42" with your account ID and "license_key" with your license
289-
// key.
309+
// key. Set the "host" to "geolite.info" in the fourth argument options
310+
// array to use the GeoLite2 web service instead of GeoIP2 Precision.
290311
$client = new Client(42, 'abcdef123456');
291312

292313
// Replace "city" with the method corresponding to the web service that

src/WebService/Client.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ class Client implements ProviderInterface
5959
* @param array $locales list of locale codes to use in name property
6060
* from most preferred to least preferred
6161
* @param array $options array of options. Valid options include:
62-
* * `host` - The host to use when querying the web service.
62+
* * `host` - The host to use when querying the web service. To
63+
* query the GeoLite2 web service instead of GeoIP2 Precision,
64+
* set the host to `geolite.info`.
6365
* * `timeout` - Timeout in seconds.
6466
* * `connectTimeout` - Initial connection timeout in seconds.
6567
* * `proxy` - The HTTP proxy to use. May include a schema, port,
@@ -95,7 +97,7 @@ private function userAgent(): string
9597
}
9698

9799
/**
98-
* This method calls the GeoIP2 Precision: City service.
100+
* This method calls the City service.
99101
*
100102
* @param string $ipAddress IPv4 or IPv6 address as a string. If no
101103
* address is provided, the address that the web service is called
@@ -124,7 +126,7 @@ public function city(string $ipAddress = 'me'): \GeoIp2\Model\City
124126
}
125127

126128
/**
127-
* This method calls the GeoIP2 Precision: Country service.
129+
* This method calls the Country service.
128130
*
129131
* @param string $ipAddress IPv4 or IPv6 address as a string. If no
130132
* address is provided, the address that the web service is called
@@ -153,7 +155,8 @@ public function country(string $ipAddress = 'me'): \GeoIp2\Model\Country
153155
}
154156

155157
/**
156-
* This method calls the GeoIP2 Precision: Insights service.
158+
* This method calls the Insights service. Insights is only supported by GeoIP2
159+
* Precision. The GeoLite2 web service does not support it.
157160
*
158161
* @param string $ipAddress IPv4 or IPv6 address as a string. If no
159162
* address is provided, the address that the web service is called

0 commit comments

Comments
 (0)