From 26f414f290e1bf3f102cfa651583977bef50d8f0 Mon Sep 17 00:00:00 2001 From: Steven Wichers Date: Thu, 5 Dec 2019 13:10:05 -0800 Subject: [PATCH] Correct API version not being used for non-GET requests. (#23) --- src/Client.php | 13 ++++--------- tests/Unit/ClientTest.php | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/Client.php b/src/Client.php index 35d62b5..6476bbf 100644 --- a/src/Client.php +++ b/src/Client.php @@ -76,7 +76,7 @@ public function __construct(HttpClientInterface $httpClient, ActionManagerInterf */ public function apiDelete($method, array $data, int $api_version = NULL): ResponseInterface { - return $this->apiRequest('DELETE', $method, ['json' => $data]); + return $this->apiRequest('DELETE', $method, ['json' => $data], $api_version); } /** @@ -84,12 +84,7 @@ public function apiDelete($method, array $data, int $api_version = NULL): Respon */ public function apiGet($method, array $params = [], int $api_version = NULL): ResponseInterface { - return $this->apiRequest( - 'GET', - $method, - ['query' => $params], - $api_version - ); + return $this->apiRequest('GET', $method, ['query' => $params], $api_version); } /** @@ -97,7 +92,7 @@ public function apiGet($method, array $params = [], int $api_version = NULL): Re */ public function apiPost($method, array $data, int $api_version = NULL): ResponseInterface { - return $this->apiRequest('POST', $method, ['json' => $data]); + return $this->apiRequest('POST', $method, ['json' => $data], $api_version); } /** @@ -105,7 +100,7 @@ public function apiPost($method, array $data, int $api_version = NULL): Response */ public function apiPut($method, array $data, int $api_version = NULL): ResponseInterface { - return $this->apiRequest('PUT', $method, ['json' => $data]); + return $this->apiRequest('PUT', $method, ['json' => $data], $api_version); } /** diff --git a/tests/Unit/ClientTest.php b/tests/Unit/ClientTest.php index d548b07..ae6d9e4 100644 --- a/tests/Unit/ClientTest.php +++ b/tests/Unit/ClientTest.php @@ -375,6 +375,13 @@ public function testApiPost() { 'https://www.ligula-dapibus.acsitefactory.com/api/v1/Unit/Test', $resp->getOriginalResponse()->getInfo('url') ); + + $resp = $this->getClient()->apiPost('Unit/Test', [], 2); + $this->assertInstanceOf(ResponseInterface::class, $resp); + $this->assertEquals( + 'https://www.ligula-dapibus.acsitefactory.com/api/v2/Unit/Test', + $resp->getOriginalResponse()->getInfo('url') + ); } /** @@ -392,6 +399,13 @@ public function testApiDelete() { 'https://www.ligula-dapibus.acsitefactory.com/api/v1/Unit/Test', $resp->getOriginalResponse()->getInfo('url') ); + + $resp = $this->getClient()->apiDelete('Unit/Test', [], 2); + $this->assertInstanceOf(ResponseInterface::class, $resp); + $this->assertEquals( + 'https://www.ligula-dapibus.acsitefactory.com/api/v2/Unit/Test', + $resp->getOriginalResponse()->getInfo('url') + ); } /** @@ -409,6 +423,13 @@ public function testApiPut() { 'https://www.ligula-dapibus.acsitefactory.com/api/v1/Unit/Test', $resp->getOriginalResponse()->getInfo('url') ); + + $resp = $this->getClient()->apiPut('Unit/Test', [], 2); + $this->assertInstanceOf(ResponseInterface::class, $resp); + $this->assertEquals( + 'https://www.ligula-dapibus.acsitefactory.com/api/v2/Unit/Test', + $resp->getOriginalResponse()->getInfo('url') + ); } /**