Added missing ability to set host

This commit is contained in:
Gregory Oschwald 2013-05-09 15:22:11 -07:00
parent 6fe69b6504
commit ec116a2c29
2 changed files with 11 additions and 3 deletions

View File

@ -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';
}
}

View File

@ -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
);