1
1
import time
2
- import warnings
3
2
4
3
from twilio import jwt
5
4
6
- warnings .simplefilter ('always' , DeprecationWarning )
7
-
8
5
TASK_ROUTER_BASE_URL = 'https://taskrouter.twilio.com'
9
6
TASK_ROUTER_BASE_EVENTS_URL = 'https://event-bridge.twilio.com/v1/wschannels'
10
7
TASK_ROUTER_VERSION = "v1"
13
10
OPTIONAL = {'required' : False }
14
11
15
12
16
- def deprecated (func ):
17
- def log_warning (* args , ** kwargs ):
18
- # stacklevel = 2 makes the warning refer to the caller of the
19
- # deprecation rather than the source of deprecation itself
20
- warnings .warn ("Call to deprecated function {0}." .
21
- format (func .__name__ ),
22
- stacklevel = 2 ,
23
- category = DeprecationWarning )
10000
24
- return func (* args , ** kwargs )
25
- return log_warning
26
-
27
-
28
13
class TaskRouterCapability (object ):
29
14
def __init__ (self , account_sid , auth_token , workspace_sid , channel_id ):
30
15
self .account_sid = account_sid
@@ -44,7 +29,7 @@ def __init__(self, account_sid, auth_token, workspace_sid, channel_id):
44
29
self .allow_web_sockets (channel_id )
45
30
46
31
# set up resources
47
- self .setup_resource ()
32
+ self .resource_url = self . setup_resource ()
48
33
49
34
# add permissions to fetch the instance resource
50
35
self .add_policy (self .resource_url , "GET" , True )
@@ -54,23 +39,7 @@ def channel_prefix(self):
54
39
return self .channel_id [0 :2 ]
55
40
56
41
def setup_resource (self ):
57
- if self .channel_prefix == "WS" :
58
- self .resource_url = self .base_url
59
- elif self .channel_prefix == "WK" :
60
- self .resource_url = self .base_url + "/Workers/" + self .channel_id
61
-
62
- activity_url = self .base_url + "/Activities"
63
- self .allow (activity_url , "GET" )
64
-
65
- tasks_url = self .base_url + "/Tasks/**"
66
- self .allow (tasks_url , "GET" )
67
-
68
- worker_reservations_url = self .resource_url + "/Reservations/**"
69
- self .allow (worker_reservations_url , "GET" )
70
-
71
- elif self .channel_prefix == "WQ" :
72
- self .resource_url = "{0}/TaskQueues/{1}" .format (
73
- self .base_url , self .channel_id )
42
+ return self .base_url
74
43
75
44
def allow_web_sockets (self , channel_id ):
76
45
web_socket_url = "{0}/{1}/{2}" .format (TASK_ROUTER_BASE_EVENTS_URL ,
@@ -109,37 +78,6 @@ def allow_delete(self):
109
78
def allow_delete_subresources (self ):
110
79
self .allow (self .resource_url + "/**" , "DELETE" )
111
80
112
- @deprecated
113
- def allow_worker_fetch_attributes (self ):
114
- if self .channel_prefix != "WK" :
115
- raise ValueError ("Deprecated func not applicable to non Worker" )
116
- else :
117
- self .policies .append (self .make_policy (
118
- self .resource_url ,
119
- 'GET' ))
120
-
121
- @deprecated
122
- def allow_worker_activity_updates (self ):
123
- if self .channel_prefix == "WK" :
124
- self .policies .append (self .make_policy (
125
- self .resource_url ,
126
- 'POST' ,
127
- True ,
128
- post_filter = {'ActivitySid' : REQUIRED }))
129
- else :
130
- raise ValueError ("Deprecated func not applicable to non Worker" )
131
-
132
- @deprecated
133
- def allow_task_reservation_updates (self ):
134
- if self .channel_prefix == "WK" :
135
- tasks_url = self .base_url + "/Tasks/**"
136
- self .policies .append (self .make_policy (
137
- tasks_url ,
138
- 'POST' ,
139
- True ))
140
- else :
141
- raise ValueError ("Deprecated func not applicable to non Worker" )
142
-
143
81
def add_policy (self , url , method ,
144
82
allowed , query_filter = None , post_filter = None ):
145
83
@@ -224,7 +162,7 @@ def __init__(self, account_sid, auth_token, workspace_sid, worker_sid):
224
162
self .allow (self .worker_reservations_url , "GET" )
225
163
226
164
def setup_resource (self ):
227
- self . resource_url = self .base_url + "/Workers/" + self .channel_id
165
+ return self .base_url + "/Workers/" + self .channel_id
228
166
229
167
def allow_activity_updates (self ):
230
168
self .policies .append (self .make_policy (
@@ -245,8 +183,14 @@ def allow_reservation_updates(self):
245
183
246
184
247
185
class TaskRouterTaskQueueCapability (TaskRouterCapability ):
186
+ def __init__ (self , account_sid , auth_token , workspace_sid , task_queue_sid ):
187
+ super (TaskRouterTaskQueueCapability , self ).__init__ (account_sid ,
188
+ auth_token ,
189
+ workspace_sid ,
190
+ task_queue_sid )
191
+
248
192
def setup_resource (self ):
249
- self . resource_url = self .base_url + "/TaskQueues/" + self .channel_id
193
+ return self .base_url + "/TaskQueues/" + self .channel_id
250
194
251
195
252
196
class TaskRouterWorkspaceCapability (TaskRouterCapability ):
@@ -257,4 +201,4 @@ def __init__(self, account_sid, auth_token, workspace_sid):
257
201
workspace_sid )
258
202
259
203
def setup_resource (self ):
260
- self . resource_url = self .base_url
204
+ return self .base_url
0 commit comments