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