forked from twilio/twilio-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWorkerCapability.php
49 lines (40 loc) · 1.81 KB
/
WorkerCapability.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
<?php
namespace Twilio\Jwt\TaskRouter;
/**
* Twilio TaskRouter Worker Capability assigner
*
* @author Justin Witz <[email protected]>
* @license http://creativecommons.org/licenses/MIT/ MIT
*/
class WorkerCapability extends CapabilityToken {
private $tasksUrl;
private $workerReservationsUrl;
private $activityUrl;
public function __construct(string $accountSid, string $authToken, string $workspaceSid, string $workerSid,
?string $overrideBaseUrl = null, ?string $overrideBaseWSUrl = null) {
parent::__construct($accountSid, $authToken, $workspaceSid, $workerSid, null, $overrideBaseUrl, $overrideBaseWSUrl);
$this->tasksUrl = $this->baseUrl . '/Tasks/**';
$this->activityUrl = $this->baseUrl . '/Activities';
$this->workerReservationsUrl = $this->resourceUrl . '/Reservations/**';
//add permissions to fetch the list of activities, tasks, and worker reservations
$this->allow($this->activityUrl, 'GET', null, null);
$this->allow($this->tasksUrl, 'GET', null, null);
$this->allow($this->workerReservationsUrl, 'GET', null, null);
}
protected function setupResource(): void {
$this->resourceUrl = $this->baseUrl . '/Workers/' . $this->channelId;
}
public function allowActivityUpdates(): void {
$method = 'POST';
$queryFilter = [];
$postFilter = ['ActivitySid' => $this->required];
$this->allow($this->resourceUrl, $method, $queryFilter, $postFilter);
}
public function allowReservationUpdates(): void {
$method = 'POST';
$queryFilter = [];
$postFilter = [];
$this->allow($this->tasksUrl, $method, $queryFilter, $postFilter);
$this->allow($this->workerReservationsUrl, $method, $queryFilter, $postFilter);
}
}