Added missing ability to set host
This commit is contained in:
parent
6fe69b6504
commit
ec116a2c29
|
@ -20,18 +20,20 @@ class Client
|
||||||
private $userId;
|
private $userId;
|
||||||
private $licenseKey;
|
private $licenseKey;
|
||||||
private $languages;
|
private $languages;
|
||||||
private $baseUri = 'https://geoip.maxmind.com/geoip/v2.0';
|
private $host;
|
||||||
private $guzzleClient;
|
private $guzzleClient;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
$userId,
|
$userId,
|
||||||
$licenseKey,
|
$licenseKey,
|
||||||
$languages = array('en'),
|
$languages = array('en'),
|
||||||
|
$host = 'geoip.maxmind.com',
|
||||||
$guzzleClient = null
|
$guzzleClient = null
|
||||||
) {
|
) {
|
||||||
$this->userId = $userId;
|
$this->userId = $userId;
|
||||||
$this->licenseKey = $licenseKey;
|
$this->licenseKey = $licenseKey;
|
||||||
$this->languages = $languages;
|
$this->languages = $languages;
|
||||||
|
$this->host = $host;
|
||||||
// To enable unit testing
|
// To enable unit testing
|
||||||
$this->guzzleClient = $guzzleClient;
|
$this->guzzleClient = $guzzleClient;
|
||||||
}
|
}
|
||||||
|
@ -56,9 +58,9 @@ class Client
|
||||||
return $this->responseFor('omni', 'Omni', $ipAddress);
|
return $this->responseFor('omni', 'Omni', $ipAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function responseFor($path, $class, $ipAddress)
|
private function responseFor($endpoint, $class, $ipAddress)
|
||||||
{
|
{
|
||||||
$uri = implode('/', array($this->baseUri, $path, $ipAddress));
|
$uri = implode('/', array($this->baseUri(), $endpoint, $ipAddress));
|
||||||
|
|
||||||
$client = $this->guzzleClient ?
|
$client = $this->guzzleClient ?
|
||||||
$this->guzzleClient : new GuzzleClient();
|
$this->guzzleClient : new GuzzleClient();
|
||||||
|
@ -177,4 +179,8 @@ class Client
|
||||||
$uri
|
$uri
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function baseUri() {
|
||||||
|
return 'https://' . $this->host . '/geoip/v2.0';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -273,6 +273,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
||||||
42,
|
42,
|
||||||
'abcdef123456',
|
'abcdef123456',
|
||||||
array('en'),
|
array('en'),
|
||||||
|
'geoip.maxmind.com',
|
||||||
$guzzleClient
|
$guzzleClient
|
||||||
);
|
);
|
||||||
$client->country('1.2.3.4');
|
$client->country('1.2.3.4');
|
||||||
|
@ -316,6 +317,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
||||||
42,
|
42,
|
||||||
'abcdef123456',
|
'abcdef123456',
|
||||||
$languages,
|
$languages,
|
||||||
|
'geoip.maxmind.com',
|
||||||
$guzzleClient
|
$guzzleClient
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user