File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Cloudflare \API \Endpoints ;
4+
5+ use Cloudflare \API \Adapter \Adapter ;
6+ use Cloudflare \API \Traits \BodyAccessorTrait ;
7+
8+ class AccountMembers implements API
9+ {
10+ use BodyAccessorTrait;
11+
12+ /**
13+ * @var Adapter
14+ */
15+ private $ adapter ;
16+
17+ public function __construct (Adapter $ adapter )
18+ {
19+ $ this ->adapter = $ adapter ;
20+ }
21+
22+ public function addAccountMember (string $ accountId , string $ email , array $ roles ): \stdClass
23+ {
24+ $ options = [
25+ 'email ' => $ email ,
26+ 'roles ' => $ roles ,
27+ ];
28+
29+ $ account = $ this ->adapter ->post ('accounts/ ' . $ accountId . '/members ' , $ options );
30+ $ this ->body = json_decode ($ account ->getBody ());
31+
32+ return $ this ->body ->result ;
33+ }
34+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ use Cloudflare \API \Adapter \Adapter ;
4+ use Cloudflare \API \Endpoints \AccountMembers ;
5+
6+ class AccountMembersTest extends TestCase
7+ {
8+ public function testAddAccountMember ()
9+ {
10+ $ response = $ this ->getPsr7JsonResponseForFixture ('Endpoints/createAccountMember.json ' );
11+
12+ $ mock = $ this ->getMockBuilder (Adapter::class)->getMock ();
13+ $ mock ->method ('post ' )->willReturn ($ response );
14+
15+ $ mock ->expects ($ this ->once ())
16+ ->method ('post ' )
17+ ->with (
18+ $ this ->equalTo ('accounts/01a7362d577a6c3019a474fd6f485823/members ' ),
19+ $ this ->equalTo ([
20+ 'email ' => 'user@example.com ' ,
21+ 'roles ' => [
22+ '3536bcfad5faccb999b47003c79917fb ' ,
23+ ],
24+ ])
25+ );
26+
27+ $ accountMembers = new AccountMembers ($ mock );
28+ $ accountMembers ->addAccountMember ('01a7362d577a6c3019a474fd6f485823 ' , 'user@example.com ' , ['3536bcfad5faccb999b47003c79917fb ' ]);
29+
30+ $ this ->assertEquals ('4536bcfad5faccb111b47003c79917fa ' , $ accountMembers ->getBody ()->result ->id );
31+ }
32+ }
Original file line number Diff line number Diff line change 1+ {
2+ "success" : true ,
3+ "errors" : [],
4+ "messages" : [],
5+ "result" : {
6+ "id" : " 4536bcfad5faccb111b47003c79917fa" ,
7+ "code" : " 05dd05cce12bbed97c0d87cd78e89bc2fd41a6cee72f27f6fc84af2e45c0fac0" ,
8+ "user" : {
9+ "id" : " 7c5dae5552338874e5053f2534d2767a" ,
10+ "first_name" : " John" ,
11+ "last_name" : " Appleseed" ,
12+ "email" : " user@example.com" ,
13+ "two_factor_authentication_enabled" : false
14+ },
15+ "status" : " accepted" ,
16+ "roles" : [
17+ {
18+ "id" : " 3536bcfad5faccb999b47003c79917fb" ,
19+ "name" : " Account Administrator" ,
20+ "description" : " Administrative access to the entire Account" ,
21+ "permissions" : {
22+ "analytics" : {
23+ "read" : true ,
24+ "write" : true
25+ },
26+ "billing" : {
27+ "read" : true ,
28+ "write" : true
29+ },
30+ "cache_purge" : {
31+ "read" : true ,
32+ "write" : true
33+ },
34+ "dns" : {
35+ "read" : true ,
36+ "write" : true
37+ },
38+ "dns_records" : {
39+ "read" : true ,
40+ "write" : true
41+ },
42+ "lb" : {
43+ "read" : true ,
44+ "write" : true
45+ },
46+ "logs" : {
47+ "read" : true ,
48+ "write" : true
49+ },
50+ "organization" : {
51+ "read" : true ,
52+ "write" : true
53+ },
54+ "ssl" : {
55+ "read" : true ,
56+ "write" : true
57+ },
58+ "waf" : {
59+ "read" : true ,
60+ "write" : true
61+ },
62+ "zones" : {
63+ "read" : true ,
64+ "write" : true
65+ },
66+ "zone_settings" : {
67+ "read" : true ,
68+ "write" : true
69+ }
70+ }
71+ }
72+ ]
73+ }
74+ }
You can’t perform that action at this time.
0 commit comments