This commit is contained in:
Edoardo Zuliani
2025-01-02 12:51:48 +01:00
parent 0f602b563b
commit c289ef2ef7
2 changed files with 17 additions and 12 deletions

View File

@@ -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;

View File

@@ -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);