Skip to content

Commit

Permalink
fix api
Browse files Browse the repository at this point in the history
  • Loading branch information
Edo-1234 committed Jan 2, 2025
1 parent 0f602b5 commit c289ef2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
27 changes: 16 additions & 11 deletions src/Endpoints/RulesLists.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ public function __construct(Adapter $adapter)

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;
Expand All @@ -47,10 +47,10 @@ public function getListItems(string $accountId, string $listId, string $search =
$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 = '')
Expand All @@ -64,7 +64,7 @@ public function createList(string $accountId, string $kind, string $name, string
$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;
Expand All @@ -74,27 +74,32 @@ public function createListItem(string $accountId, string $listId, array $ip)
{
$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;
}

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;
Expand Down
2 changes: 1 addition & 1 deletion tests/Endpoints/RulesListsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function testDeleteRulesListItem() {
);

$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);
Expand Down

0 comments on commit c289ef2

Please sign in to comment.