Add Account Role Listings (#198)
I want to list the roles availablew in an account so I can add a member to the account
This commit is contained in:
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,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
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
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user