Add Account Member Creation (#192)
We can now create account members threough the SDK
This commit is contained in:
34
src/Endpoints/AccountMembers.php
Normal file
34
src/Endpoints/AccountMembers.php
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?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;
|
||||||
|
}
|
||||||
|
}
|
||||||
32
tests/Endpoints/AccountMembersTest.php
Normal file
32
tests/Endpoints/AccountMembersTest.php
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<?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);
|
||||||
|
}
|
||||||
|
}
|
||||||
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user