Merge pull request #1 from shellrent/feature/merge-upstream
Merge cloudflare-php upstream
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
"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",
|
||||
"ext-json": "*"
|
||||
|
||||
50
src/Endpoints/AccountMembers.php
Normal file
50
src/Endpoints/AccountMembers.php
Normal 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,
|
||||
];
|
||||
}
|
||||
}
|
||||
33
src/Endpoints/AccountRoles.php
Normal file
33
src/Endpoints/AccountRoles.php
Normal 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,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
51
src/Endpoints/ZoneSubscriptions.php
Normal file
51
src/Endpoints/ZoneSubscriptions.php
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
59
tests/Endpoints/AccountMembersTest.php
Normal file
59
tests/Endpoints/AccountMembersTest.php
Normal 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);
|
||||
}
|
||||
}
|
||||
32
tests/Endpoints/AccountRolesTest.php
Normal file
32
tests/Endpoints/AccountRolesTest.php
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
78
tests/Endpoints/ZoneCacheTest.php
Normal file
78
tests/Endpoints/ZoneCacheTest.php
Normal 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);
|
||||
}
|
||||
}
|
||||
81
tests/Endpoints/ZoneSubscriptionsTest.php
Normal file
81
tests/Endpoints/ZoneSubscriptionsTest.php
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,10 @@
|
||||
"email": "user@example.com",
|
||||
"owner_type": "user"
|
||||
},
|
||||
"account": {
|
||||
"id": "023e105f4ecef8ad9ca31a8372d0c353",
|
||||
"name": "Demo Account"
|
||||
},
|
||||
"permissions": [
|
||||
"#zone:read",
|
||||
"#zone:edit"
|
||||
|
||||
74
tests/Fixtures/Endpoints/createAccountMember.json
Normal file
74
tests/Fixtures/Endpoints/createAccountMember.json
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
13
tests/Fixtures/Endpoints/createEnterpriseAccount.json
Normal file
13
tests/Fixtures/Endpoints/createEnterpriseAccount.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"result": {
|
||||
"id": "2bab6ace8c72ed3f09b9eca6db1396bb",
|
||||
"name": "Foo Bar",
|
||||
"type": "enterprise",
|
||||
"settings": {
|
||||
"enforce_twofactor": false
|
||||
}
|
||||
},
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": []
|
||||
}
|
||||
13
tests/Fixtures/Endpoints/createStandardAccount.json
Normal file
13
tests/Fixtures/Endpoints/createStandardAccount.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"result": {
|
||||
"id": "2bab6ace8c72ed3f09b9eca6db1396bb",
|
||||
"name": "Foo Bar",
|
||||
"type": "standard",
|
||||
"settings": {
|
||||
"enforce_twofactor": false
|
||||
}
|
||||
},
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": []
|
||||
}
|
||||
40
tests/Fixtures/Endpoints/createZoneSubscription.json
Normal file
40
tests/Fixtures/Endpoints/createZoneSubscription.json
Normal 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"
|
||||
}
|
||||
}
|
||||
82
tests/Fixtures/Endpoints/listAccountMembers.json
Normal file
82
tests/Fixtures/Endpoints/listAccountMembers.json
Normal 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
|
||||
}
|
||||
}
|
||||
69
tests/Fixtures/Endpoints/listAccountRoles.json
Normal file
69
tests/Fixtures/Endpoints/listAccountRoles.json
Normal 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
|
||||
}
|
||||
}
|
||||
6
tests/Fixtures/Endpoints/listEmptyZoneSubscriptions.json
Normal file
6
tests/Fixtures/Endpoints/listEmptyZoneSubscriptions.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": [],
|
||||
"result": []
|
||||
}
|
||||
42
tests/Fixtures/Endpoints/listZoneSubscriptions.json
Normal file
42
tests/Fixtures/Endpoints/listZoneSubscriptions.json
Normal 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"
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user