twilio-ruby 5.0.0.rc21 → 5.0.0.rc22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Makefile +3 -0
- data/lib/twilio-ruby.rb +7 -3
- data/lib/twilio-ruby/framework/domain.rb +5 -1
- data/lib/twilio-ruby/framework/page.rb +4 -4
- data/lib/twilio-ruby/framework/serialize.rb +3 -2
- data/lib/twilio-ruby/framework/values.rb +7 -0
- data/lib/twilio-ruby/framework/version.rb +4 -6
- data/lib/twilio-ruby/jwt/access_token.rb +160 -134
- data/lib/twilio-ruby/jwt/client_capability.rb +98 -0
- data/lib/twilio-ruby/jwt/jwt.rb +56 -0
- data/lib/twilio-ruby/jwt/task_router.rb +108 -139
- data/lib/twilio-ruby/rest/accounts.rb +1 -1
- data/lib/twilio-ruby/rest/accounts/v1/credential.rb +1 -1
- data/lib/twilio-ruby/rest/accounts/v1/credential/public_key.rb +30 -17
- data/lib/twilio-ruby/rest/api.rb +2 -2
- data/lib/twilio-ruby/rest/api/v2010/account.rb +31 -18
- data/lib/twilio-ruby/rest/api/v2010/account/address.rb +32 -19
- data/lib/twilio-ruby/rest/api/v2010/account/address/dependent_phone_number.rb +18 -5
- data/lib/twilio-ruby/rest/api/v2010/account/application.rb +32 -19
- data/lib/twilio-ruby/rest/api/v2010/account/authorized_connect_app.rb +20 -7
- data/lib/twilio-ruby/rest/api/v2010/account/available_phone_number.rb +20 -7
- data/lib/twilio-ruby/rest/api/v2010/account/available_phone_number/local.rb +20 -7
- data/lib/twilio-ruby/rest/api/v2010/account/available_phone_number/mobile.rb +20 -7
- data/lib/twilio-ruby/rest/api/v2010/account/available_phone_number/toll_free.rb +20 -7
- data/lib/twilio-ruby/rest/api/v2010/account/call.rb +33 -20
- data/lib/twilio-ruby/rest/api/v2010/account/call/feedback.rb +13 -13
- data/lib/twilio-ruby/rest/api/v2010/account/call/feedback_summary.rb +8 -8
- data/lib/twilio-ruby/rest/api/v2010/account/call/notification.rb +23 -10
- data/lib/twilio-ruby/rest/api/v2010/account/call/recording.rb +23 -10
- data/lib/twilio-ruby/rest/api/v2010/account/conference.rb +27 -14
- data/lib/twilio-ruby/rest/api/v2010/account/conference/participant.rb +32 -19
- data/lib/twilio-ruby/rest/api/v2010/account/connect_app.rb +25 -12
- data/lib/twilio-ruby/rest/api/v2010/account/incoming_phone_number.rb +32 -19
- data/lib/twilio-ruby/rest/api/v2010/account/incoming_phone_number/assigned_add_on.rb +24 -11
- data/lib/twilio-ruby/rest/api/v2010/account/incoming_phone_number/assigned_add_on/assigned_add_on_extension.rb +20 -7
- data/lib/twilio-ruby/rest/api/v2010/account/incoming_phone_number/local.rb +24 -11
- data/lib/twilio-ruby/rest/api/v2010/account/incoming_phone_number/mobile.rb +24 -11
- data/lib/twilio-ruby/rest/api/v2010/account/incoming_phone_number/toll_free.rb +24 -11
- data/lib/twilio-ruby/rest/api/v2010/account/key.rb +26 -13
- data/lib/twilio-ruby/rest/api/v2010/account/message.rb +30 -17
- data/lib/twilio-ruby/rest/api/v2010/account/message/feedback.rb +5 -5
- data/lib/twilio-ruby/rest/api/v2010/account/message/media.rb +23 -10
- data/lib/twilio-ruby/rest/api/v2010/account/new_key.rb +5 -5
- data/lib/twilio-ruby/rest/api/v2010/account/new_signing_key.rb +5 -5
- data/lib/twilio-ruby/rest/api/v2010/account/notification.rb +23 -10
- data/lib/twilio-ruby/rest/api/v2010/account/outgoing_caller_id.rb +28 -15
- data/lib/twilio-ruby/rest/api/v2010/account/queue.rb +30 -17
- data/lib/twilio-ruby/rest/api/v2010/account/queue/member.rb +23 -10
- data/lib/twilio-ruby/rest/api/v2010/account/recording.rb +23 -10
- data/lib/twilio-ruby/rest/api/v2010/account/recording/add_on_result.rb +21 -8
- data/lib/twilio-ruby/rest/api/v2010/account/recording/add_on_result/payload.rb +21 -8
- data/lib/twilio-ruby/rest/api/v2010/account/recording/transcription.rb +21 -8
- data/lib/twilio-ruby/rest/api/v2010/account/short_code.rb +27 -14
- data/lib/twilio-ruby/rest/api/v2010/account/signing_key.rb +26 -13
- data/lib/twilio-ruby/rest/api/v2010/account/sip.rb +1 -1
- data/lib/twilio-ruby/rest/api/v2010/account/sip/credential_list.rb +27 -14
- data/lib/twilio-ruby/rest/api/v2010/account/sip/credential_list/credential.rb +29 -16
- data/lib/twilio-ruby/rest/api/v2010/account/sip/domain.rb +30 -17
- data/lib/twilio-ruby/rest/api/v2010/account/sip/domain/credential_list_mapping.rb +24 -11
- data/lib/twilio-ruby/rest/api/v2010/account/sip/domain/ip_access_control_list_mapping.rb +24 -11
- data/lib/twilio-ruby/rest/api/v2010/account/sip/ip_access_control_list.rb +27 -14
- data/lib/twilio-ruby/rest/api/v2010/account/sip/ip_access_control_list/ip_address.rb +29 -16
- data/lib/twilio-ruby/rest/api/v2010/account/token.rb +5 -5
- data/lib/twilio-ruby/rest/api/v2010/account/transcription.rb +21 -8
- data/lib/twilio-ruby/rest/api/v2010/account/usage.rb +1 -1
- data/lib/twilio-ruby/rest/api/v2010/account/usage/record.rb +20 -7
- data/lib/twilio-ruby/rest/api/v2010/account/usage/record/all_time.rb +20 -7
- data/lib/twilio-ruby/rest/api/v2010/account/usage/record/daily.rb +20 -7
- data/lib/twilio-ruby/rest/api/v2010/account/usage/record/last_month.rb +20 -7
- data/lib/twilio-ruby/rest/api/v2010/account/usage/record/monthly.rb +20 -7
- data/lib/twilio-ruby/rest/api/v2010/account/usage/record/this_month.rb +20 -7
- data/lib/twilio-ruby/rest/api/v2010/account/usage/record/today.rb +20 -7
- data/lib/twilio-ruby/rest/api/v2010/account/usage/record/yearly.rb +20 -7
- data/lib/twilio-ruby/rest/api/v2010/account/usage/record/yesterday.rb +20 -7
- data/lib/twilio-ruby/rest/api/v2010/account/usage/trigger.rb +32 -19
- data/lib/twilio-ruby/rest/api/v2010/account/validation_request.rb +5 -5
- data/lib/twilio-ruby/rest/chat.rb +4 -4
- data/lib/twilio-ruby/rest/chat/v1/credential.rb +30 -17
- data/lib/twilio-ruby/rest/chat/v1/service.rb +29 -16
- data/lib/twilio-ruby/rest/chat/v1/service/channel.rb +32 -19
- data/lib/twilio-ruby/rest/chat/v1/service/channel/invite.rb +27 -14
- data/lib/twilio-ruby/rest/chat/v1/service/channel/member.rb +32 -19
- data/lib/twilio-ruby/rest/chat/v1/service/channel/message.rb +32 -19
- data/lib/twilio-ruby/rest/chat/v1/service/role.rb +27 -14
- data/lib/twilio-ruby/rest/chat/v1/service/user.rb +30 -17
- data/lib/twilio-ruby/rest/chat/v1/service/user/user_channel.rb +18 -5
- data/lib/twilio-ruby/rest/chat/v2/credential.rb +30 -17
- data/lib/twilio-ruby/rest/chat/v2/service.rb +29 -16
- data/lib/twilio-ruby/rest/chat/v2/service/channel.rb +32 -19
- data/lib/twilio-ruby/rest/chat/v2/service/channel/invite.rb +27 -14
- data/lib/twilio-ruby/rest/chat/v2/service/channel/member.rb +32 -19
- data/lib/twilio-ruby/rest/chat/v2/service/channel/message.rb +32 -19
- data/lib/twilio-ruby/rest/chat/v2/service/role.rb +27 -14
- data/lib/twilio-ruby/rest/chat/v2/service/user.rb +30 -17
- data/lib/twilio-ruby/rest/chat/v2/service/user/user_channel.rb +18 -5
- data/lib/twilio-ruby/rest/fax.rb +2 -2
- data/lib/twilio-ruby/rest/fax/v1/fax.rb +32 -19
- data/lib/twilio-ruby/rest/fax/v1/fax/fax_media.rb +21 -8
- data/lib/twilio-ruby/rest/ip_messaging.rb +4 -4
- data/lib/twilio-ruby/rest/ip_messaging/v1/credential.rb +30 -17
- data/lib/twilio-ruby/rest/ip_messaging/v1/service.rb +29 -16
- data/lib/twilio-ruby/rest/ip_messaging/v1/service/channel.rb +32 -19
- data/lib/twilio-ruby/rest/ip_messaging/v1/service/channel/invite.rb +27 -14
- data/lib/twilio-ruby/rest/ip_messaging/v1/service/channel/member.rb +32 -19
- data/lib/twilio-ruby/rest/ip_messaging/v1/service/channel/message.rb +32 -19
- data/lib/twilio-ruby/rest/ip_messaging/v1/service/role.rb +27 -14
- data/lib/twilio-ruby/rest/ip_messaging/v1/service/user.rb +30 -17
- data/lib/twilio-ruby/rest/ip_messaging/v1/service/user/user_channel.rb +18 -5
- data/lib/twilio-ruby/rest/ip_messaging/v2/credential.rb +30 -17
- data/lib/twilio-ruby/rest/ip_messaging/v2/service.rb +29 -16
- data/lib/twilio-ruby/rest/ip_messaging/v2/service/channel.rb +32 -19
- data/lib/twilio-ruby/rest/ip_messaging/v2/service/channel/invite.rb +27 -14
- data/lib/twilio-ruby/rest/ip_messaging/v2/service/channel/member.rb +32 -19
- data/lib/twilio-ruby/rest/ip_messaging/v2/service/channel/message.rb +32 -19
- data/lib/twilio-ruby/rest/ip_messaging/v2/service/role.rb +27 -14
- data/lib/twilio-ruby/rest/ip_messaging/v2/service/user.rb +30 -17
- data/lib/twilio-ruby/rest/ip_messaging/v2/service/user/user_channel.rb +18 -5
- data/lib/twilio-ruby/rest/lookups.rb +2 -2
- data/lib/twilio-ruby/rest/lookups/v1/phone_number.rb +6 -6
- data/lib/twilio-ruby/rest/messaging.rb +2 -2
- data/lib/twilio-ruby/rest/messaging/v1/service.rb +30 -17
- data/lib/twilio-ruby/rest/messaging/v1/service/alpha_sender.rb +24 -11
- data/lib/twilio-ruby/rest/messaging/v1/service/phone_number.rb +24 -11
- data/lib/twilio-ruby/rest/messaging/v1/service/short_code.rb +24 -11
- data/lib/twilio-ruby/rest/monitor.rb +4 -4
- data/lib/twilio-ruby/rest/monitor/v1/alert.rb +23 -10
- data/lib/twilio-ruby/rest/monitor/v1/event.rb +22 -9
- data/lib/twilio-ruby/rest/notify.rb +4 -4
- data/lib/twilio-ruby/rest/notify/v1/credential.rb +30 -17
- data/lib/twilio-ruby/rest/notify/v1/service.rb +32 -19
- data/lib/twilio-ruby/rest/notify/v1/service/binding.rb +27 -14
- data/lib/twilio-ruby/rest/notify/v1/service/notification.rb +5 -5
- data/lib/twilio-ruby/rest/notify/v1/service/segment.rb +18 -5
- data/lib/twilio-ruby/rest/notify/v1/service/user.rb +27 -14
- data/lib/twilio-ruby/rest/notify/v1/service/user/segment_memberships.rb +7 -7
- data/lib/twilio-ruby/rest/notify/v1/service/user/user_binding.rb +27 -14
- data/lib/twilio-ruby/rest/preview.rb +18 -18
- data/lib/twilio-ruby/rest/preview/bulk_exports/export.rb +3 -3
- data/lib/twilio-ruby/rest/preview/bulk_exports/export/day.rb +18 -5
- data/lib/twilio-ruby/rest/preview/bulk_exports/export_configuration.rb +8 -8
- data/lib/twilio-ruby/rest/preview/hosted_numbers/hosted_number_order.rb +32 -19
- data/lib/twilio-ruby/rest/preview/marketplace/available_add_on.rb +20 -7
- data/lib/twilio-ruby/rest/preview/marketplace/available_add_on/available_add_on_extension.rb +20 -7
- data/lib/twilio-ruby/rest/preview/marketplace/installed_add_on.rb +30 -17
- data/lib/twilio-ruby/rest/preview/marketplace/installed_add_on/installed_add_on_extension.rb +23 -10
- data/lib/twilio-ruby/rest/preview/proxy/service.rb +30 -17
- data/lib/twilio-ruby/rest/preview/proxy/service/phone_number.rb +24 -11
- data/lib/twilio-ruby/rest/preview/proxy/service/session.rb +32 -19
- data/lib/twilio-ruby/rest/preview/proxy/service/session/interaction.rb +22 -9
- data/lib/twilio-ruby/rest/preview/proxy/service/session/participant.rb +32 -19
- data/lib/twilio-ruby/rest/preview/proxy/service/session/participant/message_interaction.rb +24 -11
- data/lib/twilio-ruby/rest/preview/proxy/service/short_code.rb +24 -11
- data/lib/twilio-ruby/rest/preview/sync/service.rb +30 -17
- data/lib/twilio-ruby/rest/preview/sync/service/document.rb +28 -15
- data/lib/twilio-ruby/rest/preview/sync/service/document/document_permission.rb +24 -11
- data/lib/twilio-ruby/rest/preview/sync/service/sync_list.rb +25 -12
- data/lib/twilio-ruby/rest/preview/sync/service/sync_list/sync_list_item.rb +29 -16
- data/lib/twilio-ruby/rest/preview/sync/service/sync_list/sync_list_permission.rb +24 -11
- data/lib/twilio-ruby/rest/preview/sync/service/sync_map.rb +25 -12
- data/lib/twilio-ruby/rest/preview/sync/service/sync_map/sync_map_item.rb +29 -16
- data/lib/twilio-ruby/rest/preview/sync/service/sync_map/sync_map_permission.rb +24 -11
- data/lib/twilio-ruby/rest/preview/wireless/command.rb +26 -13
- data/lib/twilio-ruby/rest/preview/wireless/rate_plan.rb +30 -17
- data/lib/twilio-ruby/rest/preview/wireless/sim.rb +28 -15
- data/lib/twilio-ruby/rest/preview/wireless/sim/usage.rb +6 -6
- data/lib/twilio-ruby/rest/pricing.rb +3 -3
- data/lib/twilio-ruby/rest/pricing/v1/messaging.rb +1 -1
- data/lib/twilio-ruby/rest/pricing/v1/messaging/country.rb +20 -7
- data/lib/twilio-ruby/rest/pricing/v1/phone_number.rb +1 -1
- data/lib/twilio-ruby/rest/pricing/v1/phone_number/country.rb +20 -7
- data/lib/twilio-ruby/rest/pricing/v1/voice.rb +1 -1
- data/lib/twilio-ruby/rest/pricing/v1/voice/country.rb +20 -7
- data/lib/twilio-ruby/rest/pricing/v1/voice/number.rb +3 -3
- data/lib/twilio-ruby/rest/sync.rb +2 -2
- data/lib/twilio-ruby/rest/sync/v1/service.rb +30 -17
- data/lib/twilio-ruby/rest/sync/v1/service/document.rb +28 -15
- data/lib/twilio-ruby/rest/sync/v1/service/document/document_permission.rb +24 -11
- data/lib/twilio-ruby/rest/sync/v1/service/sync_list.rb +25 -12
- data/lib/twilio-ruby/rest/sync/v1/service/sync_list/sync_list_item.rb +29 -16
- data/lib/twilio-ruby/rest/sync/v1/service/sync_list/sync_list_permission.rb +24 -11
- data/lib/twilio-ruby/rest/sync/v1/service/sync_map.rb +25 -12
- data/lib/twilio-ruby/rest/sync/v1/service/sync_map/sync_map_item.rb +29 -16
- data/lib/twilio-ruby/rest/sync/v1/service/sync_map/sync_map_permission.rb +24 -11
- data/lib/twilio-ruby/rest/taskrouter.rb +2 -2
- data/lib/twilio-ruby/rest/taskrouter/v1/workspace.rb +33 -20
- data/lib/twilio-ruby/rest/taskrouter/v1/workspace/activity.rb +32 -19
- data/lib/twilio-ruby/rest/taskrouter/v1/workspace/event.rb +22 -9
- data/lib/twilio-ruby/rest/taskrouter/v1/workspace/task.rb +32 -19
- data/lib/twilio-ruby/rest/taskrouter/v1/workspace/task/reservation.rb +27 -14
- data/lib/twilio-ruby/rest/taskrouter/v1/workspace/task_channel.rb +20 -7
- data/lib/twilio-ruby/rest/taskrouter/v1/workspace/task_queue.rb +33 -20
- data/lib/twilio-ruby/rest/taskrouter/v1/workspace/task_queue/task_queue_statistics.rb +6 -6
- data/lib/twilio-ruby/rest/taskrouter/v1/workspace/task_queue/task_queues_statistics.rb +20 -7
- data/lib/twilio-ruby/rest/taskrouter/v1/workspace/worker.rb +33 -20
- data/lib/twilio-ruby/rest/taskrouter/v1/workspace/worker/reservation.rb +27 -14
- data/lib/twilio-ruby/rest/taskrouter/v1/workspace/worker/worker_channel.rb +25 -12
- data/lib/twilio-ruby/rest/taskrouter/v1/workspace/worker/worker_statistics.rb +6 -6
- data/lib/twilio-ruby/rest/taskrouter/v1/workspace/worker/workers_statistics.rb +6 -6
- data/lib/twilio-ruby/rest/taskrouter/v1/workspace/workflow.rb +33 -20
- data/lib/twilio-ruby/rest/taskrouter/v1/workspace/workflow/workflow_statistics.rb +6 -6
- data/lib/twilio-ruby/rest/taskrouter/v1/workspace/workspace_statistics.rb +6 -6
- data/lib/twilio-ruby/rest/trunking.rb +2 -2
- data/lib/twilio-ruby/rest/trunking/v1/trunk.rb +30 -17
- data/lib/twilio-ruby/rest/trunking/v1/trunk/credential_list.rb +24 -11
- data/lib/twilio-ruby/rest/trunking/v1/trunk/ip_access_control_list.rb +24 -11
- data/lib/twilio-ruby/rest/trunking/v1/trunk/origination_url.rb +29 -16
- data/lib/twilio-ruby/rest/trunking/v1/trunk/phone_number.rb +24 -11
- data/lib/twilio-ruby/rest/video.rb +4 -4
- data/lib/twilio-ruby/rest/video/v1/recording.rb +23 -10
- data/lib/twilio-ruby/rest/video/v1/room.rb +29 -16
- data/lib/twilio-ruby/rest/video/v1/room/recording.rb +20 -7
- data/lib/twilio-ruby/rest/wireless.rb +6 -6
- data/lib/twilio-ruby/rest/wireless/v1/command.rb +26 -13
- data/lib/twilio-ruby/rest/wireless/v1/rate_plan.rb +30 -17
- data/lib/twilio-ruby/rest/wireless/v1/sim.rb +27 -14
- data/lib/twilio-ruby/rest/wireless/v1/sim/usage_record.rb +20 -7
- data/lib/twilio-ruby/twiml/messaging_response.rb +147 -0
- data/lib/twilio-ruby/twiml/twiml.rb +77 -0
- data/lib/twilio-ruby/twiml/voice_response.rb +925 -0
- data/lib/twilio-ruby/version.rb +1 -1
- data/spec/holodeck/hologram.rb +0 -1
- data/spec/jwt/access_token_spec.rb +126 -182
- data/spec/jwt/client_capability_spec.rb +104 -0
- data/spec/jwt/task_router_spec.rb +164 -97
- data/spec/twiml/messaging_response_spec.rb +62 -0
- data/spec/twiml/voice_response_spec.rb +452 -0
- data/twilio-ruby.gemspec +4 -2
- metadata +36 -23
- data/lib/twilio-ruby/compatibility/v2010/account/call/feedback.rb +0 -15
- data/lib/twilio-ruby/compatibility/v2010/account/queue/member.rb +0 -23
- data/lib/twilio-ruby/jwt/capability.rb +0 -64
- data/lib/twilio-ruby/twiml/response.rb +0 -16
- data/spec/jwt/capability_spec.rb +0 -186
- data/spec/jwt/task_router_taskqueue_spec.rb +0 -111
- data/spec/jwt/task_router_worker_spec.rb +0 -146
- data/spec/jwt/task_router_workspace_spec.rb +0 -110
- data/spec/twiml/twiml_response_spec.rb +0 -47
@@ -0,0 +1,98 @@
|
|
1
|
+
module Twilio
|
2
|
+
module JWT
|
3
|
+
class ClientCapability < BaseJWT
|
4
|
+
attr_accessor :account_sid,
|
5
|
+
:auth_token,
|
6
|
+
:client_name,
|
7
|
+
:scopes
|
8
|
+
|
9
|
+
def initialize(account_sid, auth_token, scopes: [], nbf: nil, ttl: 3600, valid_until: nil)
|
10
|
+
super(secret_key: auth_token, issuer: account_sid, nbf: nbf, ttl: ttl, valid_until: valid_until)
|
11
|
+
@account_sid = account_sid
|
12
|
+
@auth_token = auth_token
|
13
|
+
@client_name = nil
|
14
|
+
@scopes = scopes
|
15
|
+
end
|
16
|
+
|
17
|
+
def add_scope(scope)
|
18
|
+
@scopes.push(scope)
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_s
|
22
|
+
self.to_jwt
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
def _generate_payload
|
27
|
+
|
28
|
+
scope = ''
|
29
|
+
unless @scopes.empty?
|
30
|
+
scope = @scopes.map {|scope| scope._generate_payload}.join(' ')
|
31
|
+
end
|
32
|
+
|
33
|
+
payload = {
|
34
|
+
scope: scope
|
35
|
+
}
|
36
|
+
|
37
|
+
payload
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
module Scope
|
42
|
+
def _generate_payload
|
43
|
+
raise 'Not Implemented'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class IncomingClientScope
|
48
|
+
include Scope
|
49
|
+
|
50
|
+
def initialize(client_name)
|
51
|
+
@client_name = client_name
|
52
|
+
end
|
53
|
+
|
54
|
+
def _generate_payload
|
55
|
+
"scope:client:incoming?clientName" + CGI.escape("=#{@client_name}")
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
class OutgoingClientScope
|
61
|
+
include Scope
|
62
|
+
|
63
|
+
def initialize(application_sid, client_name = nil, params = {})
|
64
|
+
@application_sid = application_sid
|
65
|
+
@client_name = client_name
|
66
|
+
@params = params
|
67
|
+
end
|
68
|
+
|
69
|
+
def _generate_payload
|
70
|
+
prefix = "scope:client:outgoing"
|
71
|
+
application_sid = "appSid=#{@application_sid}"
|
72
|
+
unless @client_name.nil?
|
73
|
+
client_name = "clientName=#{@client_name}"
|
74
|
+
end
|
75
|
+
unless @params.empty?
|
76
|
+
params = "appParams=" + @params.map {|k, v| "#{k}=#{v}"}.join('&')
|
77
|
+
end
|
78
|
+
|
79
|
+
suffix = CGI.escape([application_sid, client_name, params].compact.join('&'))
|
80
|
+
|
81
|
+
[prefix, suffix].join('?')
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
class EventStreamScope
|
86
|
+
include Scope
|
87
|
+
|
88
|
+
def initialize(filters = {})
|
89
|
+
@filters = filters
|
90
|
+
@filters[:path] = '/2010-04-01/Events'
|
91
|
+
end
|
92
|
+
|
93
|
+
def _generate_payload
|
94
|
+
"scope:stream:subscribe?" + CGI.escape(@filters.map {|k, v| "#{k}=#{v}"}.join('&'))
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Twilio
|
2
|
+
module JWT
|
3
|
+
class BaseJWT
|
4
|
+
# valid_until overrides ttl if specified
|
5
|
+
def initialize(secret_key: nil, issuer: nil, subject: nil, nbf: nil, ttl: 3600, valid_until: nil)
|
6
|
+
if secret_key.nil?
|
7
|
+
raise ArgumentError, 'JWT does not have a signing key'
|
8
|
+
end
|
9
|
+
|
10
|
+
@secret_key = secret_key
|
11
|
+
@issuer = issuer
|
12
|
+
@subject = subject
|
13
|
+
@algorithm = 'HS256'
|
14
|
+
@nbf = nbf
|
15
|
+
@ttl = ttl
|
16
|
+
@valid_until = valid_until
|
17
|
+
end
|
18
|
+
|
19
|
+
def _generate_headers
|
20
|
+
{}
|
21
|
+
end
|
22
|
+
|
23
|
+
def _generate_payload
|
24
|
+
fail NotImplementedError
|
25
|
+
end
|
26
|
+
|
27
|
+
def headers
|
28
|
+
headers = self._generate_headers.clone()
|
29
|
+
headers[:typ] = 'JWT'
|
30
|
+
headers[:alg] = @algorithm
|
31
|
+
headers
|
32
|
+
end
|
33
|
+
|
34
|
+
def payload
|
35
|
+
payload = self._generate_payload.clone()
|
36
|
+
|
37
|
+
payload[:iss] = @issuer
|
38
|
+
payload[:nbf] = @nbf || Time.now.to_i
|
39
|
+
|
40
|
+
if @valid_until.nil?
|
41
|
+
payload[:exp] = Time.now.to_i + @ttl
|
42
|
+
else
|
43
|
+
payload[:exp] = @valid_until
|
44
|
+
end
|
45
|
+
|
46
|
+
payload[:sub] = @subject unless @subject.nil?
|
47
|
+
payload
|
48
|
+
end
|
49
|
+
|
50
|
+
def to_jwt
|
51
|
+
::JWT.encode self.payload, @secret_key, @algorithm, self.headers
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -1,202 +1,171 @@
|
|
1
1
|
module Twilio
|
2
2
|
module JWT
|
3
|
-
class TaskRouterCapability
|
4
|
-
TASK_ROUTER_BASE_URL = 'https://taskrouter.twilio.com'
|
3
|
+
class TaskRouterCapability < BaseJWT
|
5
4
|
TASK_ROUTER_VERSION = 'v1'
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
def initialize(account_sid, auth_token, workspace_sid, channel_id, nbf: nil, ttl: 3600, valid_until: nil)
|
6
|
+
super(secret_key: auth_token,
|
7
|
+
issuer: account_sid,
|
8
|
+
nbf: nbf,
|
9
|
+
ttl: ttl,
|
10
|
+
valid_until: valid_until
|
11
|
+
)
|
12
12
|
@account_sid = account_sid
|
13
13
|
@auth_token = auth_token
|
14
|
-
@policies = []
|
15
|
-
|
16
14
|
@workspace_sid = workspace_sid
|
17
15
|
@channel_id = channel_id
|
18
|
-
|
19
|
-
@base_url = "#{TASK_ROUTER_BASE_URL}/#{TASK_ROUTER_VERSION}/Workspaces/#{workspace_sid}"
|
20
|
-
|
21
|
-
validate_jwt
|
22
|
-
|
23
|
-
setup_resource
|
24
|
-
|
25
|
-
allow_websocket_requests(@channel_id)
|
26
|
-
allow(@resource_url, 'GET')
|
27
|
-
end
|
28
|
-
|
29
|
-
def allow_fetch_subresources
|
30
|
-
allow(@resource_url + '/**', 'GET')
|
31
|
-
end
|
32
|
-
|
33
|
-
def allow_updates
|
34
|
-
allow(@resource_url, 'POST')
|
35
|
-
end
|
36
|
-
|
37
|
-
def allow_updates_subresources
|
38
|
-
allow(@resource_url + '/**', 'POST')
|
39
|
-
end
|
40
|
-
|
41
|
-
def allow_delete
|
42
|
-
allow(@resource_url, 'DELETE')
|
43
|
-
end
|
44
|
-
|
45
|
-
def allow_delete_subresources
|
46
|
-
allow(@resource_url + '/**', 'DELETE')
|
16
|
+
@policies = []
|
47
17
|
end
|
48
18
|
|
49
|
-
def add_policy(
|
50
|
-
policy = {
|
51
|
-
url: url,
|
52
|
-
method: method,
|
53
|
-
query_filter: query_filters || {},
|
54
|
-
post_filter: post_filters || {},
|
55
|
-
allow: allowed
|
56
|
-
}
|
57
|
-
|
19
|
+
def add_policy(policy)
|
58
20
|
@policies.push(policy)
|
59
21
|
end
|
60
22
|
|
61
|
-
def
|
62
|
-
|
23
|
+
def to_s
|
24
|
+
to_jwt
|
63
25
|
end
|
64
26
|
|
65
|
-
|
66
|
-
|
67
|
-
|
27
|
+
protected
|
28
|
+
def _generate_payload
|
29
|
+
Twilio::JWT::TaskRouterUtils.web_socket_policies(@account_sid, @channel_id).each {|policy| self.add_policy(policy)}
|
30
|
+
policies = @policies.map{ |policy| policy._generate_payload}
|
68
31
|
|
69
|
-
|
70
|
-
task_router_attributes = {
|
32
|
+
payload = {
|
71
33
|
account_sid: @account_sid,
|
72
34
|
workspace_sid: @workspace_sid,
|
73
|
-
channel: @channel_id
|
35
|
+
channel: @channel_id,
|
36
|
+
version: TASK_ROUTER_VERSION,
|
37
|
+
friendly_name: @channel_id,
|
38
|
+
policies: policies
|
74
39
|
}
|
75
40
|
|
76
41
|
if @channel_id[0..1] == 'WK'
|
77
|
-
|
42
|
+
payload[:worker_sid] = @channel_id
|
78
43
|
elsif @channel_id[0..1] == 'WQ'
|
79
|
-
|
44
|
+
payload[:taskqueue_sid] = @channel_id
|
80
45
|
end
|
81
46
|
|
82
|
-
|
47
|
+
payload
|
83
48
|
end
|
49
|
+
end
|
84
50
|
|
85
|
-
|
51
|
+
class Policy
|
52
|
+
attr_accessor :url,
|
53
|
+
:method,
|
54
|
+
:allowed,
|
55
|
+
:post_filters,
|
56
|
+
:query_filters
|
86
57
|
|
87
|
-
def
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
policies: @policies,
|
94
|
-
}
|
95
|
-
extra_attributes.each { |key, value|
|
96
|
-
payload[key] = value
|
97
|
-
}
|
98
|
-
|
99
|
-
::JWT.encode payload, @auth_token
|
58
|
+
def initialize(url, method, allowed, post_filters={}, query_filters={})
|
59
|
+
@url = url
|
60
|
+
@method = method
|
61
|
+
@allowed = allowed
|
62
|
+
@post_filters = post_filters
|
63
|
+
@query_filters = query_filters
|
100
64
|
end
|
101
65
|
|
102
|
-
def
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
66
|
+
def _generate_payload
|
67
|
+
policy = {
|
68
|
+
url: @url,
|
69
|
+
method: @method,
|
70
|
+
query_filter: @query_filters,
|
71
|
+
post_filter: @post_filters,
|
72
|
+
allow: @allowed
|
73
|
+
}
|
74
|
+
policy
|
75
|
+
end
|
110
76
|
|
111
|
-
|
112
|
-
allow(@tasks_url, 'GET')
|
77
|
+
end
|
113
78
|
|
114
|
-
|
115
|
-
|
79
|
+
class TaskRouterUtils
|
80
|
+
TASK_ROUTER_VERSION = 'v1'
|
81
|
+
TASK_ROUTER_BASE_URL = 'https://taskrouter.twilio.com'
|
82
|
+
TASK_ROUTER_WEBSOCKET_BASE_URL = 'https://event-bridge.twilio.com/v1/wschannels'
|
116
83
|
|
117
|
-
|
118
|
-
|
119
|
-
end
|
84
|
+
def self.workspaces
|
85
|
+
[TASK_ROUTER_BASE_URL, TASK_ROUTER_VERSION, 'Workspaces'].join('/')
|
120
86
|
end
|
121
87
|
|
122
|
-
def
|
123
|
-
|
124
|
-
['GET', 'POST'].each do |meth|
|
125
|
-
add_policy(worker_url, meth)
|
126
|
-
end
|
88
|
+
def self.workspace(worskspace_sid)
|
89
|
+
[TASK_ROUTER_BASE_URL, TASK_ROUTER_VERSION, 'Workspaces', worskspace_sid].join('/')
|
127
90
|
end
|
128
91
|
|
129
|
-
def
|
130
|
-
|
131
|
-
raise "Invalid AccountSid provided #{@account_sid}"
|
132
|
-
end
|
133
|
-
if @workspace_sid.nil? or @workspace_sid[0..1] != 'WS'
|
134
|
-
raise "Invalid WorkspaceSid provided #{@workspace_sid}"
|
135
|
-
end
|
136
|
-
if @channel_id.nil?
|
137
|
-
raise 'ChannelId not provided'
|
138
|
-
end
|
139
|
-
@prefix = @channel_id[0..1]
|
140
|
-
if @prefix != 'WS' and @prefix != 'WK' and @prefix != 'WQ'
|
141
|
-
raise "Invalid ChannelId provided: #{@channel_id}"
|
142
|
-
end
|
92
|
+
def self.all_workspaces
|
93
|
+
[TASK_ROUTER_BASE_URL, TASK_ROUTER_VERSION, 'Workspaces', '**'].join('/')
|
143
94
|
end
|
144
|
-
end
|
145
95
|
|
146
|
-
|
96
|
+
def self.tasks(workspace_sid)
|
97
|
+
[self.workspace(workspace_sid), 'Tasks'].join('/')
|
98
|
+
end
|
147
99
|
|
148
|
-
def
|
149
|
-
|
150
|
-
|
151
|
-
@activity_url = @base_url + '/Activities'
|
152
|
-
@worker_reservations_url = @resource_url + '/Reservations/**'
|
100
|
+
def self.task(workspace_sid, tasks_sid)
|
101
|
+
[self.workspace(workspace_sid), 'Tasks', tasks_sid].join('/')
|
102
|
+
end
|
153
103
|
|
154
|
-
|
155
|
-
|
156
|
-
allow(@worker_reservations_url, 'GET')
|
104
|
+
def self.all_tasks(workspace_sid)
|
105
|
+
[self.workspace(workspace_sid), 'Tasks', '**'].join('/')
|
157
106
|
end
|
158
107
|
|
159
|
-
def
|
160
|
-
|
108
|
+
def self.task_queues(workspace_sid)
|
109
|
+
[self.workspace(workspace_sid), 'TaskQueues'].join('/')
|
161
110
|
end
|
162
111
|
|
163
|
-
def
|
164
|
-
|
165
|
-
allow(@worker_reservations_url, 'POST', nil, nil)
|
112
|
+
def self.task_queue(workspace_sid, taskqueue_sid)
|
113
|
+
[self.workspace(workspace_sid), 'TaskQueues', taskqueue_sid].join('/')
|
166
114
|
end
|
167
115
|
|
168
|
-
|
116
|
+
def self.all_task_queues(workspace_sid)
|
117
|
+
[self.workspace(workspace_sid), 'TaskQueues', '**'].join('/')
|
118
|
+
end
|
169
119
|
|
170
|
-
def
|
171
|
-
|
120
|
+
def self.activities(workspace_sid)
|
121
|
+
[self.workspace(workspace_sid), 'Activities'].join('/')
|
172
122
|
end
|
173
123
|
|
174
|
-
|
124
|
+
def self.activity(workspace_sid, activity_sid)
|
125
|
+
[self.workspace(workspace_sid), 'Activities', activity_sid].join('/')
|
126
|
+
end
|
175
127
|
|
176
|
-
|
128
|
+
def self.all_activities(workspace_sid)
|
129
|
+
[self.workspace(workspace_sid), 'Activities', '**'].join('/')
|
130
|
+
end
|
177
131
|
|
178
|
-
def
|
179
|
-
|
132
|
+
def self.workers(workspace_sid)
|
133
|
+
[self.workspace(workspace_sid), 'Workers'].join('/')
|
180
134
|
end
|
181
135
|
|
182
|
-
|
136
|
+
def self.worker(workspace_sid, worker_sid)
|
137
|
+
[self.workspace(workspace_sid), 'Workers', worker_sid].join('/')
|
138
|
+
end
|
183
139
|
|
184
|
-
def
|
185
|
-
|
140
|
+
def self.all_workers(workspace_sid)
|
141
|
+
[self.workspace(workspace_sid), 'Workers', '**'].join('/')
|
186
142
|
end
|
187
143
|
|
188
|
-
|
144
|
+
def self.reservations(workspace_sid, worker_sid)
|
145
|
+
[self.worker(workspace_sid, worker_sid), 'Reservations'].join('/')
|
146
|
+
end
|
189
147
|
|
190
|
-
|
148
|
+
def self.reservation(workspace_sid, worker_sid, reservation_sid)
|
149
|
+
[self.worker(workspace_sid, worker_sid), 'Reservations', reservation_sid].join('/')
|
150
|
+
end
|
191
151
|
|
192
|
-
def
|
193
|
-
|
152
|
+
def self.all_reservations(workspace_sid, worker_sid)
|
153
|
+
[self.worker(workspace_sid, worker_sid), 'Reservations', '**'].join('/')
|
194
154
|
end
|
195
155
|
|
196
|
-
|
156
|
+
def self.web_socket_policies(account_sid, channel_sid)
|
157
|
+
url = [TASK_ROUTER_WEBSOCKET_BASE_URL, account_sid, channel_sid].join('/')
|
158
|
+
get = Policy.new(url, 'GET', true)
|
159
|
+
post = Policy.new(url, 'POST', true)
|
160
|
+
[get, post]
|
161
|
+
end
|
197
162
|
|
198
|
-
def
|
199
|
-
|
163
|
+
def self.worker_policies(workspace_sid, worker_sid)
|
164
|
+
activities = Policy.new(self.activities(workspace_sid), 'GET', true)
|
165
|
+
tasks = Policy.new(self.all_tasks(workspace_sid), 'GET', true)
|
166
|
+
reservations = Policy.new(self.all_reservations(workspace_sid, worker_sid), 'GET', true)
|
167
|
+
fetch = Policy.new(self.worker(workspace_sid, worker_sid), 'GET', true)
|
168
|
+
[activities, tasks, reservations, fetch]
|
200
169
|
end
|
201
170
|
end
|
202
171
|
end
|