Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions lib/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* @method Client sums()
* @method Client monitor()
* @method Client test()
* @method Client _version()
*
* Access settings
* @method Client access_settings()
Expand Down Expand Up @@ -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
Expand All @@ -664,4 +671,4 @@ public function __call($name, $args)

return $this->_($name);
}
}
}
11 changes: 10 additions & 1 deletion test/unit/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -256,4 +265,4 @@ private function callMethod($obj, $name, $args = [])
$method->setAccessible(true);
return $method->invokeArgs($obj, $args);
}
}
}