Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/Endpoints/UserInvites.php
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;

class UserInvites implements API
{
use BodyAccessorTrait;

/**
* @var Adapter
*/
private $adapter;

public function __construct(Adapter $adapter)
{
$this->adapter = $adapter;
}

public function respondToInvite(string $inviteId, string $status)
{
$options = [
'status' => $status,
];

$invite = $this->adapter->patch('user/invites/' . $inviteId, $options);
$this->body = json_decode($invite->getBody());

return $this->body->result;
}
}
31 changes: 31 additions & 0 deletions tests/Endpoints/UserInviteTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Endpoints\UserInvites;

class UserInviteTest extends TestCase
{
public function testUpdateUserInvite()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/respondToUserInvite.json');

$mock = $this->getMockBuilder(Adapter::class)->getMock();
$mock->method('patch')->willReturn($response);

$mock->expects($this->once())
->method('patch')
->with(
$this->equalTo('user/invites/4f5f0c14a2a41d5063dd301b2f829f04'),
$this->equalTo([
'status' => 'accepted',
])
);

$userInvites = new UserInvites($mock);

$result = $userInvites->respondToInvite('4f5f0c14a2a41d5063dd301b2f829f04', 'accepted');

$this->assertObjectHasAttribute('id', $result);
$this->assertEquals('4f5f0c14a2a41d5063dd301b2f829f04', $userInvites->getBody()->result->id);
}
}
26 changes: 26 additions & 0 deletions tests/Fixtures/Endpoints/respondToUserInvite.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "4f5f0c14a2a41d5063dd301b2f829f04",
"invited_member_id": "5a7805061c76ada191ed06f989cc3dac",
"invited_member_email": "user@example.com",
"organization_id": "5a7805061c76ada191ed06f989cc3dac",
"organization_name": "Cloudflare, Inc.",
"roles": [
{
"id": "3536bcfad5faccb999b47003c79917fb",
"name": "Organization Admin",
"description": "Administrative access to the entire Organization",
"permissions": [
"#zones:read"
]
}
],
"invited_by": "user@example.com",
"invited_on": "2014-01-01T05:20:00Z",
"expires_on": "2014-01-01T05:20:00Z",
"status": "accepted"
}
}