Class: Twilio::TaskRouter::Capability

Inherits:
Object
  • Object
show all
Defined in:
lib/twilio-ruby/task_router/capability.rb

Constant Summary collapse

TASK_ROUTER_BASE_URL =
'https://taskrouter.twilio.com'
TASK_ROUTER_VERSION =
'v1'
TASK_ROUTER_WEBSOCKET_BASE_URL =
'https://event-bridge.twilio.com/v1/wschannels'
REQUIRED =
{required: true}
OPTIONAL =
{required: false}

Instance Method Summary collapse

Constructor Details

#initialize(account_sid, auth_token, workspace_sid, channel_id) ⇒ Capability

Returns a new instance of Capability.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/twilio-ruby/task_router/capability.rb', line 11

def initialize(, auth_token, workspace_sid, channel_id)
  @account_sid = 
  @auth_token = auth_token
  @policies = []

  @workspace_sid = workspace_sid
  @channel_id = channel_id

  @baseUrl = "#{TASK_ROUTER_BASE_URL}/#{TASK_ROUTER_VERSION}/Workspaces/#{workspace_sid}"

  validate_jwt

  setup_resource

  allow_websocket_requests(@channel_id)
  allow(@resourceUrl, "GET")
end

Instance Method Details

#add_policy(url, method, allowed = true, query_filters = nil, post_filters = nil) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/twilio-ruby/task_router/capability.rb', line 77

def add_policy(url, method, allowed = true, query_filters = nil, post_filters = nil)
  policy = {
      url: url,
      method: method,
      query_filter: query_filters || {},
      post_filter: post_filters || {},
      allow: allowed
  }

  @policies.push(policy)
end

#allow(url, method, query_filters = nil, post_filters = nil) ⇒ Object



89
90
91
# File 'lib/twilio-ruby/task_router/capability.rb', line 89

def allow(url, method, query_filters = nil, post_filters = nil)
  add_policy(url, method, true, query_filters, post_filters)
end

#allow_deleteObject



41
42
43
# File 'lib/twilio-ruby/task_router/capability.rb', line 41

def allow_delete
  allow(@resourceUrl, "DELETE")
end

#allow_delete_subresourcesObject



45
46
47
# File 'lib/twilio-ruby/task_router/capability.rb', line 45

def allow_delete_subresources
  allow(@resourceUrl + "/**", "DELETE")
end

#allow_fetch_subresourcesObject



29
30
31
# File 'lib/twilio-ruby/task_router/capability.rb', line 29

def allow_fetch_subresources
  allow(@resourceUrl + "/**", "GET")
end

#allow_task_reservation_updatesObject

Deprecated.

Please use WorkerCapability.allowReservationUpdates instead



68
69
70
71
72
73
74
75
# File 'lib/twilio-ruby/task_router/capability.rb', line 68

def allow_task_reservation_updates
  if(@channel_id[0..1] == 'WK')
    task_url = "#{@baseUrl}/Tasks/**"
    allow(task_url, "POST", nil, nil)
  else
    raise "Deprecated function not applicable to non Worker"
  end
end

#allow_updatesObject



33
34
35
# File 'lib/twilio-ruby/task_router/capability.rb', line 33

def allow_updates
  allow(@resourceUrl, "POST")
end

#allow_updates_subresourcesObject



37
38
39
# File 'lib/twilio-ruby/task_router/capability.rb', line 37

def allow_updates_subresources
  allow(@resourceUrl + "/**", "POST")
end

#allow_worker_activity_updatesObject

Deprecated.

Please use WorkerCapability.allowActivityUpdates instead



50
51
52
53
54
55
56
# File 'lib/twilio-ruby/task_router/capability.rb', line 50

def allow_worker_activity_updates
  if(@channel_id[0..1] == 'WK')
    allow(@resourceUrl, "POST", nil, {ActivitySid: REQUIRED})
  else
    raise "Deprecreated function not applicable to non-Worker"
  end
end

#allow_worker_fetch_attributesObject

Deprecated.

Please use WorkerCapability instead; added automatically in constructor



59
60
61
62
63
64
65
# File 'lib/twilio-ruby/task_router/capability.rb', line 59

def allow_worker_fetch_attributes
  if(@channel_id[0..1] == 'WK')
    allow(@resourceUrl, "GET")
  else
    raise "Deprecated function not applicable to non Worker"
  end
end

#deny(url, method, query_filters = nil, post_filters = nil) ⇒ Object



93
94
95
# File 'lib/twilio-ruby/task_router/capability.rb', line 93

def deny(url, method, query_filters = nil, post_filters = nil)
  add_policy(url, method, false, query_filters, post_filters)
end

#generate_token(ttl = 3600) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/twilio-ruby/task_router/capability.rb', line 97

def generate_token(ttl = 3600)
  taskRouterAttributes = {
      account_sid: @account_sid,
      workspace_sid: @workspace_sid,
      channel: @channel_id
  }

  if(@channel_id[0..1] == 'WK')
    taskRouterAttributes['worker_sid'] = @channel_id
  elsif(@channel_id[0..1] == 'WQ')
    taskRouterAttributes['taskqueue_sid'] = @channel_id
  end

  generate_token_protected(ttl, taskRouterAttributes)
end