20 Commits

Author SHA1 Message Date
f4b9092175 Update composer.json 2025-07-25 19:13:35 +07:00
SVDIGITAL
7e89626b59 Merge pull request #3 from Edo-1234/rule-lists-implementation
fix api
2025-02-24 09:53:57 +01:00
Edoardo Zuliani
b2187e7b52 fix test 2025-01-02 15:42:37 +01:00
Edoardo Zuliani
04e2032e9f fix api eliminazione lista 2025-01-02 15:05:36 +01:00
Edoardo Zuliani
7a839dfc2a api eliminazione lista 2025-01-02 14:57:34 +01:00
Edoardo Zuliani
10e3e120e4 api eliminazione lista 2025-01-02 14:54:11 +01:00
Edoardo Zuliani
369160682d fix api 2025-01-02 14:07:00 +01:00
Edoardo Zuliani
66e2ba45ca fix api 2025-01-02 14:04:52 +01:00
Edoardo Zuliani
9a5995970b fix api 2025-01-02 14:01:47 +01:00
Edoardo Zuliani
c289ef2ef7 fix api 2025-01-02 12:51:48 +01:00
SVDIGITAL
1c97befdd8 Merge pull request #2 from Edo-1234/rule-lists-implementation
Implementazione api relative alle rule lists
2024-12-31 10:29:22 +01:00
Edoardo Zuliani
0f602b563b modifiche 2024-12-27 18:09:26 +01:00
SVDIGITAL
aa10bcba3c Merge pull request #1 from shellrent/feature/merge-upstream
Merge cloudflare-php upstream
2022-01-05 15:02:44 +01:00
Joshua Chapman
6ea062af19 Merge remote-tracking branch 'upstream/master' into feature/merge-upstream 2021-11-10 16:21:48 +01:00
Phil Young
fdfc656aa8 Add Account Role Listings (#198)
I want to list the roles availablew in an account so I can add a member
to the account
2021-10-13 14:40:33 +11:00
Phil Young
5024c2ab53 Add Zone Subscription Creation (#196)
Consuming the tenant API requires this as a part of the provisioning
2021-10-13 14:39:47 +11:00
Phil Young
12ac2bbd76 Add Account Id To Zone Creation (#195) 2021-10-13 14:31:32 +11:00
Phil Young
99d8cfb71c Add Account Member Listing (#194) 2021-10-11 11:42:54 +11:00
Phil Young
bf796b9ec8 Add Account Member Creation (#192)
We can now create account members threough the SDK
2021-10-01 10:19:15 +10:00
Phil Young
7f72427fa1 Add Account Creation (#191)
This is used on the tenant API but is currently undocumented on the main
documentation
2021-10-01 10:16:27 +10:00
31 changed files with 1313 additions and 83 deletions

View File

@@ -1,11 +1,11 @@
{
"name": "shellrent/cloudflare-php",
"name": "yuemi/cloudflare-php",
"description": "PHP binding for v4 of the Cloudflare Client API.",
"type": "library",
"require": {
"guzzlehttp/guzzle": "~6.0",
"guzzlehttp/guzzle": "^7.0.1",
"php": ">=7.2.5",
"psr/http-message": "~1.0",
"psr/http-message": "^1.0 || ^2.0",
"ext-json": "*"
},
"require-dev": {

View File

@@ -0,0 +1,50 @@
<?php
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Traits\BodyAccessorTrait;
class AccountMembers implements API
{
use BodyAccessorTrait;
/**
* @var Adapter
*/
private $adapter;
public function __construct(Adapter $adapter)
{
$this->adapter = $adapter;
}
public function addAccountMember(string $accountId, string $email, array $roles): \stdClass
{
$options = [
'email' => $email,
'roles' => $roles,
];
$account = $this->adapter->post('accounts/' . $accountId . '/members', $options);
$this->body = json_decode($account->getBody());
return $this->body->result;
}
public function listAccountMembers(string $accountId, int $page = 1, int $perPage = 20): \stdClass
{
$query = [
'page' => $page,
'per_page' => $perPage,
];
$zone = $this->adapter->get('accounts/' . $accountId . '/members', $query);
$this->body = json_decode($zone->getBody());
return (object)[
'result' => $this->body->result,
'result_info' => $this->body->result_info,
];
}
}

View File

@@ -0,0 +1,33 @@
<?php
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Traits\BodyAccessorTrait;
use stdClass;
class AccountRoles implements API
{
use BodyAccessorTrait;
/**
* @var Adapter
*/
private $adapter;
public function __construct(Adapter $adapter)
{
$this->adapter = $adapter;
}
public function listAccountRoles(string $accountId): stdClass
{
$roles = $this->adapter->get('accounts/' . $accountId . '/roles');
$this->body = json_decode($roles->getBody());
return (object)[
'result' => $this->body->result,
'result_info' => $this->body->result_info,
];
}
}

View File

@@ -21,6 +21,19 @@ class Accounts implements API
$this->adapter = $adapter;
}
public function addAccount(string $name, string $type = 'standard'): \stdClass
{
$options = [
'name' => $name,
'type' => $type,
];
$account = $this->adapter->post('accounts', $options);
$this->body = json_decode($account->getBody());
return $this->body->result;
}
public function listAccounts(
int $page = 1,
int $perPage = 20,

117
src/Endpoints/RulesLists.php Executable file
View File

@@ -0,0 +1,117 @@
<?php
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Traits\BodyAccessorTrait;
class RulesLists implements API
{
use BodyAccessorTrait;
private $adapter;
public function __construct(Adapter $adapter)
{
$this->adapter = $adapter;
}
public function getLists(string $accountId)
{
$response = $this->adapter->get('accounts/' . $accountId . '/rules/lists');
$this->body = json_decode($response->getBody());
return $this->body->result;
}
public function getListDetails(string $accountId, string $listId)
{
$response = $this->adapter->get('accounts/' . $accountId . '/rules/lists/' . $listId);
$this->body = json_decode($response->getBody());
return $this->body->result;
}
public function getListItems(string $accountId, string $listId, string $search = '', int $itemsPerPage = 20, string $cursor = '')
{
$options = [
'per_page' => $itemsPerPage,
];
if ($search) {
$options['search'] = $search;
}
if ($cursor) {
$options['cursor'] = $cursor;
}
$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 ?? null];
}
public function createList(string $accountId, string $kind, string $name, string $description = '')
{
$options = [
'kind' => $kind,
'name' => $name,
];
if ($description) {
$options['description'] = $description;
}
$response = $this->adapter->post('accounts/' . $accountId . '/rules/lists', $options);
$this->body = json_decode($response->getBody());
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 = [];
foreach ($ip as $ipAddress) {
$options[] = ['ip' => $ipAddress];
}
$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, array $itemIds)
{
$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);
$this->body = json_decode($response->getBody());
return $this->body->result;
}
}

View File

@@ -0,0 +1,51 @@
<?php
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Traits\BodyAccessorTrait;
use stdClass;
class ZoneSubscriptions implements API
{
use BodyAccessorTrait;
/**
* @var Adapter
*/
private $adapter;
public function __construct(Adapter $adapter)
{
$this->adapter = $adapter;
}
public function listZoneSubscriptions(string $zoneId): \stdClass
{
$user = $this->adapter->get('zones/' . $zoneId . '/subscriptions');
$this->body = json_decode($user->getBody());
return (object)[
'result' => $this->body->result,
];
}
public function addZoneSubscription(string $zoneId, string $ratePlanId = ''): stdClass
{
$options = [];
if (empty($ratePlanId) === false) {
$options['rate_plan'] = [
'id' => $ratePlanId,
];
}
$existingSubscription = $this->listZoneSubscriptions($zoneId);
$method = empty($existingSubscription->result) ? 'post' : 'put';
$subscription = $this->adapter->{$method}('zones/' . $zoneId . '/subscription', $options);
$this->body = json_decode($subscription->getBody());
return $this->body->result;
}
}

View File

@@ -27,18 +27,20 @@ class Zones implements API
*
* @param string $name
* @param bool $jumpStart
* @param string $organizationID
* @param string $accountId
* @return \stdClass
*/
public function addZone(string $name, bool $jumpStart = false, string $organizationID = ''): \stdClass
public function addZone(string $name, bool $jumpStart = false, string $accountId = ''): \stdClass
{
$options = [
'name' => $name,
'jump_start' => $jumpStart
];
if (!empty($organizationID)) {
$options['organization'] = ['id' => $organizationID];
if (!empty($accountId)) {
$options['account'] = [
'id' => $accountId,
];
}
$user = $this->adapter->post('zones', $options);

View File

@@ -0,0 +1,59 @@
<?php
use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Endpoints\AccountMembers;
class AccountMembersTest extends TestCase
{
public function testAddAccountMember()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createAccountMember.json');
$mock = $this->getMockBuilder(Adapter::class)->getMock();
$mock->method('post')->willReturn($response);
$mock->expects($this->once())
->method('post')
->with(
$this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/members'),
$this->equalTo([
'email' => 'user@example.com',
'roles' => [
'3536bcfad5faccb999b47003c79917fb',
],
])
);
$accountMembers = new AccountMembers($mock);
$accountMembers->addAccountMember('01a7362d577a6c3019a474fd6f485823', 'user@example.com', ['3536bcfad5faccb999b47003c79917fb']);
$this->assertEquals('4536bcfad5faccb111b47003c79917fa', $accountMembers->getBody()->result->id);
}
public function testListAccountMembers()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listAccountMembers.json');
$mock = $this->getMockBuilder(Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('accounts/023e105f4ecef8ad9ca31a8372d0c353/members'),
$this->equalTo([
'page' => 1,
'per_page' => 20,
])
);
$accountMembers = new AccountMembers($mock);
$result = $accountMembers->listAccountMembers('023e105f4ecef8ad9ca31a8372d0c353', 1, 20);
$this->assertObjectHasAttribute('result', $result);
$this->assertEquals('4536bcfad5faccb111b47003c79917fa', $result->result[0]->id);
$this->assertEquals(1, $result->result_info->count);
$this->assertEquals('4536bcfad5faccb111b47003c79917fa', $accountMembers->getBody()->result[0]->id);
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace Endpoints;
use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Endpoints\AccountRoles;
use TestCase;
class AccountRolesTest extends TestCase
{
public function testListAccountRoles()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listAccountRoles.json');
$adapter = $this->getMockBuilder(Adapter::class)->getMock();
$adapter->method('get')->willReturn($response);
$adapter->expects($this->once())
->method('get')
->with($this->equalTo('accounts/023e105f4ecef8ad9ca31a8372d0c353/roles'));
$roles = new AccountRoles($adapter);
$result = $roles->listAccountRoles('023e105f4ecef8ad9ca31a8372d0c353');
$this->assertObjectHasAttribute('result', $result);
$this->assertObjectHasAttribute('result_info', $result);
$this->assertEquals('3536bcfad5faccb999b47003c79917fb', $result->result[0]->id);
$this->assertEquals(1, $result->result_info->page);
$this->assertEquals('3536bcfad5faccb999b47003c79917fb', $roles->getBody()->result[0]->id);
}
}

View File

@@ -1,4 +1,7 @@
<?php
use Cloudflare\API\Endpoints\Accounts;
/**
* User: kanasite
* Date: 01/28/2019
@@ -24,7 +27,7 @@ class AccountsTest extends TestCase
])
);
$accounts = new \Cloudflare\API\Endpoints\Accounts($mock);
$accounts = new Accounts($mock);
$result = $accounts->listAccounts(1, 20, 'desc');
$this->assertObjectHasAttribute('result', $result);
@@ -34,4 +37,50 @@ class AccountsTest extends TestCase
$this->assertEquals(1, $result->result_info->page);
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $accounts->getBody()->result[0]->id);
}
public function testAddAccountWithDefaultType()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createStandardAccount.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('post')->willReturn($response);
$mock->expects($this->once())
->method('post')
->with(
$this->equalTo('accounts'),
$this->equalTo([
'name' => 'Foo Bar',
'type' => 'standard',
])
);
$accounts = new Accounts($mock);
$accounts->addAccount('Foo Bar');
$this->assertEquals('2bab6ace8c72ed3f09b9eca6db1396bb', $accounts->getBody()->result->id);
}
public function testAddAccountWithCustomType()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createEnterpriseAccount.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('post')->willReturn($response);
$mock->expects($this->once())
->method('post')
->with(
$this->equalTo('accounts'),
$this->equalTo([
'name' => 'Foo Bar',
'type' => 'enterprise',
])
);
$accounts = new Accounts($mock);
$accounts->addAccount('Foo Bar', 'enterprise');
$this->assertEquals('2bab6ace8c72ed3f09b9eca6db1396bb', $accounts->getBody()->result->id);
}
}

View File

@@ -0,0 +1,191 @@
<?php
namespace Endpoints;
use TestCase;
class RulesListsTest extends TestCase
{
public function testCreateRulesList()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createRulesList.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('post')->willReturn($response);
$mock->expects($this->once())
->method('post')
->with(
$this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/rules/lists'),
$this->equalTo([
'kind' => 'ip',
'name' => 'ip-allowlist',
])
);
$rulesLists = new \Cloudflare\API\Endpoints\RulesLists($mock);
$result = $rulesLists->createList('01a7362d577a6c3019a474fd6f485823', 'ip', 'ip-allowlist');
$this->assertEquals('2c0fc9fa937b11eaa1b71c4d701ab86e', $result->id);
$this->assertEquals('ip', $result->kind);
$this->assertEquals('ip-allowlist', $result->name);
$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('delete')->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('2c0fc9fa937b11eaa1b71c4d701ab86e', $result->id);
$this->assertEquals('2c0fc9fa937b11eaa1b71c4d701ab86e', $rulesLists->getBody()->result->id);
}
public function testGetRulesLists()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listRulesLists.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/rules/lists')
);
$rulesLists = new \Cloudflare\API\Endpoints\RulesLists($mock);
$result = $rulesLists->getLists('01a7362d577a6c3019a474fd6f485823');
$this->assertEquals('2c0fc9fa937b11eaa1b71c4d701ab86e', $result[0]->id);
$this->assertEquals('2c0fc9fa937b11eaa1b71c4d701ab86e', $rulesLists->getBody()->result[0]->id);
}
public function testGetRulesListDetails()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getRulesListDetails.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/rules/lists/2c0fc9fa937b11eaa1b71c4d701ab86e')
);
$rulesLists = new \Cloudflare\API\Endpoints\RulesLists($mock);
$result = $rulesLists->getListDetails('01a7362d577a6c3019a474fd6f485823', '2c0fc9fa937b11eaa1b71c4d701ab86e');
$this->assertEquals('2c0fc9fa937b11eaa1b71c4d701ab86e', $result->id);
$this->assertEquals('ip', $result->kind);
$this->assertEquals('2c0fc9fa937b11eaa1b71c4d701ab86e', $rulesLists->getBody()->result->id);
}
public function testGetRulesListItems()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getRulesListItems.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/rules/lists/2c0fc9fa937b11eaa1b71c4d701ab86e/items'),
$this->equalTo([
'per_page' => 20,
])
);
$rulesLists = new \Cloudflare\API\Endpoints\RulesLists($mock);
$result = $rulesLists->getListItems('01a7362d577a6c3019a474fd6f485823', '2c0fc9fa937b11eaa1b71c4d701ab86e');
$this->assertObjectHasAttribute('result', $result);
$this->assertObjectHasAttribute('result_info', $result);
$this->assertEquals('10.0.0.1', $result->result[0]);
$this->assertEquals('10.0.0.1', $rulesLists->getBody()->result[0]);
}
public function testCreateRulesListItem() {
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createRulesListItem.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('post')->willReturn($response);
$mock->expects($this->once())
->method('post')
->with(
$this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/rules/lists/2c0fc9fa937b11eaa1b71c4d701ab86e/items')
);
$rulesLists = new \Cloudflare\API\Endpoints\RulesLists($mock);
$result = $rulesLists->createListItem('01a7362d577a6c3019a474fd6f485823', '2c0fc9fa937b11eaa1b71c4d701ab86e', [
'10.0.0.1'
]);
$this->assertEquals('4da8780eeb215e6cb7f48dd981c4ea02', $result->operation_id);
$this->assertEquals('4da8780eeb215e6cb7f48dd981c4ea02', $rulesLists->getBody()->result->operation_id);
}
public function testDeleteRulesListItem() {
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deleteRulesListItem.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('delete')->willReturn($response);
$mock->expects($this->once())
->method('delete')
->with(
$this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/rules/lists/2c0fc9fa937b11eaa1b71c4d701ab86e/items')
);
$rulesLists = new \Cloudflare\API\Endpoints\RulesLists($mock);
$result = $rulesLists->deleteListItem('01a7362d577a6c3019a474fd6f485823', '2c0fc9fa937b11eaa1b71c4d701ab86e', ['6as9450mma215q6so7p79dd981r4ee09']);
$this->assertEquals('4da8780eeb215e6cb7f48dd981c4ea02', $result->operation_id);
$this->assertEquals('4da8780eeb215e6cb7f48dd981c4ea02', $rulesLists->getBody()->result->operation_id);
}
public function testGetOperationStatus() {
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getOperationStatus.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/rules/lists/bulk_operations/4da8780eeb215e6cb7f48dd981c4ea02')
);
$rulesLists = new \Cloudflare\API\Endpoints\RulesLists($mock);
$result = $rulesLists->getOperationStatus('01a7362d577a6c3019a474fd6f485823', '4da8780eeb215e6cb7f48dd981c4ea02');
$this->assertEquals('4da8780eeb215e6cb7f48dd981c4ea02', $result->id);
$this->assertEquals('4da8780eeb215e6cb7f48dd981c4ea02', $rulesLists->getBody()->result->id);
}
}

View File

@@ -0,0 +1,78 @@
<?php
class ZoneCacheTest extends TestCase
{
public function testCachePurgeEverything()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/cachePurgeEverything.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('post')->willReturn($response);
$mock->expects($this->once())
->method('post')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'),
$this->equalTo(['purge_everything' => true])
);
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
$result = $zones->cachePurgeEverything('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
$this->assertTrue($result);
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id);
}
public function testCachePurgeHost()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/cachePurgeHost.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('post')->willReturn($response);
$mock->expects($this->once())
->method('post')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'),
$this->equalTo(
[
'files' => [],
'tags' => [],
'hosts' => ['dash.cloudflare.com']
]
)
);
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
$result = $zones->cachePurge('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', [], [], ['dash.cloudflare.com']);
$this->assertTrue($result);
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id);
}
public function testCachePurge()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/cachePurge.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('post')->willReturn($response);
$mock->expects($this->once())
->method('post')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'),
$this->equalTo(['files' => [
'https://example.com/file.jpg',
]
])
);
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
$result = $zones->cachePurge('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', [
'https://example.com/file.jpg',
]);
$this->assertTrue($result);
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id);
}
}

View File

@@ -0,0 +1,81 @@
<?php
use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Endpoints\ZoneSubscriptions;
class ZoneSubscriptionsTest extends TestCase
{
public function testListZoneSubscriptions()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listZoneSubscriptions.json');
$mock = $this->getMockBuilder(Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/subscriptions')
);
$zoneSubscriptions = new ZoneSubscriptions($mock);
$zoneSubscriptions->listZoneSubscriptions('023e105f4ecef8ad9ca31a8372d0c353');
$this->assertEquals('506e3185e9c882d175a2d0cb0093d9f2', $zoneSubscriptions->getBody()->result[0]->id);
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zoneSubscriptions->getBody()->result[0]->zone->id);
}
public function testAddZoneSubscriptionIfMissing()
{
$postResponse = $this->getPsr7JsonResponseForFixture('Endpoints/createZoneSubscription.json');
$getResponse = $this->getPsr7JsonResponseForFixture('Endpoints/listEmptyZoneSubscriptions.json');
$mock = $this->getMockBuilder(Adapter::class)->getMock();
$mock->method('post')->willReturn($postResponse);
$mock->method('get')->willReturn($getResponse);
$mock->expects($this->once())
->method('post')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/subscription'),
$this->equalTo([
'rate_plan' => [
'id' => 'PARTNER_PRO',
],
])
);
$zoneSubscriptions = new ZoneSubscriptions($mock);
$zoneSubscriptions->addZoneSubscription('023e105f4ecef8ad9ca31a8372d0c353', 'PARTNER_PRO');
$this->assertEquals('506e3185e9c882d175a2d0cb0093d9f2', $zoneSubscriptions->getBody()->result->id);
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zoneSubscriptions->getBody()->result->zone->id);
}
public function testAddZoneSubscriptionIfExisting()
{
$postResponse = $this->getPsr7JsonResponseForFixture('Endpoints/createZoneSubscription.json');
$getResponse = $this->getPsr7JsonResponseForFixture('Endpoints/listZoneSubscriptions.json');
$mock = $this->getMockBuilder(Adapter::class)->getMock();
$mock->method('put')->willReturn($postResponse);
$mock->method('get')->willReturn($getResponse);
$mock->expects($this->once())
->method('put')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/subscription'),
$this->equalTo([
'rate_plan' => [
'id' => 'PARTNER_PRO',
],
])
);
$zoneSubscriptions = new ZoneSubscriptions($mock);
$zoneSubscriptions->addZoneSubscription('023e105f4ecef8ad9ca31a8372d0c353', 'PARTNER_PRO');
$this->assertEquals('506e3185e9c882d175a2d0cb0093d9f2', $zoneSubscriptions->getBody()->result->id);
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zoneSubscriptions->getBody()->result->zone->id);
}
}

View File

@@ -40,7 +40,9 @@ class ZonesTest extends TestCase
$this->equalTo([
'name' => 'example.com',
'jump_start' => true,
'organization' => ['id' => '01a7362d577a6c3019a474fd6f485823']
'account' => [
'id' => '01a7362d577a6c3019a474fd6f485823',
],
])
);
@@ -49,6 +51,33 @@ class ZonesTest extends TestCase
$this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $zones->getBody()->result->id);
}
public function testAddZoneWithAccountId()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/addZone.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('post')->willReturn($response);
$mock->expects($this->once())
->method('post')
->with(
$this->equalTo('zones'),
$this->equalTo([
'name' => 'example.com',
'jump_start' => false,
'account' => [
'id' => '023e105f4ecef8ad9ca31a8372d0c353',
],
])
);
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
$result = $zones->addZone('example.com', false, '023e105f4ecef8ad9ca31a8372d0c353');
$this->assertObjectHasAttribute('id', $result);
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $result->account->id);
}
public function testActivationTest()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/activationTest.json');
@@ -188,78 +217,4 @@ class ZonesTest extends TestCase
$this->assertTrue($result);
$this->assertEquals('development_mode', $zones->getBody()->result->id);
}
public function testCachePurgeEverything()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/cachePurgeEverything.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('post')->willReturn($response);
$mock->expects($this->once())
->method('post')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'),
$this->equalTo(['purge_everything' => true])
);
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
$result = $zones->cachePurgeEverything('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
$this->assertTrue($result);
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id);
}
public function testCachePurgeHost()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/cachePurgeHost.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('post')->willReturn($response);
$mock->expects($this->once())
->method('post')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'),
$this->equalTo(
[
'files' => [],
'tags' => [],
'hosts' => ['dash.cloudflare.com']
]
)
);
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
$result = $zones->cachePurge('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', [], [], ['dash.cloudflare.com']);
$this->assertTrue($result);
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id);
}
public function testCachePurge()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/cachePurge.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('post')->willReturn($response);
$mock->expects($this->once())
->method('post')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'),
$this->equalTo(['files' => [
'https://example.com/file.jpg',
]
])
);
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
$result = $zones->cachePurge('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', [
'https://example.com/file.jpg',
]);
$this->assertTrue($result);
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id);
}
}

View File

@@ -23,6 +23,10 @@
"email": "user@example.com",
"owner_type": "user"
},
"account": {
"id": "023e105f4ecef8ad9ca31a8372d0c353",
"name": "Demo Account"
},
"permissions": [
"#zone:read",
"#zone:edit"

View File

@@ -0,0 +1,74 @@
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "4536bcfad5faccb111b47003c79917fa",
"code": "05dd05cce12bbed97c0d87cd78e89bc2fd41a6cee72f27f6fc84af2e45c0fac0",
"user": {
"id": "7c5dae5552338874e5053f2534d2767a",
"first_name": "John",
"last_name": "Appleseed",
"email": "user@example.com",
"two_factor_authentication_enabled": false
},
"status": "accepted",
"roles": [
{
"id": "3536bcfad5faccb999b47003c79917fb",
"name": "Account Administrator",
"description": "Administrative access to the entire Account",
"permissions": {
"analytics": {
"read": true,
"write": true
},
"billing": {
"read": true,
"write": true
},
"cache_purge": {
"read": true,
"write": true
},
"dns": {
"read": true,
"write": true
},
"dns_records": {
"read": true,
"write": true
},
"lb": {
"read": true,
"write": true
},
"logs": {
"read": true,
"write": true
},
"organization": {
"read": true,
"write": true
},
"ssl": {
"read": true,
"write": true
},
"waf": {
"read": true,
"write": true
},
"zones": {
"read": true,
"write": true
},
"zone_settings": {
"read": true,
"write": true
}
}
}
]
}
}

View File

@@ -0,0 +1,13 @@
{
"result": {
"id": "2bab6ace8c72ed3f09b9eca6db1396bb",
"name": "Foo Bar",
"type": "enterprise",
"settings": {
"enforce_twofactor": false
}
},
"success": true,
"errors": [],
"messages": []
}

View File

@@ -0,0 +1,25 @@
{
"success": true,
"errors": [
{
"code": 1000,
"message": "message"
}
],
"messages": [
{
"code": 1000,
"message": "message"
}
],
"result": {
"id": "2c0fc9fa937b11eaa1b71c4d701ab86e",
"created_on": "2020-01-01T08:00:00Z",
"description": "",
"kind": "ip",
"modified_on": "2020-01-10T14:00:00Z",
"name": "ip-allowlist",
"num_items": 10,
"num_referencing_filters": 2
}
}

View File

@@ -0,0 +1,18 @@
{
"errors": [
{
"code": 1000,
"message": "message"
}
],
"messages": [
{
"code": 1000,
"message": "message"
}
],
"result": {
"operation_id": "4da8780eeb215e6cb7f48dd981c4ea02"
},
"success": true
}

View File

@@ -0,0 +1,13 @@
{
"result": {
"id": "2bab6ace8c72ed3f09b9eca6db1396bb",
"name": "Foo Bar",
"type": "standard",
"settings": {
"enforce_twofactor": false
}
},
"success": true,
"errors": [],
"messages": []
}

View File

@@ -0,0 +1,40 @@
{
"success": true,
"errors": [],
"messages": [],
"result": {
"app": {
"install_id": null
},
"id": "506e3185e9c882d175a2d0cb0093d9f2",
"state": "Paid",
"price": 20,
"currency": "USD",
"component_values": [
{
"name": "page_rules",
"value": 20,
"default": 5,
"price": 5
}
],
"zone": {
"id": "023e105f4ecef8ad9ca31a8372d0c353",
"name": "example.com"
},
"frequency": "monthly",
"rate_plan": {
"id": "free",
"public_name": "Business Plan",
"currency": "USD",
"scope": "zone",
"sets": [
{}
],
"is_contract": false,
"externally_managed": false
},
"current_period_end": "2014-03-31T12:20:00Z",
"current_period_start": "2014-05-11T12:20:00Z"
}
}

View File

@@ -0,0 +1,18 @@
{
"errors": [
{
"code": 1000,
"message": "message"
}
],
"messages": [
{
"code": 1000,
"message": "message"
}
],
"result": {
"id": "2c0fc9fa937b11eaa1b71c4d701ab86e"
},
"success": true
}

View File

@@ -0,0 +1,18 @@
{
"success": true,
"errors": [
{
"code": 1000,
"message": "message"
}
],
"messages": [
{
"code": 1000,
"message": "message"
}
],
"result": {
"operation_id": "4da8780eeb215e6cb7f48dd981c4ea02"
}
}

View File

@@ -0,0 +1,21 @@
{
"errors": [
{
"code": 1000,
"message": "message"
}
],
"messages": [
{
"code": 1000,
"message": "message"
}
],
"result": {
"id": "4da8780eeb215e6cb7f48dd981c4ea02",
"status": "pending",
"completed": "2020-01-01T08:00:00Z",
"error": "This list is at the maximum number of items"
},
"success": true
}

View File

@@ -0,0 +1,25 @@
{
"success": true,
"errors": [
{
"code": 1000,
"message": "message"
}
],
"messages": [
{
"code": 1000,
"message": "message"
}
],
"result": {
"id": "2c0fc9fa937b11eaa1b71c4d701ab86e",
"created_on": "2020-01-01T08:00:00Z",
"description": "This is a note",
"kind": "ip",
"modified_on": "2020-01-10T14:00:00Z",
"name": "list1",
"num_items": 10,
"num_referencing_filters": 2
}
}

View File

@@ -0,0 +1,24 @@
{
"success": true,
"errors": [
{
"code": 1000,
"message": "message"
}
],
"messages": [
{
"code": 1000,
"message": "message"
}
],
"result": [
"10.0.0.1"
],
"result_info": {
"cursors": {
"after": "yyy",
"before": "xxx"
}
}
}

View File

@@ -0,0 +1,82 @@
{
"success": true,
"errors": [],
"messages": [],
"result": [
{
"id": "4536bcfad5faccb111b47003c79917fa",
"code": "05dd05cce12bbed97c0d87cd78e89bc2fd41a6cee72f27f6fc84af2e45c0fac0",
"user": {
"id": "7c5dae5552338874e5053f2534d2767a",
"first_name": "John",
"last_name": "Appleseed",
"email": "user@example.com",
"two_factor_authentication_enabled": false
},
"status": "accepted",
"roles": [
{
"id": "3536bcfad5faccb999b47003c79917fb",
"name": "Account Administrator",
"description": "Administrative access to the entire Account",
"permissions": {
"analytics": {
"read": true,
"write": true
},
"billing": {
"read": true,
"write": true
},
"cache_purge": {
"read": true,
"write": true
},
"dns": {
"read": true,
"write": true
},
"dns_records": {
"read": true,
"write": true
},
"lb": {
"read": true,
"write": true
},
"logs": {
"read": true,
"write": true
},
"organization": {
"read": true,
"write": true
},
"ssl": {
"read": true,
"write": true
},
"waf": {
"read": true,
"write": true
},
"zones": {
"read": true,
"write": true
},
"zone_settings": {
"read": true,
"write": true
}
}
}
]
}
],
"result_info": {
"page": 1,
"per_page": 20,
"count": 1,
"total_count": 200
}
}

View File

@@ -0,0 +1,69 @@
{
"success": true,
"errors": [],
"messages": [],
"result": [
{
"id": "3536bcfad5faccb999b47003c79917fb",
"name": "Account Administrator",
"description": "Administrative access to the entire Account",
"permissions": {
"analytics": {
"read": true,
"write": true
},
"billing": {
"read": true,
"write": true
},
"cache_purge": {
"read": true,
"write": true
},
"dns": {
"read": true,
"write": true
},
"dns_records": {
"read": true,
"write": true
},
"lb": {
"read": true,
"write": true
},
"logs": {
"read": true,
"write": true
},
"organization": {
"read": true,
"write": true
},
"ssl": {
"read": true,
"write": true
},
"waf": {
"read": true,
"write": true
},
"zones": {
"read": true,
"write": true
},
"zone_settings": {
"read": true,
"write": true
}
}
}
],
"result_info": {
"page": 1,
"per_page": 1,
"total_pages": 1,
"count": 1,
"total_count": 1
}
}

View File

@@ -0,0 +1,6 @@
{
"success": true,
"errors": [],
"messages": [],
"result": []
}

View File

@@ -0,0 +1,27 @@
{
"success": true,
"errors": [
{
"code": 1000,
"message": "message"
}
],
"messages": [
{
"code": 1000,
"message": "message"
}
],
"result": [
{
"id": "2c0fc9fa937b11eaa1b71c4d701ab86e",
"created_on": "2020-01-01T08:00:00Z",
"kind": "ip",
"modified_on": "2020-01-10T14:00:00Z",
"name": "list1",
"num_items": 10,
"description": "This is a note",
"num_referencing_filters": 2
}
]
}

View File

@@ -0,0 +1,42 @@
{
"success": true,
"errors": [],
"messages": [],
"result": [
{
"app": {
"install_id": null
},
"id": "506e3185e9c882d175a2d0cb0093d9f2",
"state": "Paid",
"price": 20,
"currency": "USD",
"component_values": [
{
"name": "page_rules",
"value": 20,
"default": 5,
"price": 5
}
],
"zone": {
"id": "023e105f4ecef8ad9ca31a8372d0c353",
"name": "example.com"
},
"frequency": "monthly",
"rate_plan": {
"id": "free",
"public_name": "Business Plan",
"currency": "USD",
"scope": "zone",
"sets": [
{}
],
"is_contract": false,
"externally_managed": false
},
"current_period_end": "2014-03-31T12:20:00Z",
"current_period_start": "2014-05-11T12:20:00Z"
}
]
}