-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathpermissions.php
60 lines (49 loc) · 2.13 KB
/
permissions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
use Mailtrap\Config;
use Mailtrap\DTO\Request\Permission\CreateOrUpdatePermission;
use Mailtrap\DTO\Request\Permission\DestroyPermission;
use Mailtrap\DTO\Request\Permission\PermissionInterface;
use Mailtrap\DTO\Request\Permission\Permissions;
use Mailtrap\Helper\ResponseHelper;
use Mailtrap\MailtrapGeneralClient;
require __DIR__ . '/../vendor/autoload.php';
$accountId = getenv('MAILTRAP_ACCOUNT_ID');
$config = new Config(getenv('MAILTRAP_API_KEY')); #your API token from here https://mailtrap.io/api-tokens
$generalPermissions = (new MailtrapGeneralClient($config))->permissions($accountId);
/**
* Get resources
*
* GET https://mailtrap.io/api/accounts/{account_id}/permissions/resources
*/
try {
$response = $generalPermissions->getResources();
// print the response body (array)
var_dump(ResponseHelper::toArray($response));
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
/**
* Manage user or token permissions
*
* If you send a combination of resource_type and resource_id that already exists, the permission is updated.
* If the combination doesn’t exist, the permission is created.
*
* PUT https://mailtrap.io/api/accounts/{account_id}/account_accesses/{account_access_id}/permissions/bulk
*/
try {
$accountAccessId = getenv('MAILTRAP_ACCOUNT_ACCESS_ID');
// resource IDs
$projectResourceId = getenv('MAILTRAP_NEW_PROJECT_RESOURCE_ID');
$inboxResourceId = getenv('MAILTRAP_INBOX_RESOURCE_ID');
$destroyProjectResourceId = getenv('MAILTRAP_OLD_PROJECT_RESOURCE_ID');
$permissions = new Permissions(
new CreateOrUpdatePermission($projectResourceId, PermissionInterface::TYPE_PROJECT, 10), // viewer = 10
new CreateOrUpdatePermission($inboxResourceId, PermissionInterface::TYPE_INBOX, 100), // admin = 100
new DestroyPermission($destroyProjectResourceId, PermissionInterface::TYPE_PROJECT),
);
$response = $generalPermissions->update($accountAccessId, $permissions);
// print the response body (array)
var_dump(ResponseHelper::toArray($response));
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}