From c289ef2ef7af32c795eaf7bd6636e0b7fc938f10 Mon Sep 17 00:00:00 2001 From: Edoardo Zuliani Date: Thu, 2 Jan 2025 12:51:48 +0100 Subject: [PATCH 1/8] fix api --- src/Endpoints/RulesLists.php | 27 ++++++++++++++++----------- tests/Endpoints/RulesListsTest.php | 2 +- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/Endpoints/RulesLists.php b/src/Endpoints/RulesLists.php index 6ef83d1..3513256 100755 --- a/src/Endpoints/RulesLists.php +++ b/src/Endpoints/RulesLists.php @@ -18,15 +18,15 @@ class RulesLists implements API public function getLists(string $accountId) { - $response = $this->adapter->get('/accounts/' . $accountId . '/rules/lists'); + $response = $this->adapter->get('accounts/' . $accountId . '/rules/lists'); $this->body = json_decode($response->getBody()); - return (object)['result' => $this->body->result]; + return $this->body->result; } public function getListDetails(string $accountId, string $listId) { - $response = $this->adapter->get('/accounts/' . $accountId . '/rules/lists/' . $listId); + $response = $this->adapter->get('accounts/' . $accountId . '/rules/lists/' . $listId); $this->body = json_decode($response->getBody()); return $this->body->result; @@ -47,10 +47,10 @@ class RulesLists implements API $options['cursor'] = $cursor; } - $response = $this->adapter->get('/accounts/' . $accountId . '/rules/lists/' . $listId . '/items', $options); + $response = $this->adapter->get('accounts/' . $accountId . '/rules/lists/' . $listId . '/items', $options); $this->body = json_decode($response->getBody()); - return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info]; + return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info ?? null]; } public function createList(string $accountId, string $kind, string $name, string $description = '') @@ -64,7 +64,7 @@ class RulesLists implements API $options['description'] = $description; } - $response = $this->adapter->post('/accounts/' . $accountId . '/rules/lists', $options); + $response = $this->adapter->post('accounts/' . $accountId . '/rules/lists', $options); $this->body = json_decode($response->getBody()); return $this->body->result; @@ -74,19 +74,24 @@ class RulesLists implements API { $options = []; foreach ($ip as $ipAddress) { - $options['ip'] = $ipAddress; + $options[] = ['ip' => $ipAddress]; } - $response = $this->adapter->post('/accounts/' . $accountId . '/rules/lists/' . $listId . '/items', $options); + $response = $this->adapter->post('accounts/' . $accountId . '/rules/lists/' . $listId . '/items', $options); $this->body = json_decode($response->getBody()); return $this->body->result; } - public function deleteListItem(string $accountId, string $listId, string $item = '') + public function deleteListItem(string $accountId, string $listId, array $itemIds) { - $response = $this->adapter->delete('/accounts/' . $accountId . '/rules/lists/' . $listId . '/items' . ($item ? '/' . $item : '')); + $options = ['items' => []]; + foreach ($itemIds as $itemId) { + $options['items'][] = ['id' => $itemId]; + } + + $response = $this->adapter->delete('accounts/' . $accountId . '/rules/lists/' . $listId . '/items', $options); $this->body = json_decode($response->getBody()); return $this->body->result; @@ -94,7 +99,7 @@ class RulesLists implements API public function getOperationStatus(string $accountId, string $operationId) { - $response = $this->adapter->get('/accounts/' . $accountId . '/rules/lists/bulk_operations/' . $operationId); + $response = $this->adapter->get('accounts/' . $accountId . '/rules/lists/bulk_operations/' . $operationId); $this->body = json_decode($response->getBody()); return $this->body->result; diff --git a/tests/Endpoints/RulesListsTest.php b/tests/Endpoints/RulesListsTest.php index 34a0884..18a93fc 100755 --- a/tests/Endpoints/RulesListsTest.php +++ b/tests/Endpoints/RulesListsTest.php @@ -143,7 +143,7 @@ class RulesListsTest extends TestCase ); $rulesLists = new \Cloudflare\API\Endpoints\RulesLists($mock); - $result = $rulesLists->deleteListItem('01a7362d577a6c3019a474fd6f485823', '2c0fc9fa937b11eaa1b71c4d701ab86e'); + $result = $rulesLists->deleteListItem('01a7362d577a6c3019a474fd6f485823', '2c0fc9fa937b11eaa1b71c4d701ab86e', ['6as9450mma215q6so7p79dd981r4ee09']); $this->assertEquals('4da8780eeb215e6cb7f48dd981c4ea02', $result->operation_id); $this->assertEquals('4da8780eeb215e6cb7f48dd981c4ea02', $rulesLists->getBody()->result->operation_id); From 9a5995970b768bda3a99354c4beafa152d3b711f Mon Sep 17 00:00:00 2001 From: Edoardo Zuliani Date: Thu, 2 Jan 2025 14:01:47 +0100 Subject: [PATCH 2/8] fix api --- tests/Endpoints/RulesListsTest.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/Endpoints/RulesListsTest.php b/tests/Endpoints/RulesListsTest.php index 18a93fc..29f93ed 100755 --- a/tests/Endpoints/RulesListsTest.php +++ b/tests/Endpoints/RulesListsTest.php @@ -18,7 +18,7 @@ class RulesListsTest extends TestCase $mock->expects($this->once()) ->method('post') ->with( - $this->equalTo('/accounts/01a7362d577a6c3019a474fd6f485823/rules/lists'), + $this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/rules/lists'), $this->equalTo([ 'kind' => 'ip', 'name' => 'ip-allowlist', @@ -45,7 +45,7 @@ class RulesListsTest extends TestCase $mock->expects($this->once()) ->method('get') ->with( - $this->equalTo('/accounts/01a7362d577a6c3019a474fd6f485823/rules/lists') + $this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/rules/lists') ); $rulesLists = new \Cloudflare\API\Endpoints\RulesLists($mock); @@ -68,7 +68,7 @@ class RulesListsTest extends TestCase $mock->expects($this->once()) ->method('get') ->with( - $this->equalTo('/accounts/01a7362d577a6c3019a474fd6f485823/rules/lists/2c0fc9fa937b11eaa1b71c4d701ab86e') + $this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/rules/lists/2c0fc9fa937b11eaa1b71c4d701ab86e') ); $rulesLists = new \Cloudflare\API\Endpoints\RulesLists($mock); @@ -91,7 +91,7 @@ class RulesListsTest extends TestCase $mock->expects($this->once()) ->method('get') ->with( - $this->equalTo('/accounts/01a7362d577a6c3019a474fd6f485823/rules/lists/2c0fc9fa937b11eaa1b71c4d701ab86e/items'), + $this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/rules/lists/2c0fc9fa937b11eaa1b71c4d701ab86e/items'), $this->equalTo([ 'per_page' => 20, ]) @@ -117,7 +117,7 @@ class RulesListsTest extends TestCase $mock->expects($this->once()) ->method('post') ->with( - $this->equalTo('/accounts/01a7362d577a6c3019a474fd6f485823/rules/lists/2c0fc9fa937b11eaa1b71c4d701ab86e/items') + $this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/rules/lists/2c0fc9fa937b11eaa1b71c4d701ab86e/items') ); $rulesLists = new \Cloudflare\API\Endpoints\RulesLists($mock); @@ -139,7 +139,7 @@ class RulesListsTest extends TestCase $mock->expects($this->once()) ->method('delete') ->with( - $this->equalTo('/accounts/01a7362d577a6c3019a474fd6f485823/rules/lists/2c0fc9fa937b11eaa1b71c4d701ab86e/items') + $this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/rules/lists/2c0fc9fa937b11eaa1b71c4d701ab86e/items') ); $rulesLists = new \Cloudflare\API\Endpoints\RulesLists($mock); @@ -159,7 +159,7 @@ class RulesListsTest extends TestCase $mock->expects($this->once()) ->method('get') ->with( - $this->equalTo('/accounts/01a7362d577a6c3019a474fd6f485823/rules/lists/bulk_operations/4da8780eeb215e6cb7f48dd981c4ea02') + $this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/rules/lists/bulk_operations/4da8780eeb215e6cb7f48dd981c4ea02') ); $rulesLists = new \Cloudflare\API\Endpoints\RulesLists($mock); From 66e2ba45cac41f9099180c281e1767ebae4a226f Mon Sep 17 00:00:00 2001 From: Edoardo Zuliani Date: Thu, 2 Jan 2025 14:04:52 +0100 Subject: [PATCH 3/8] fix api --- tests/Endpoints/RulesListsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Endpoints/RulesListsTest.php b/tests/Endpoints/RulesListsTest.php index 29f93ed..5496b4b 100755 --- a/tests/Endpoints/RulesListsTest.php +++ b/tests/Endpoints/RulesListsTest.php @@ -52,7 +52,7 @@ class RulesListsTest extends TestCase $result = $rulesLists->getLists('01a7362d577a6c3019a474fd6f485823'); $this->assertObjectHasAttribute('result', $result); - $this->assertEquals('2c0fc9fa937b11eaa1b71c4d701ab86e', $result->result[0]->id); + $this->assertEquals('2c0fc9fa937b11eaa1b71c4d701ab86e', $result[0]->id); $this->assertEquals('2c0fc9fa937b11eaa1b71c4d701ab86e', $rulesLists->getBody()->result[0]->id); } From 369160682d7eaff0f8edf0701a069c3240dd9ad1 Mon Sep 17 00:00:00 2001 From: Edoardo Zuliani Date: Thu, 2 Jan 2025 14:07:00 +0100 Subject: [PATCH 4/8] fix api --- tests/Endpoints/RulesListsTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/Endpoints/RulesListsTest.php b/tests/Endpoints/RulesListsTest.php index 5496b4b..1070534 100755 --- a/tests/Endpoints/RulesListsTest.php +++ b/tests/Endpoints/RulesListsTest.php @@ -51,9 +51,7 @@ class RulesListsTest extends TestCase $rulesLists = new \Cloudflare\API\Endpoints\RulesLists($mock); $result = $rulesLists->getLists('01a7362d577a6c3019a474fd6f485823'); - $this->assertObjectHasAttribute('result', $result); $this->assertEquals('2c0fc9fa937b11eaa1b71c4d701ab86e', $result[0]->id); - $this->assertEquals('2c0fc9fa937b11eaa1b71c4d701ab86e', $rulesLists->getBody()->result[0]->id); } From 10e3e120e45679b7b645a2e100ca13cea3ec11db Mon Sep 17 00:00:00 2001 From: Edoardo Zuliani Date: Thu, 2 Jan 2025 14:54:11 +0100 Subject: [PATCH 5/8] api eliminazione lista --- src/Endpoints/RulesLists.php | 9 ++++++++ tests/Endpoints/RulesListsTest.php | 21 +++++++++++++++++++ tests/Fixtures/Endpoints/deleteRulesList.json | 18 ++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100755 tests/Fixtures/Endpoints/deleteRulesList.json diff --git a/src/Endpoints/RulesLists.php b/src/Endpoints/RulesLists.php index 3513256..b019b95 100755 --- a/src/Endpoints/RulesLists.php +++ b/src/Endpoints/RulesLists.php @@ -70,6 +70,15 @@ class RulesLists implements API return $this->body->result; } + public function deleteList(string $accountId, string $listId) + { + + $response = $this->adapter->delete('accounts/' . $accountId . '/rules/lists/' . $listId); + $this->body = json_decode($response->getBody()); + + return $this->body->result; + } + public function createListItem(string $accountId, string $listId, array $ip) { $options = []; diff --git a/tests/Endpoints/RulesListsTest.php b/tests/Endpoints/RulesListsTest.php index 1070534..a4d08b8 100755 --- a/tests/Endpoints/RulesListsTest.php +++ b/tests/Endpoints/RulesListsTest.php @@ -35,6 +35,27 @@ class RulesListsTest extends TestCase $this->assertEquals('2c0fc9fa937b11eaa1b71c4d701ab86e', $rulesLists->getBody()->result->id); } + public function testDeleteRulesList() + { + + $response = $this->getPsr7JsonResponseForFixture('Endpoints/deleteRulesList.json'); + + $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock(); + $mock->method('post')->willReturn($response); + + $mock->expects($this->once()) + ->method('delete') + ->with( + $this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/rules/lists/2c0fc9fa937b11eaa1b71c4d701ab86e') + ); + + $rulesLists = new \Cloudflare\API\Endpoints\RulesLists($mock); + $result = $rulesLists->deleteList('01a7362d577a6c3019a474fd6f485823', '2c0fc9fa937b11eaa1b71c4d701ab86e'); + + $this->assertEquals(true, $result->success); + $this->assertEquals(true, $rulesLists->getBody()->result->success); + } + public function testGetRulesLists() { $response = $this->getPsr7JsonResponseForFixture('Endpoints/listRulesLists.json'); diff --git a/tests/Fixtures/Endpoints/deleteRulesList.json b/tests/Fixtures/Endpoints/deleteRulesList.json new file mode 100755 index 0000000..1683eb2 --- /dev/null +++ b/tests/Fixtures/Endpoints/deleteRulesList.json @@ -0,0 +1,18 @@ +{ + "errors": [ + { + "code": 1000, + "message": "message" + } + ], + "messages": [ + { + "code": 1000, + "message": "message" + } + ], + "result": { + "id": "34b12448945f11eaa1b71c4d701ab86e" + }, + "success": true +} \ No newline at end of file From 7a839dfc2a68fa97d01c27c809ae27f49c14307f Mon Sep 17 00:00:00 2001 From: Edoardo Zuliani Date: Thu, 2 Jan 2025 14:57:34 +0100 Subject: [PATCH 6/8] api eliminazione lista --- src/Endpoints/RulesLists.php | 2 +- tests/Endpoints/RulesListsTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Endpoints/RulesLists.php b/src/Endpoints/RulesLists.php index b019b95..68dbb2f 100755 --- a/src/Endpoints/RulesLists.php +++ b/src/Endpoints/RulesLists.php @@ -76,7 +76,7 @@ class RulesLists implements API $response = $this->adapter->delete('accounts/' . $accountId . '/rules/lists/' . $listId); $this->body = json_decode($response->getBody()); - return $this->body->result; + return $this->body; } public function createListItem(string $accountId, string $listId, array $ip) diff --git a/tests/Endpoints/RulesListsTest.php b/tests/Endpoints/RulesListsTest.php index a4d08b8..54d86e5 100755 --- a/tests/Endpoints/RulesListsTest.php +++ b/tests/Endpoints/RulesListsTest.php @@ -53,7 +53,7 @@ class RulesListsTest extends TestCase $result = $rulesLists->deleteList('01a7362d577a6c3019a474fd6f485823', '2c0fc9fa937b11eaa1b71c4d701ab86e'); $this->assertEquals(true, $result->success); - $this->assertEquals(true, $rulesLists->getBody()->result->success); + $this->assertEquals(true, $rulesLists->getBody()->success); } public function testGetRulesLists() From 04e2032e9f1ede00fd65b46e441d7bc1075660ed Mon Sep 17 00:00:00 2001 From: Edoardo Zuliani Date: Thu, 2 Jan 2025 15:05:36 +0100 Subject: [PATCH 7/8] fix api eliminazione lista --- src/Endpoints/RulesLists.php | 2 +- tests/Endpoints/RulesListsTest.php | 4 ++-- tests/Fixtures/Endpoints/deleteRulesList.json | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Endpoints/RulesLists.php b/src/Endpoints/RulesLists.php index 68dbb2f..b019b95 100755 --- a/src/Endpoints/RulesLists.php +++ b/src/Endpoints/RulesLists.php @@ -76,7 +76,7 @@ class RulesLists implements API $response = $this->adapter->delete('accounts/' . $accountId . '/rules/lists/' . $listId); $this->body = json_decode($response->getBody()); - return $this->body; + return $this->body->result; } public function createListItem(string $accountId, string $listId, array $ip) diff --git a/tests/Endpoints/RulesListsTest.php b/tests/Endpoints/RulesListsTest.php index 54d86e5..bd6f74d 100755 --- a/tests/Endpoints/RulesListsTest.php +++ b/tests/Endpoints/RulesListsTest.php @@ -52,8 +52,8 @@ class RulesListsTest extends TestCase $rulesLists = new \Cloudflare\API\Endpoints\RulesLists($mock); $result = $rulesLists->deleteList('01a7362d577a6c3019a474fd6f485823', '2c0fc9fa937b11eaa1b71c4d701ab86e'); - $this->assertEquals(true, $result->success); - $this->assertEquals(true, $rulesLists->getBody()->success); + $this->assertEquals('2c0fc9fa937b11eaa1b71c4d701ab86e', $result->id); + $this->assertEquals('2c0fc9fa937b11eaa1b71c4d701ab86e', $rulesLists->getBody()->result->id); } public function testGetRulesLists() diff --git a/tests/Fixtures/Endpoints/deleteRulesList.json b/tests/Fixtures/Endpoints/deleteRulesList.json index 1683eb2..cf72665 100755 --- a/tests/Fixtures/Endpoints/deleteRulesList.json +++ b/tests/Fixtures/Endpoints/deleteRulesList.json @@ -12,7 +12,7 @@ } ], "result": { - "id": "34b12448945f11eaa1b71c4d701ab86e" + "id": "2c0fc9fa937b11eaa1b71c4d701ab86e" }, "success": true } \ No newline at end of file From b2187e7b5202e465a236ca60a12088fcfa5049a6 Mon Sep 17 00:00:00 2001 From: Edoardo Zuliani Date: Thu, 2 Jan 2025 15:42:37 +0100 Subject: [PATCH 8/8] fix test --- tests/Endpoints/RulesListsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Endpoints/RulesListsTest.php b/tests/Endpoints/RulesListsTest.php index bd6f74d..74755d6 100755 --- a/tests/Endpoints/RulesListsTest.php +++ b/tests/Endpoints/RulesListsTest.php @@ -41,7 +41,7 @@ class RulesListsTest extends TestCase $response = $this->getPsr7JsonResponseForFixture('Endpoints/deleteRulesList.json'); $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock(); - $mock->method('post')->willReturn($response); + $mock->method('delete')->willReturn($response); $mock->expects($this->once()) ->method('delete')