diff --git a/lib/Client.php b/lib/Client.php index b6bcd4a..ecb03d5 100644 --- a/lib/Client.php +++ b/lib/Client.php @@ -32,6 +32,7 @@ * @method Client sums() * @method Client monitor() * @method Client test() + * @method Client _version() * * Access settings * @method Client access_settings() @@ -633,23 +634,29 @@ public function __call($name, $args) { $name = mb_strtolower($name); + // set the API version if ($name === 'version') { $this->version = $args[0]; return $this->_(); } + // set the endpoint version (e.g. client.name.name._version("2.0")) + if ($name === '_version') { + return $this->_($version = $args[0]); + } + // send all saved requests if (($name === 'send') && $this->isConcurrentRequest) { return $this->makeAllRequests(); } if (\in_array($name, $this->methods, true)) { - $body = isset($args[0]) ? $args[0] : null; - $queryParams = isset($args[1]) ? $args[1] : null; - $url = $this->buildUrl($queryParams); - $headers = isset($args[2]) ? $args[2] : null; - $retryOnLimit = isset($args[3]) ? $args[3] : $this->retryOnLimit; + $body = $args[0] ?? null; + $queryParams = $args[1] ?? null; + $url = $this->buildUrl($queryParams); + $headers = $args[2] ?? null; + $retryOnLimit = $args[3] ?? $this->retryOnLimit; if ($this->isConcurrentRequest) { // save request to be sent later @@ -664,4 +671,4 @@ public function __call($name, $args) return $this->_($name); } -} +} \ No newline at end of file diff --git a/test/unit/ClientTest.php b/test/unit/ClientTest.php index 55f6c10..6308dcc 100644 --- a/test/unit/ClientTest.php +++ b/test/unit/ClientTest.php @@ -70,6 +70,15 @@ public function test__call() $this->assertEquals(['path_to_endpoint', 'one_more_segment'], $client->getPath()); } + public function test__callWithEndpointVersion() + { + $endpoint_version = '2.0'; + $object_id = '00000000-0000-0000-0000-000000000000'; + $response = $this->client->segments()->_version($endpoint_version)->_($object_id)->patch(); + + $this->assertEquals("https://localhost:4010/v3/segments/$endpoint_version/$object_id", $response->url); + } + public function testGetHost() { $client = new Client('https://localhost:4010'); @@ -256,4 +265,4 @@ private function callMethod($obj, $name, $args = []) $method->setAccessible(true); return $method->invokeArgs($obj, $args); } -} +} \ No newline at end of file