-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I want to list the roles availablew in an account so I can add a member to the account
- Loading branch information
Showing
3 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |