Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
4ec525a313 | |||
6f776ffac1 | |||
a323cc38cb | |||
![]() |
a7f561bb64 | ||
![]() |
0f77785480 | ||
![]() |
a9e6ff4cfa | ||
![]() |
01f58d749b |
@ -1,6 +1,12 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
2.1.1 (2014-12-03)
|
||||
------------------
|
||||
|
||||
* The 2.1.0 Phar builds included a shebang line, causing issues when loading
|
||||
it as a library. This has been corrected. GitHub #33.
|
||||
|
||||
2.1.0 (2014-10-29)
|
||||
------------------
|
||||
|
||||
|
@ -114,7 +114,7 @@ print($record->location->longitude . "\n"); // -93.2323
|
||||
|
||||
```
|
||||
|
||||
### Anonymoous-IP Example ###
|
||||
### Anonymous IP Example ###
|
||||
|
||||
```php
|
||||
<?php
|
||||
@ -305,7 +305,7 @@ supported.
|
||||
|
||||
This library works and is tested with HHVM.
|
||||
|
||||
This library also relies on the [Guzzle HTTP client](http://guzzlephp.org/)
|
||||
This library also relies on the [Guzzle3 HTTP client](https://github.com/guzzle/guzzle3)
|
||||
and the [MaxMind DB Reader](https://github.com/maxmind/MaxMind-DB-Reader-php).
|
||||
|
||||
If you are using PHP 5.3 with an autoloader besides Composer, you must load
|
||||
@ -314,7 +314,7 @@ If you are using PHP 5.3 with an autoloader besides Composer, you must load
|
||||
## Contributing ##
|
||||
|
||||
Patches and pull requests are encouraged. All code should follow the
|
||||
PSR-2 style guidelines. Please include unit tests whenever possible.
|
||||
PSR-2 style guidelines. Please include unit tests whenever possible. You may obtain the test data for the maxmind-db folder by running `git submodule update --init --recursive` or adding `--recursive` to your initial clone, or from https://github.com/maxmind/MaxMind-DB
|
||||
|
||||
## Versioning ##
|
||||
|
||||
|
2
box.json
2
box.json
@ -29,8 +29,8 @@
|
||||
"in": "vendor"
|
||||
}
|
||||
],
|
||||
|
||||
"directories": ["compat", "src/"],
|
||||
"git-version": "git-version",
|
||||
"shebang": false,
|
||||
"stub": true
|
||||
}
|
||||
|
15
dev-bin/phar-test.php
Executable file
15
dev-bin/phar-test.php
Executable file
@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
require_once 'geoip2.phar';
|
||||
use GeoIp2\Database\Reader;
|
||||
|
||||
$reader = new Reader('maxmind-db/test-data/GeoIP2-City-Test.mmdb');
|
||||
|
||||
$record = $reader->city('81.2.69.160');
|
||||
|
||||
if ( $record->country->isoCode === 'GB' ) {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
print('Problem with Phar!');
|
||||
exit(1);
|
@ -26,11 +26,18 @@ php composer.phar self-update
|
||||
php composer.phar update --no-dev
|
||||
|
||||
if [ ! -f box.phar ]; then
|
||||
wget -O box.phar "https://github.com/kherge-archive/Box/releases/download/2.4.4/box-2.4.4.phar"
|
||||
wget -O box.phar "https://github.com/box-project/box2/releases/download/2.5.0/box-2.5.0.phar"
|
||||
fi
|
||||
|
||||
php box.phar build
|
||||
|
||||
PHAR_TEST=$(./dev-bin/phar-test.php)
|
||||
if [[ -n $PHAR_TEST ]]; then
|
||||
echo "Phar test outputed non-empty string: $PHAR_TEST"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Download test deps
|
||||
php composer.phar update
|
||||
|
||||
./vendor/bin/phpunit
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace GeoIp2\Model;
|
||||
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
|
@ -51,6 +51,8 @@ class Client implements ProviderInterface
|
||||
private $locales;
|
||||
private $host;
|
||||
private $guzzleClient;
|
||||
private $timeout;
|
||||
private $connectTimeout;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@ -62,13 +64,17 @@ class Client implements ProviderInterface
|
||||
* @param string $host Optional host parameter
|
||||
* @param object $guzzleClient Optional Guzzle client to use (to facilitate
|
||||
* unit testing).
|
||||
* @param string $timeout Total transaction timeout in seconds
|
||||
* @param string $connectTimeout Initial connection timeout in seconds
|
||||
*/
|
||||
public function __construct(
|
||||
$userId,
|
||||
$licenseKey,
|
||||
$locales = array('en'),
|
||||
$host = 'geoip.maxmind.com',
|
||||
$guzzleClient = null
|
||||
$guzzleClient = null,
|
||||
$timeout = null,
|
||||
$connectTimeout = null
|
||||
) {
|
||||
$this->userId = $userId;
|
||||
$this->licenseKey = $licenseKey;
|
||||
@ -76,6 +82,8 @@ class Client implements ProviderInterface
|
||||
$this->host = $host;
|
||||
// To enable unit testing
|
||||
$this->guzzleClient = $guzzleClient;
|
||||
$this->timeout = $timeout;
|
||||
$this->connectTimeout = $connectTimeout;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -180,7 +188,14 @@ class Client implements ProviderInterface
|
||||
|
||||
$client = $this->guzzleClient ?
|
||||
$this->guzzleClient : new GuzzleClient();
|
||||
$request = $client->get($uri, array('Accept' => 'application/json'));
|
||||
$options = array();
|
||||
if ($this->timeout !== null) {
|
||||
$options['timeout'] = $this->timeout;
|
||||
}
|
||||
if ($this->connectTimeout !== null) {
|
||||
$options['connect_timeout'] = $this->connectTimeout;
|
||||
}
|
||||
$request = $client->get($uri, array('Accept' => 'application/json'), $options);
|
||||
$request->setAuth($this->userId, $this->licenseKey);
|
||||
$this->setUserAgent($request);
|
||||
|
||||
|
@ -419,7 +419,9 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
||||
'abcdef123456',
|
||||
array('en'),
|
||||
'geoip.maxmind.com',
|
||||
$guzzleClient
|
||||
$guzzleClient,
|
||||
27,
|
||||
72
|
||||
);
|
||||
$client->country('1.2.3.4');
|
||||
|
||||
@ -446,7 +448,21 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertStringMatchesFormat(
|
||||
'GeoIP2 PHP API (Guzzle%s)',
|
||||
$request->getHeader('User-Agent') . '',
|
||||
'request sets Accept header to application/json'
|
||||
'request sets Accept header to GeoIP2 PHP API (Guzzle%s)'
|
||||
);
|
||||
|
||||
$curlOptions = $request->getCurlOptions();
|
||||
|
||||
$this->assertEquals(
|
||||
'27000',
|
||||
$curlOptions[CURLOPT_TIMEOUT_MS],
|
||||
'request sets Curl Option Timeout to 27 seconds'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'72000',
|
||||
$curlOptions[CURLOPT_CONNECTTIMEOUT_MS],
|
||||
'request sets Curl Option Connect Timeout to 72 seconds'
|
||||
);
|
||||
}
|
||||
|
||||
@ -464,6 +480,10 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
||||
$locales,
|
||||
'geoip.maxmind.com',
|
||||
$guzzleClient
|
||||
// intentionally not specifying the below, to ensure backwards compatibility
|
||||
//,
|
||||
// 1, // optional timeout
|
||||
// 1 // optional connect timeout
|
||||
);
|
||||
|
||||
return $client;
|
||||
|
Loading…
x
Reference in New Issue
Block a user