diff --git a/src/GeoIP2/Webservice/Client.php b/src/GeoIP2/Webservice/Client.php index 5625de6..f6ec6fb 100644 --- a/src/GeoIP2/Webservice/Client.php +++ b/src/GeoIP2/Webservice/Client.php @@ -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'; + } } diff --git a/tests/GeoIP2/Test/Webservice/ClientTest.php b/tests/GeoIP2/Test/Webservice/ClientTest.php index b571e7d..c9b9f1b 100644 --- a/tests/GeoIP2/Test/Webservice/ClientTest.php +++ b/tests/GeoIP2/Test/Webservice/ClientTest.php @@ -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 );