twilio-ruby 3.11.5 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -1
- data/.rubocop.yml +21 -0
- data/.rubocop_todo.yml +187 -0
- data/.travis.yml +10 -10
- data/AUTHORS.md +21 -0
- data/CHANGES.md +351 -0
- data/Gemfile +8 -1
- data/{LICENSE → LICENSE.md} +13 -11
- data/Makefile +15 -3
- data/README.md +90 -95
- data/Rakefile +59 -7
- data/VERSIONS.md +64 -0
- data/examples/examples.rb +62 -49
- data/examples/{print-call-log.rb → print_call_log.rb} +7 -7
- data/lib/rack/twilio_webhook_authentication.rb +46 -0
- data/lib/twilio-ruby/framework/domain.rb +34 -0
- data/lib/twilio-ruby/framework/error.rb +30 -0
- data/lib/twilio-ruby/framework/helper.rb +9 -0
- data/lib/twilio-ruby/framework/page.rb +101 -0
- data/lib/twilio-ruby/framework/resource.rb +21 -0
- data/lib/twilio-ruby/framework/serialize.rb +70 -0
- data/lib/twilio-ruby/framework/twilio_response.rb +15 -0
- data/lib/twilio-ruby/framework/values.rb +7 -0
- data/lib/twilio-ruby/framework/version.rb +164 -0
- data/lib/twilio-ruby/http/http_client.rb +46 -0
- data/lib/twilio-ruby/jwt/access_token.rb +232 -0
- data/lib/twilio-ruby/jwt/client_capability.rb +102 -0
- data/lib/twilio-ruby/jwt/jwt.rb +50 -0
- data/lib/twilio-ruby/jwt/task_router.rb +174 -0
- data/lib/twilio-ruby/rest/accounts/v1/credential/public_key.rb +370 -0
- data/lib/twilio-ruby/rest/accounts/v1/credential.rb +105 -0
- data/lib/twilio-ruby/rest/accounts/v1.rb +39 -0
- data/lib/twilio-ruby/rest/accounts.rb +36 -9
- data/lib/twilio-ruby/rest/api/v2010/account/address/dependent_phone_number.rb +265 -0
- data/lib/twilio-ruby/rest/api/v2010/account/address.rb +509 -0
- data/lib/twilio-ruby/rest/api/v2010/account/application.rb +620 -0
- data/lib/twilio-ruby/rest/api/v2010/account/authorized_connect_app.rb +331 -0
- data/lib/twilio-ruby/rest/api/v2010/account/available_phone_number/local.rb +389 -0
- data/lib/twilio-ruby/rest/api/v2010/account/available_phone_number/mobile.rb +389 -0
- data/lib/twilio-ruby/rest/api/v2010/account/available_phone_number/toll_free.rb +389 -0
- data/lib/twilio-ruby/rest/api/v2010/account/available_phone_number.rb +370 -0
- data/lib/twilio-ruby/rest/api/v2010/account/call/feedback.rb +296 -0
- data/lib/twilio-ruby/rest/api/v2010/account/call/feedback_summary.rb +317 -0
- data/lib/twilio-ruby/rest/api/v2010/account/call/notification.rb +427 -0
- data/lib/twilio-ruby/rest/api/v2010/account/call/recording.rb +379 -0
- data/lib/twilio-ruby/rest/api/v2010/account/call.rb +799 -0
- data/lib/twilio-ruby/rest/api/v2010/account/conference/participant.rb +515 -0
- data/lib/twilio-ruby/rest/api/v2010/account/conference.rb +455 -0
- data/lib/twilio-ruby/rest/api/v2010/account/connect_app.rb +413 -0
- data/lib/twilio-ruby/rest/api/v2010/account/incoming_phone_number/local.rb +445 -0
- data/lib/twilio-ruby/rest/api/v2010/account/incoming_phone_number/mobile.rb +445 -0
- data/lib/twilio-ruby/rest/api/v2010/account/incoming_phone_number/toll_free.rb +445 -0
- data/lib/twilio-ruby/rest/api/v2010/account/incoming_phone_number.rb +786 -0
- data/lib/twilio-ruby/rest/api/v2010/account/key.rb +336 -0
- data/lib/twilio-ruby/rest/api/v2010/account/message/feedback.rb +165 -0
- data/lib/twilio-ruby/rest/api/v2010/account/message/media.rb +355 -0
- data/lib/twilio-ruby/rest/api/v2010/account/message.rb +583 -0
- data/lib/twilio-ruby/rest/api/v2010/account/new_key.rb +153 -0
- data/lib/twilio-ruby/rest/api/v2010/account/new_signing_key.rb +153 -0
- data/lib/twilio-ruby/rest/api/v2010/account/notification.rb +418 -0
- data/lib/twilio-ruby/rest/api/v2010/account/outgoing_caller_id.rb +377 -0
- data/lib/twilio-ruby/rest/api/v2010/account/queue/member.rb +345 -0
- data/lib/twilio-ruby/rest/api/v2010/account/queue.rb +438 -0
- data/lib/twilio-ruby/rest/api/v2010/account/recording/add_on_result/payload.rb +378 -0
- data/lib/twilio-ruby/rest/api/v2010/account/recording/add_on_result.rb +397 -0
- data/lib/twilio-ruby/rest/api/v2010/account/recording/transcription.rb +375 -0
- data/lib/twilio-ruby/rest/api/v2010/account/recording.rb +479 -0
- data/lib/twilio-ruby/rest/api/v2010/account/short_code.rb +430 -0
- data/lib/twilio-ruby/rest/api/v2010/account/signing_key.rb +336 -0
- data/lib/twilio-ruby/rest/api/v2010/account/sip/credential_list/credential.rb +395 -0
- data/lib/twilio-ruby/rest/api/v2010/account/sip/credential_list.rb +419 -0
- data/lib/twilio-ruby/rest/api/v2010/account/sip/domain/credential_list_mapping.rb +361 -0
- data/lib/twilio-ruby/rest/api/v2010/account/sip/domain/ip_access_control_list_mapping.rb +361 -0
- data/lib/twilio-ruby/rest/api/v2010/account/sip/domain.rb +570 -0
- data/lib/twilio-ruby/rest/api/v2010/account/sip/ip_access_control_list/ip_address.rb +406 -0
- data/lib/twilio-ruby/rest/api/v2010/account/sip/ip_access_control_list.rb +424 -0
- data/lib/twilio-ruby/rest/api/v2010/account/sip.rb +174 -0
- data/lib/twilio-ruby/rest/api/v2010/account/token.rb +168 -0
- data/lib/twilio-ruby/rest/api/v2010/account/transcription.rb +366 -0
- data/lib/twilio-ruby/rest/api/v2010/account/usage/record/all_time.rb +304 -0
- data/lib/twilio-ruby/rest/api/v2010/account/usage/record/daily.rb +304 -0
- data/lib/twilio-ruby/rest/api/v2010/account/usage/record/last_month.rb +304 -0
- data/lib/twilio-ruby/rest/api/v2010/account/usage/record/monthly.rb +304 -0
- data/lib/twilio-ruby/rest/api/v2010/account/usage/record/this_month.rb +304 -0
- data/lib/twilio-ruby/rest/api/v2010/account/usage/record/today.rb +304 -0
- data/lib/twilio-ruby/rest/api/v2010/account/usage/record/yearly.rb +304 -0
- data/lib/twilio-ruby/rest/api/v2010/account/usage/record/yesterday.rb +304 -0
- data/lib/twilio-ruby/rest/api/v2010/account/usage/record.rb +418 -0
- data/lib/twilio-ruby/rest/api/v2010/account/usage/trigger.rb +507 -0
- data/lib/twilio-ruby/rest/api/v2010/account/usage.rb +127 -0
- data/lib/twilio-ruby/rest/api/v2010/account/validation_request.rb +161 -0
- data/lib/twilio-ruby/rest/api/v2010/account.rb +1098 -0
- data/lib/twilio-ruby/rest/api/v2010.rb +147 -0
- data/lib/twilio-ruby/rest/api.rb +234 -0
- data/lib/twilio-ruby/rest/chat/v1/credential.rb +403 -0
- data/lib/twilio-ruby/rest/chat/v1/service/channel/invite.rb +386 -0
- data/lib/twilio-ruby/rest/chat/v1/service/channel/member.rb +431 -0
- data/lib/twilio-ruby/rest/chat/v1/service/channel/message.rb +447 -0
- data/lib/twilio-ruby/rest/chat/v1/service/channel.rb +554 -0
- data/lib/twilio-ruby/rest/chat/v1/service/role.rb +396 -0
- data/lib/twilio-ruby/rest/chat/v1/service/user/user_channel.rb +244 -0
- data/lib/twilio-ruby/rest/chat/v1/service/user.rb +467 -0
- data/lib/twilio-ruby/rest/chat/v1/service.rb +935 -0
- data/lib/twilio-ruby/rest/chat/v1.rb +56 -0
- data/lib/twilio-ruby/rest/chat/v2/credential.rb +403 -0
- data/lib/twilio-ruby/rest/chat/v2/service/channel/invite.rb +386 -0
- data/lib/twilio-ruby/rest/chat/v2/service/channel/member.rb +431 -0
- data/lib/twilio-ruby/rest/chat/v2/service/channel/message.rb +447 -0
- data/lib/twilio-ruby/rest/chat/v2/service/channel.rb +554 -0
- data/lib/twilio-ruby/rest/chat/v2/service/role.rb +396 -0
- data/lib/twilio-ruby/rest/chat/v2/service/user/user_channel.rb +244 -0
- data/lib/twilio-ruby/rest/chat/v2/service/user.rb +467 -0
- data/lib/twilio-ruby/rest/chat/v2/service.rb +688 -0
- data/lib/twilio-ruby/rest/chat/v2.rb +56 -0
- data/lib/twilio-ruby/rest/chat.rb +59 -0
- data/lib/twilio-ruby/rest/client.rb +307 -215
- data/lib/twilio-ruby/rest/ip_messaging/v1/credential.rb +403 -0
- data/lib/twilio-ruby/rest/ip_messaging/v1/service/channel/invite.rb +386 -0
- data/lib/twilio-ruby/rest/ip_messaging/v1/service/channel/member.rb +431 -0
- data/lib/twilio-ruby/rest/ip_messaging/v1/service/channel/message.rb +447 -0
- data/lib/twilio-ruby/rest/ip_messaging/v1/service/channel.rb +554 -0
- data/lib/twilio-ruby/rest/ip_messaging/v1/service/role.rb +396 -0
- data/lib/twilio-ruby/rest/ip_messaging/v1/service/user/user_channel.rb +244 -0
- data/lib/twilio-ruby/rest/ip_messaging/v1/service/user.rb +467 -0
- data/lib/twilio-ruby/rest/ip_messaging/v1/service.rb +935 -0
- data/lib/twilio-ruby/rest/ip_messaging/v1.rb +56 -0
- data/lib/twilio-ruby/rest/ip_messaging/v2/credential.rb +403 -0
- data/lib/twilio-ruby/rest/ip_messaging/v2/service/channel/invite.rb +386 -0
- data/lib/twilio-ruby/rest/ip_messaging/v2/service/channel/member.rb +431 -0
- data/lib/twilio-ruby/rest/ip_messaging/v2/service/channel/message.rb +447 -0
- data/lib/twilio-ruby/rest/ip_messaging/v2/service/channel.rb +554 -0
- data/lib/twilio-ruby/rest/ip_messaging/v2/service/role.rb +396 -0
- data/lib/twilio-ruby/rest/ip_messaging/v2/service/user/user_channel.rb +244 -0
- data/lib/twilio-ruby/rest/ip_messaging/v2/service/user.rb +467 -0
- data/lib/twilio-ruby/rest/ip_messaging/v2/service.rb +688 -0
- data/lib/twilio-ruby/rest/ip_messaging/v2.rb +56 -0
- data/lib/twilio-ruby/rest/ip_messaging.rb +59 -0
- data/lib/twilio-ruby/rest/lookups/v1/phone_number.rb +224 -0
- data/lib/twilio-ruby/rest/lookups/v1.rb +41 -0
- data/lib/twilio-ruby/rest/lookups.rb +44 -0
- data/lib/twilio-ruby/rest/monitor/v1/alert.rb +398 -0
- data/lib/twilio-ruby/rest/monitor/v1/event.rb +381 -0
- data/lib/twilio-ruby/rest/monitor/v1.rb +56 -0
- data/lib/twilio-ruby/rest/monitor.rb +52 -0
- data/lib/twilio-ruby/rest/pricing/v1/messaging/country.rb +291 -0
- data/lib/twilio-ruby/rest/pricing/v1/messaging.rb +129 -0
- data/lib/twilio-ruby/rest/pricing/v1/phone_number/country.rb +284 -0
- data/lib/twilio-ruby/rest/pricing/v1/phone_number.rb +129 -0
- data/lib/twilio-ruby/rest/pricing/v1/voice/country.rb +291 -0
- data/lib/twilio-ruby/rest/pricing/v1/voice/number.rb +208 -0
- data/lib/twilio-ruby/rest/pricing/v1/voice.rb +150 -0
- data/lib/twilio-ruby/rest/pricing/v1.rb +65 -0
- data/lib/twilio-ruby/rest/pricing.rb +54 -0
- data/lib/twilio-ruby/rest/taskrouter/v1/workspace/activity.rb +399 -0
- data/lib/twilio-ruby/rest/taskrouter/v1/workspace/event.rb +418 -0
- data/lib/twilio-ruby/rest/taskrouter/v1/workspace/task/reservation.rb +461 -0
- data/lib/twilio-ruby/rest/taskrouter/v1/workspace/task.rb +584 -0
- data/lib/twilio-ruby/rest/taskrouter/v1/workspace/task_channel.rb +315 -0
- data/lib/twilio-ruby/rest/taskrouter/v1/workspace/task_queue/task_queue_statistics.rb +230 -0
- data/lib/twilio-ruby/rest/taskrouter/v1/workspace/task_queue/task_queues_statistics.rb +243 -0
- data/lib/twilio-ruby/rest/taskrouter/v1/workspace/task_queue.rb +527 -0
- data/lib/twilio-ruby/rest/taskrouter/v1/workspace/worker/reservation.rb +461 -0
- data/lib/twilio-ruby/rest/taskrouter/v1/workspace/worker/worker_channel.rb +406 -0
- data/lib/twilio-ruby/rest/taskrouter/v1/workspace/worker/worker_statistics.rb +223 -0
- data/lib/twilio-ruby/rest/taskrouter/v1/workspace/worker/workers_statistics.rb +226 -0
- data/lib/twilio-ruby/rest/taskrouter/v1/workspace/worker.rb +585 -0
- data/lib/twilio-ruby/rest/taskrouter/v1/workspace/workflow/workflow_statistics.rb +230 -0
- data/lib/twilio-ruby/rest/taskrouter/v1/workspace/workflow.rb +475 -0
- data/lib/twilio-ruby/rest/taskrouter/v1/workspace/workspace_statistics.rb +212 -0
- data/lib/twilio-ruby/rest/taskrouter/v1/workspace.rb +712 -0
- data/lib/twilio-ruby/rest/taskrouter/v1.rb +41 -0
- data/lib/twilio-ruby/rest/taskrouter.rb +44 -0
- data/lib/twilio-ruby/rest/trunking/v1/trunk/credential_list.rb +345 -0
- data/lib/twilio-ruby/rest/trunking/v1/trunk/ip_access_control_list.rb +345 -0
- data/lib/twilio-ruby/rest/trunking/v1/trunk/origination_url.rb +430 -0
- data/lib/twilio-ruby/rest/trunking/v1/trunk/phone_number.rb +478 -0
- data/lib/twilio-ruby/rest/trunking/v1/trunk.rb +577 -0
- data/lib/twilio-ruby/rest/trunking/v1.rb +41 -0
- data/lib/twilio-ruby/rest/trunking.rb +44 -0
- data/lib/twilio-ruby/rest/video/v1/recording.rb +382 -0
- data/lib/twilio-ruby/rest/video/v1/room/recording.rb +381 -0
- data/lib/twilio-ruby/rest/video/v1/room.rb +485 -0
- data/lib/twilio-ruby/rest/video/v1.rb +56 -0
- data/lib/twilio-ruby/rest/video.rb +52 -0
- data/lib/twilio-ruby/security/request_validator.rb +54 -0
- data/lib/twilio-ruby/twiml/messaging_response.rb +141 -0
- data/lib/twilio-ruby/twiml/twiml.rb +69 -0
- data/lib/twilio-ruby/twiml/voice_response.rb +916 -0
- data/lib/twilio-ruby/util/configuration.rb +7 -0
- data/lib/twilio-ruby/util.rb +1 -1
- data/lib/twilio-ruby/version.rb +1 -1
- data/lib/twilio-ruby.rb +52 -49
- data/spec/framework/serialize_spec.rb +59 -0
- data/spec/holodeck/holodeck.rb +61 -0
- data/spec/holodeck/hologram.rb +4 -0
- data/spec/integration/accounts/v1/credential/public_key_spec.rb +226 -0
- data/spec/integration/accounts/v1/credential_spec.rb +10 -0
- data/spec/integration/api/v2010/account/address/dependent_phone_number_spec.rb +90 -0
- data/spec/integration/api/v2010/account/address_spec.rb +267 -0
- data/spec/integration/api/v2010/account/application_spec.rb +286 -0
- data/spec/integration/api/v2010/account/authorized_connect_app_spec.rb +137 -0
- data/spec/integration/api/v2010/account/available_phone_number/local_spec.rb +101 -0
- data/spec/integration/api/v2010/account/available_phone_number/mobile_spec.rb +100 -0
- data/spec/integration/api/v2010/account/available_phone_number/toll_free_spec.rb +100 -0
- data/spec/integration/api/v2010/account/available_phone_number_spec.rb +128 -0
- data/spec/integration/api/v2010/account/call/feedback_spec.rb +141 -0
- data/spec/integration/api/v2010/account/call/feedback_summary_spec.rb +149 -0
- data/spec/integration/api/v2010/account/call/notification_spec.rb +179 -0
- data/spec/integration/api/v2010/account/call/recording_spec.rb +178 -0
- data/spec/integration/api/v2010/account/call_spec.rb +319 -0
- data/spec/integration/api/v2010/account/conference/participant_spec.rb +283 -0
- data/spec/integration/api/v2010/account/conference_spec.rb +174 -0
- data/spec/integration/api/v2010/account/connect_app_spec.rb +177 -0
- data/spec/integration/api/v2010/account/incoming_phone_number/local_spec.rb +181 -0
- data/spec/integration/api/v2010/account/incoming_phone_number/mobile_spec.rb +181 -0
- data/spec/integration/api/v2010/account/incoming_phone_number/toll_free_spec.rb +181 -0
- data/spec/integration/api/v2010/account/incoming_phone_number_spec.rb +331 -0
- data/spec/integration/api/v2010/account/key_spec.rb +178 -0
- data/spec/integration/api/v2010/account/message/feedback_spec.rb +48 -0
- data/spec/integration/api/v2010/account/message/media_spec.rb +162 -0
- data/spec/integration/api/v2010/account/message_spec.rb +297 -0
- data/spec/integration/api/v2010/account/new_key_spec.rb +45 -0
- data/spec/integration/api/v2010/account/new_signing_key_spec.rb +45 -0
- data/spec/integration/api/v2010/account/notification_spec.rb +172 -0
- data/spec/integration/api/v2010/account/outgoing_caller_id_spec.rb +193 -0
- data/spec/integration/api/v2010/account/queue/member_spec.rb +170 -0
- data/spec/integration/api/v2010/account/queue_spec.rb +242 -0
- data/spec/integration/api/v2010/account/recording/add_on_result/payload_spec.rb +175 -0
- data/spec/integration/api/v2010/account/recording/add_on_result_spec.rb +166 -0
- data/spec/integration/api/v2010/account/recording/transcription_spec.rb +174 -0
- data/spec/integration/api/v2010/account/recording_spec.rb +179 -0
- data/spec/integration/api/v2010/account/short_code_spec.rb +180 -0
- data/spec/integration/api/v2010/account/signing_key_spec.rb +178 -0
- data/spec/integration/api/v2010/account/sip/credential_list/credential_spec.rb +257 -0
- data/spec/integration/api/v2010/account/sip/credential_list_spec.rb +246 -0
- data/spec/integration/api/v2010/account/sip/domain/credential_list_mapping_spec.rb +210 -0
- data/spec/integration/api/v2010/account/sip/domain/ip_access_control_list_mapping_spec.rb +220 -0
- data/spec/integration/api/v2010/account/sip/domain_spec.rb +283 -0
- data/spec/integration/api/v2010/account/sip/ip_access_control_list/ip_address_spec.rb +261 -0
- data/spec/integration/api/v2010/account/sip/ip_access_control_list_spec.rb +256 -0
- data/spec/integration/api/v2010/account/sip_spec.rb +10 -0
- data/spec/integration/api/v2010/account/token_spec.rb +56 -0
- data/spec/integration/api/v2010/account/transcription_spec.rb +167 -0
- data/spec/integration/api/v2010/account/usage/record/all_time_spec.rb +111 -0
- data/spec/integration/api/v2010/account/usage/record/daily_spec.rb +111 -0
- data/spec/integration/api/v2010/account/usage/record/last_month_spec.rb +111 -0
- data/spec/integration/api/v2010/account/usage/record/monthly_spec.rb +111 -0
- data/spec/integration/api/v2010/account/usage/record/this_month_spec.rb +111 -0
- data/spec/integration/api/v2010/account/usage/record/today_spec.rb +111 -0
- data/spec/integration/api/v2010/account/usage/record/yearly_spec.rb +111 -0
- data/spec/integration/api/v2010/account/usage/record/yesterday_spec.rb +111 -0
- data/spec/integration/api/v2010/account/usage/record_spec.rb +108 -0
- data/spec/integration/api/v2010/account/usage/trigger_spec.rb +283 -0
- data/spec/integration/api/v2010/account/usage_spec.rb +10 -0
- data/spec/integration/api/v2010/account/validation_request_spec.rb +48 -0
- data/spec/integration/api/v2010/account_spec.rb +254 -0
- data/spec/integration/chat/v1/credential_spec.rb +223 -0
- data/spec/integration/chat/v1/service/channel/invite_spec.rb +210 -0
- data/spec/integration/chat/v1/service/channel/member_spec.rb +284 -0
- data/spec/integration/chat/v1/service/channel/message_spec.rb +294 -0
- data/spec/integration/chat/v1/service/channel_spec.rb +275 -0
- data/spec/integration/chat/v1/service/role_spec.rb +263 -0
- data/spec/integration/chat/v1/service/user/user_channel_spec.rb +92 -0
- data/spec/integration/chat/v1/service/user_spec.rb +266 -0
- data/spec/integration/chat/v1/service_spec.rb +299 -0
- data/spec/integration/chat/v2/credential_spec.rb +223 -0
- data/spec/integration/chat/v2/service/channel/invite_spec.rb +210 -0
- data/spec/integration/chat/v2/service/channel/member_spec.rb +284 -0
- data/spec/integration/chat/v2/service/channel/message_spec.rb +294 -0
- data/spec/integration/chat/v2/service/channel_spec.rb +275 -0
- data/spec/integration/chat/v2/service/role_spec.rb +263 -0
- data/spec/integration/chat/v2/service/user/user_channel_spec.rb +92 -0
- data/spec/integration/chat/v2/service/user_spec.rb +266 -0
- data/spec/integration/chat/v2/service_spec.rb +325 -0
- data/spec/integration/ip_messaging/v1/credential_spec.rb +223 -0
- data/spec/integration/ip_messaging/v1/service/channel/invite_spec.rb +210 -0
- data/spec/integration/ip_messaging/v1/service/channel/member_spec.rb +284 -0
- data/spec/integration/ip_messaging/v1/service/channel/message_spec.rb +294 -0
- data/spec/integration/ip_messaging/v1/service/channel_spec.rb +275 -0
- data/spec/integration/ip_messaging/v1/service/role_spec.rb +263 -0
- data/spec/integration/ip_messaging/v1/service/user/user_channel_spec.rb +92 -0
- data/spec/integration/ip_messaging/v1/service/user_spec.rb +266 -0
- data/spec/integration/ip_messaging/v1/service_spec.rb +299 -0
- data/spec/integration/ip_messaging/v2/credential_spec.rb +223 -0
- data/spec/integration/ip_messaging/v2/service/channel/invite_spec.rb +210 -0
- data/spec/integration/ip_messaging/v2/service/channel/member_spec.rb +284 -0
- data/spec/integration/ip_messaging/v2/service/channel/message_spec.rb +294 -0
- data/spec/integration/ip_messaging/v2/service/channel_spec.rb +275 -0
- data/spec/integration/ip_messaging/v2/service/role_spec.rb +263 -0
- data/spec/integration/ip_messaging/v2/service/user/user_channel_spec.rb +92 -0
- data/spec/integration/ip_messaging/v2/service/user_spec.rb +266 -0
- data/spec/integration/ip_messaging/v2/service_spec.rb +325 -0
- data/spec/integration/lookups/v1/phone_number_spec.rb +60 -0
- data/spec/integration/monitor/v1/alert_spec.rb +161 -0
- data/spec/integration/monitor/v1/event_spec.rb +148 -0
- data/spec/integration/pricing/v1/messaging/country_spec.rb +137 -0
- data/spec/integration/pricing/v1/messaging_spec.rb +10 -0
- data/spec/integration/pricing/v1/phone_number/country_spec.rb +128 -0
- data/spec/integration/pricing/v1/phone_number_spec.rb +10 -0
- data/spec/integration/pricing/v1/voice/country_spec.rb +266 -0
- data/spec/integration/pricing/v1/voice/number_spec.rb +54 -0
- data/spec/integration/pricing/v1/voice_spec.rb +10 -0
- data/spec/integration/taskrouter/v1/workspace/activity_spec.rb +236 -0
- data/spec/integration/taskrouter/v1/workspace/event_spec.rb +157 -0
- data/spec/integration/taskrouter/v1/workspace/task/reservation_spec.rb +192 -0
- data/spec/integration/taskrouter/v1/workspace/task_channel_spec.rb +127 -0
- data/spec/integration/taskrouter/v1/workspace/task_queue/task_queue_statistics_spec.rb +106 -0
- data/spec/integration/taskrouter/v1/workspace/task_queue/task_queues_statistics_spec.rb +144 -0
- data/spec/integration/taskrouter/v1/workspace/task_queue_spec.rb +292 -0
- data/spec/integration/taskrouter/v1/workspace/task_spec.rb +324 -0
- data/spec/integration/taskrouter/v1/workspace/worker/reservation_spec.rb +192 -0
- data/spec/integration/taskrouter/v1/workspace/worker/worker_channel_spec.rb +201 -0
- data/spec/integration/taskrouter/v1/workspace/worker/worker_statistics_spec.rb +107 -0
- data/spec/integration/taskrouter/v1/workspace/worker/workers_statistics_spec.rb +141 -0
- data/spec/integration/taskrouter/v1/workspace/worker_spec.rb +282 -0
- data/spec/integration/taskrouter/v1/workspace/workflow/workflow_statistics_spec.rb +69 -0
- data/spec/integration/taskrouter/v1/workspace/workflow_spec.rb +265 -0
- data/spec/integration/taskrouter/v1/workspace/workspace_statistics_spec.rb +103 -0
- data/spec/integration/taskrouter/v1/workspace_spec.rb +287 -0
- data/spec/integration/trunking/v1/trunk/credential_list_spec.rb +192 -0
- data/spec/integration/trunking/v1/trunk/ip_access_control_list_spec.rb +192 -0
- data/spec/integration/trunking/v1/trunk/origination_url_spec.rb +250 -0
- data/spec/integration/trunking/v1/trunk/phone_number_spec.rb +267 -0
- data/spec/integration/trunking/v1/trunk_spec.rb +276 -0
- data/spec/integration/video/v1/recording_spec.rb +165 -0
- data/spec/integration/video/v1/room/recording_spec.rb +146 -0
- data/spec/integration/video/v1/room_spec.rb +237 -0
- data/spec/jwt/access_token_spec.rb +130 -0
- data/spec/jwt/client_capability_spec.rb +104 -0
- data/spec/jwt/task_router_spec.rb +172 -0
- data/spec/rack/twilio_webhook_authentication_spec.rb +106 -0
- data/spec/security/request_validator_spec.rb +113 -0
- data/spec/spec_helper.rb +29 -3
- data/spec/support/fakeweb.rb +2 -0
- data/spec/twilio_spec.rb +15 -0
- data/spec/twiml/messaging_response_spec.rb +90 -0
- data/spec/twiml/voice_response_spec.rb +474 -0
- data/spec/util/configuration_spec.rb +15 -0
- data/spec/util/url_encode_spec.rb +2 -2
- data/twilio-ruby.gemspec +32 -26
- metadata +502 -152
- data/CHANGES +0 -47
- data/docs/Makefile +0 -130
- data/docs/_themes/LICENSE +0 -45
- data/docs/_themes/README.rst +0 -25
- data/docs/_themes/flask_theme_support.py +0 -86
- data/docs/_themes/kr/layout.html +0 -32
- data/docs/_themes/kr/relations.html +0 -19
- data/docs/_themes/kr/static/flasky.css_t +0 -469
- data/docs/_themes/kr/static/small_flask.css +0 -70
- data/docs/_themes/kr/theme.conf +0 -7
- data/docs/_themes/kr_small/layout.html +0 -22
- data/docs/_themes/kr_small/static/flasky.css_t +0 -287
- data/docs/_themes/kr_small/theme.conf +0 -10
- data/docs/changelog.rst +0 -1
- data/docs/conf.py +0 -266
- data/docs/faq.rst +0 -42
- data/docs/getting-started.rst +0 -91
- data/docs/index.rst +0 -109
- data/docs/make.bat +0 -170
- data/docs/src/pip-delete-this-directory.txt +0 -5
- data/docs/usage/accounts.rst +0 -89
- data/docs/usage/applications.rst +0 -108
- data/docs/usage/basics.rst +0 -102
- data/docs/usage/caller-ids.rst +0 -45
- data/docs/usage/conferences.rst +0 -108
- data/docs/usage/errors.rst +0 -29
- data/docs/usage/messages.rst +0 -109
- data/docs/usage/notifications.rst +0 -70
- data/docs/usage/phone-calls.rst +0 -166
- data/docs/usage/phone-numbers.rst +0 -174
- data/docs/usage/queues.rst +0 -112
- data/docs/usage/recordings.rst +0 -96
- data/docs/usage/sip.rst +0 -103
- data/docs/usage/token-generation.rst +0 -81
- data/docs/usage/transcriptions.rst +0 -31
- data/docs/usage/twiml.rst +0 -69
- data/docs/usage/validation.rst +0 -71
- data/lib/twilio-ruby/rest/applications.rb +0 -6
- data/lib/twilio-ruby/rest/authorized_connect_apps.rb +0 -6
- data/lib/twilio-ruby/rest/available_phone_numbers/country.rb +0 -10
- data/lib/twilio-ruby/rest/available_phone_numbers/local.rb +0 -11
- data/lib/twilio-ruby/rest/available_phone_numbers/mobile.rb +0 -11
- data/lib/twilio-ruby/rest/available_phone_numbers/toll_free.rb +0 -11
- data/lib/twilio-ruby/rest/available_phone_numbers.rb +0 -13
- data/lib/twilio-ruby/rest/calls.rb +0 -28
- data/lib/twilio-ruby/rest/conferences/participants.rb +0 -23
- data/lib/twilio-ruby/rest/conferences.rb +0 -12
- data/lib/twilio-ruby/rest/connect_apps.rb +0 -6
- data/lib/twilio-ruby/rest/errors.rb +0 -14
- data/lib/twilio-ruby/rest/incoming_phone_numbers/local.rb +0 -13
- data/lib/twilio-ruby/rest/incoming_phone_numbers/mobile.rb +0 -13
- data/lib/twilio-ruby/rest/incoming_phone_numbers/toll_free.rb +0 -13
- data/lib/twilio-ruby/rest/incoming_phone_numbers.rb +0 -17
- data/lib/twilio-ruby/rest/instance_resource.rb +0 -101
- data/lib/twilio-ruby/rest/list_resource.rb +0 -110
- data/lib/twilio-ruby/rest/media.rb +0 -14
- data/lib/twilio-ruby/rest/messages.rb +0 -17
- data/lib/twilio-ruby/rest/notifications.rb +0 -6
- data/lib/twilio-ruby/rest/outgoing_caller_ids.rb +0 -25
- data/lib/twilio-ruby/rest/queues/members.rb +0 -29
- data/lib/twilio-ruby/rest/queues.rb +0 -12
- data/lib/twilio-ruby/rest/recordings.rb +0 -35
- data/lib/twilio-ruby/rest/sandbox.rb +0 -5
- data/lib/twilio-ruby/rest/sip/credential_lists/credentials.rb +0 -6
- data/lib/twilio-ruby/rest/sip/credential_lists.rb +0 -11
- data/lib/twilio-ruby/rest/sip/domains/credential_list_mappings.rb +0 -6
- data/lib/twilio-ruby/rest/sip/domains/ip_access_control_list_mappings.rb +0 -6
- data/lib/twilio-ruby/rest/sip/domains.rb +0 -12
- data/lib/twilio-ruby/rest/sip/ip_access_control_lists/ip_addresses.rb +0 -6
- data/lib/twilio-ruby/rest/sip/ip_access_control_lists.rb +0 -11
- data/lib/twilio-ruby/rest/sip.rb +0 -12
- data/lib/twilio-ruby/rest/sms/messages.rb +0 -15
- data/lib/twilio-ruby/rest/sms/short_codes.rb +0 -8
- data/lib/twilio-ruby/rest/sms.rb +0 -11
- data/lib/twilio-ruby/rest/transcriptions.rb +0 -6
- data/lib/twilio-ruby/rest/usage/records.rb +0 -21
- data/lib/twilio-ruby/rest/usage/triggers.rb +0 -12
- data/lib/twilio-ruby/rest/usage.rb +0 -10
- data/lib/twilio-ruby/rest/utils.rb +0 -25
- data/lib/twilio-ruby/twiml/response.rb +0 -15
- data/lib/twilio-ruby/util/capability.rb +0 -61
- data/lib/twilio-ruby/util/request_validator.rb +0 -22
- data/spec/rest/account_spec.rb +0 -58
- data/spec/rest/call_spec.rb +0 -18
- data/spec/rest/client_spec.rb +0 -100
- data/spec/rest/conference_spec.rb +0 -9
- data/spec/rest/instance_resource_spec.rb +0 -15
- data/spec/rest/message_spec.rb +0 -12
- data/spec/rest/numbers_spec.rb +0 -46
- data/spec/rest/queue_spec.rb +0 -9
- data/spec/rest/recording_spec.rb +0 -9
- data/spec/util/capability_spec.rb +0 -137
- data/spec/util/request_validator_spec.rb +0 -65
@@ -0,0 +1,232 @@
|
|
1
|
+
module Twilio
|
2
|
+
module JWT
|
3
|
+
module AccessTokenGrant
|
4
|
+
def _key
|
5
|
+
raise NotImplementedError
|
6
|
+
end
|
7
|
+
|
8
|
+
def _generate_payload
|
9
|
+
raise NotImplementedError
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class AccessToken < BaseJWT
|
14
|
+
attr_accessor :account_sid,
|
15
|
+
:signing_key_id,
|
16
|
+
:secret,
|
17
|
+
:identity,
|
18
|
+
:grants,
|
19
|
+
:nbf,
|
20
|
+
:ttl,
|
21
|
+
:valid_until
|
22
|
+
|
23
|
+
def initialize(
|
24
|
+
account_sid,
|
25
|
+
signing_key_sid,
|
26
|
+
secret,
|
27
|
+
grants = [],
|
28
|
+
identity: nil,
|
29
|
+
nbf: nil,
|
30
|
+
ttl: 3600,
|
31
|
+
valid_until: nil
|
32
|
+
)
|
33
|
+
super(secret_key: secret,
|
34
|
+
issuer: signing_key_sid,
|
35
|
+
subject: account_sid,
|
36
|
+
nbf: nbf,
|
37
|
+
ttl: ttl,
|
38
|
+
valid_until: valid_until)
|
39
|
+
@account_sid = account_sid
|
40
|
+
@signing_key_sid = signing_key_sid
|
41
|
+
@secret = secret
|
42
|
+
@identity = identity
|
43
|
+
@nbf = nbf
|
44
|
+
@grants = grants
|
45
|
+
@ttl = ttl
|
46
|
+
@valid_until = valid_until
|
47
|
+
end
|
48
|
+
|
49
|
+
def add_grant(grant)
|
50
|
+
@grants.push(grant)
|
51
|
+
end
|
52
|
+
|
53
|
+
def to_s
|
54
|
+
to_jwt
|
55
|
+
end
|
56
|
+
|
57
|
+
protected
|
58
|
+
|
59
|
+
def _generate_payload
|
60
|
+
now = Time.now.to_i
|
61
|
+
grants = {}
|
62
|
+
grants[:identity] = @identity if @identity
|
63
|
+
|
64
|
+
@grants.each { |grant| grants[grant._key] = grant._generate_payload } unless @grants.empty?
|
65
|
+
|
66
|
+
payload = {
|
67
|
+
jti: "#{@signing_key_sid}-#{now}",
|
68
|
+
grants: grants
|
69
|
+
}
|
70
|
+
|
71
|
+
payload
|
72
|
+
end
|
73
|
+
|
74
|
+
protected
|
75
|
+
|
76
|
+
def _generate_headers
|
77
|
+
headers = {
|
78
|
+
cty: 'twilio-fpa;v=1'
|
79
|
+
}
|
80
|
+
|
81
|
+
headers
|
82
|
+
end
|
83
|
+
|
84
|
+
class IpMessagingGrant
|
85
|
+
include AccessTokenGrant
|
86
|
+
attr_accessor :service_sid,
|
87
|
+
:endpoint_id,
|
88
|
+
:deployment_role_sid,
|
89
|
+
:push_credential_sid
|
90
|
+
|
91
|
+
def _key
|
92
|
+
'ip_messaging'
|
93
|
+
end
|
94
|
+
|
95
|
+
def _generate_payload
|
96
|
+
payload = {}
|
97
|
+
|
98
|
+
payload[:service_sid] = service_sid if service_sid
|
99
|
+
|
100
|
+
payload[:endpoint_id] = endpoint_id if endpoint_id
|
101
|
+
|
102
|
+
if deployment_role_sid
|
103
|
+
payload[:deployment_role_sid] = deployment_role_sid
|
104
|
+
end
|
105
|
+
|
106
|
+
if push_credential_sid
|
107
|
+
payload[:push_credential_sid] = push_credential_sid
|
108
|
+
end
|
109
|
+
|
110
|
+
payload
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
class VoiceGrant
|
115
|
+
include AccessTokenGrant
|
116
|
+
attr_accessor :outgoing_application_sid,
|
117
|
+
:outgoing_application_params,
|
118
|
+
:push_credential_sid,
|
119
|
+
:endpoint_id
|
120
|
+
|
121
|
+
def _key
|
122
|
+
'voice'
|
123
|
+
end
|
124
|
+
|
125
|
+
def _generate_payload
|
126
|
+
payload = {}
|
127
|
+
|
128
|
+
if outgoing_application_sid
|
129
|
+
outgoing = {}
|
130
|
+
outgoing[:application_sid] = outgoing_application_sid
|
131
|
+
if outgoing_application_params
|
132
|
+
outgoing[:params] = outgoing_application_params
|
133
|
+
end
|
134
|
+
|
135
|
+
payload[:outgoing] = outgoing
|
136
|
+
end
|
137
|
+
|
138
|
+
if push_credential_sid
|
139
|
+
payload[:push_credential_sid] = push_credential_sid
|
140
|
+
end
|
141
|
+
|
142
|
+
payload[:endpoint_id] = endpoint_id if endpoint_id
|
143
|
+
|
144
|
+
payload
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
class SyncGrant
|
149
|
+
include AccessTokenGrant
|
150
|
+
attr_accessor :service_sid,
|
151
|
+
:endpoint_id
|
152
|
+
|
153
|
+
def _key
|
154
|
+
'data_sync'
|
155
|
+
end
|
156
|
+
|
157
|
+
def _generate_payload
|
158
|
+
payload = {}
|
159
|
+
|
160
|
+
payload['service_sid'] = service_sid if service_sid
|
161
|
+
payload['endpoint_id'] = endpoint_id if endpoint_id
|
162
|
+
|
163
|
+
payload
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
class ConversationsGrant
|
168
|
+
include AccessTokenGrant
|
169
|
+
attr_accessor :configuration_profile_sid
|
170
|
+
|
171
|
+
def _key
|
172
|
+
'rtc'
|
173
|
+
end
|
174
|
+
|
175
|
+
def _generate_payload
|
176
|
+
payload = {}
|
177
|
+
|
178
|
+
if configuration_profile_sid
|
179
|
+
payload[:configuration_profile_sid] = configuration_profile_sid
|
180
|
+
end
|
181
|
+
|
182
|
+
payload
|
183
|
+
end
|
184
|
+
|
185
|
+
class << self
|
186
|
+
extend Gem::Deprecate
|
187
|
+
deprecate :new, 'VideoGrant.new', 2017, 5
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
class VideoGrant
|
192
|
+
include AccessTokenGrant
|
193
|
+
attr_accessor :room
|
194
|
+
|
195
|
+
def _key
|
196
|
+
'video'
|
197
|
+
end
|
198
|
+
|
199
|
+
def _generate_payload
|
200
|
+
payload = {}
|
201
|
+
|
202
|
+
payload[:room] = room if room
|
203
|
+
|
204
|
+
payload
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
class TaskRouterGrant
|
209
|
+
include AccessTokenGrant
|
210
|
+
attr_accessor :workspace_sid,
|
211
|
+
:worker_sid,
|
212
|
+
:role
|
213
|
+
|
214
|
+
def _key
|
215
|
+
'task_router'
|
216
|
+
end
|
217
|
+
|
218
|
+
def _generate_payload
|
219
|
+
payload = {}
|
220
|
+
|
221
|
+
payload[:workspace_sid] = workspace_sid if workspace_sid
|
222
|
+
|
223
|
+
payload[:worker_sid] = worker_sid if worker_sid
|
224
|
+
|
225
|
+
payload[:role] = role if role
|
226
|
+
|
227
|
+
payload
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
module Twilio
|
2
|
+
module JWT
|
3
|
+
module Scope
|
4
|
+
def _generate_payload
|
5
|
+
raise 'Not Implemented'
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class ClientCapability < BaseJWT
|
10
|
+
attr_accessor :account_sid,
|
11
|
+
:auth_token,
|
12
|
+
:client_name,
|
13
|
+
:scopes
|
14
|
+
|
15
|
+
alias to_s to_jwt
|
16
|
+
|
17
|
+
def initialize(account_sid, auth_token, scopes: [], nbf: nil, ttl: 3600, valid_until: nil)
|
18
|
+
super(secret_key: auth_token, issuer: account_sid, nbf: nbf, ttl: ttl, valid_until: valid_until)
|
19
|
+
@account_sid = account_sid
|
20
|
+
@auth_token = auth_token
|
21
|
+
@client_name = nil
|
22
|
+
@scopes = scopes
|
23
|
+
end
|
24
|
+
|
25
|
+
def add_scope(scope)
|
26
|
+
@scopes.push(scope)
|
27
|
+
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
|
31
|
+
def _generate_payload
|
32
|
+
scope = ''
|
33
|
+
scope = @scopes.map(&:_generate_payload).join(' ') unless @scopes.empty?
|
34
|
+
|
35
|
+
payload = {
|
36
|
+
scope: scope
|
37
|
+
}
|
38
|
+
|
39
|
+
payload
|
40
|
+
end
|
41
|
+
|
42
|
+
class IncomingClientScope
|
43
|
+
include Scope
|
44
|
+
|
45
|
+
def initialize(client_name)
|
46
|
+
@client_name = client_name
|
47
|
+
end
|
48
|
+
|
49
|
+
def _generate_payload
|
50
|
+
prefix = 'scope:client:incoming'
|
51
|
+
suffix = 'clientName=' + CGI.escape(@client_name.to_s)
|
52
|
+
|
53
|
+
[prefix, suffix].join('?')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class OutgoingClientScope
|
58
|
+
include Scope
|
59
|
+
|
60
|
+
def initialize(application_sid, client_name = nil, params = {})
|
61
|
+
@application_sid = application_sid
|
62
|
+
@client_name = client_name
|
63
|
+
@params = params
|
64
|
+
end
|
65
|
+
|
66
|
+
def _generate_payload
|
67
|
+
prefix = 'scope:client:outgoing'
|
68
|
+
application_sid = "appSid=#{CGI.escape(@application_sid)}"
|
69
|
+
unless @client_name.nil?
|
70
|
+
client_name = "clientName=#{CGI.escape(@client_name)}"
|
71
|
+
end
|
72
|
+
unless @params.empty?
|
73
|
+
params = 'appParams=' + @params.map { |k, v| CGI.escape("#{k}=#{v}") }.join('&')
|
74
|
+
end
|
75
|
+
|
76
|
+
suffix = [application_sid, client_name, params].compact.join('&')
|
77
|
+
[prefix, suffix].join('?')
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
class EventStreamScope
|
82
|
+
include Scope
|
83
|
+
|
84
|
+
def initialize(filters = {})
|
85
|
+
@filters = filters
|
86
|
+
@path = '/2010-04-01/Events'
|
87
|
+
end
|
88
|
+
|
89
|
+
def _generate_payload
|
90
|
+
prefix = 'scope:stream:subscribe'
|
91
|
+
path = "path=#{CGI.escape(@path)}"
|
92
|
+
unless @filters.empty?
|
93
|
+
filters = 'params=' + @filters.map { |k, v| CGI.escape("#{k}=#{v}") }.join('&')
|
94
|
+
end
|
95
|
+
|
96
|
+
suffix = [path, filters].compact.join('&')
|
97
|
+
[prefix, suffix].join('?')
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,50 @@
|
|
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
|
+
raise NotImplementedError
|
25
|
+
end
|
26
|
+
|
27
|
+
def headers
|
28
|
+
headers = _generate_headers.clone
|
29
|
+
headers['typ'] = 'JWT'
|
30
|
+
headers['alg'] = @algorithm
|
31
|
+
headers
|
32
|
+
end
|
33
|
+
|
34
|
+
def payload
|
35
|
+
payload = _generate_payload.clone
|
36
|
+
|
37
|
+
payload[:iss] = @issuer
|
38
|
+
payload[:nbf] = @nbf || Time.now.to_i
|
39
|
+
payload[:exp] = @valid_until.nil? ? Time.now.to_i + @ttl : @valid_until
|
40
|
+
payload[:sub] = @subject unless @subject.nil?
|
41
|
+
|
42
|
+
payload
|
43
|
+
end
|
44
|
+
|
45
|
+
def to_jwt
|
46
|
+
::JWT.encode payload, @secret_key, @algorithm, headers
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,174 @@
|
|
1
|
+
module Twilio
|
2
|
+
module JWT
|
3
|
+
class TaskRouterCapability < BaseJWT
|
4
|
+
TASK_ROUTER_VERSION = 'v1'.freeze
|
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
|
+
@account_sid = account_sid
|
13
|
+
@auth_token = auth_token
|
14
|
+
@workspace_sid = workspace_sid
|
15
|
+
@channel_id = channel_id
|
16
|
+
@policies = []
|
17
|
+
end
|
18
|
+
|
19
|
+
def add_policy(policy)
|
20
|
+
@policies.push(policy)
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_s
|
24
|
+
to_jwt
|
25
|
+
end
|
26
|
+
|
27
|
+
protected
|
28
|
+
|
29
|
+
def _generate_payload
|
30
|
+
Twilio::JWT::TaskRouterCapability::TaskRouterUtils
|
31
|
+
.web_socket_policies(@account_sid, @channel_id)
|
32
|
+
.each { |policy| add_policy(policy) }
|
33
|
+
policies = @policies.map(&:_generate_payload)
|
34
|
+
|
35
|
+
payload = {
|
36
|
+
account_sid: @account_sid,
|
37
|
+
workspace_sid: @workspace_sid,
|
38
|
+
channel: @channel_id,
|
39
|
+
version: TASK_ROUTER_VERSION,
|
40
|
+
friendly_name: @channel_id,
|
41
|
+
policies: policies
|
42
|
+
}
|
43
|
+
|
44
|
+
if @channel_id[0..1] == 'WK'
|
45
|
+
payload[:worker_sid] = @channel_id
|
46
|
+
elsif @channel_id[0..1] == 'WQ'
|
47
|
+
payload[:taskqueue_sid] = @channel_id
|
48
|
+
end
|
49
|
+
|
50
|
+
payload
|
51
|
+
end
|
52
|
+
|
53
|
+
class Policy
|
54
|
+
attr_accessor :url,
|
55
|
+
:method,
|
56
|
+
:allowed,
|
57
|
+
:post_filters,
|
58
|
+
:query_filters
|
59
|
+
|
60
|
+
def initialize(url, method, allowed, post_filters = {}, query_filters = {})
|
61
|
+
@url = url
|
62
|
+
@method = method
|
63
|
+
@allowed = allowed
|
64
|
+
@post_filters = post_filters
|
65
|
+
@query_filters = query_filters
|
66
|
+
end
|
67
|
+
|
68
|
+
def _generate_payload
|
69
|
+
policy = {
|
70
|
+
url: @url,
|
71
|
+
method: @method,
|
72
|
+
query_filter: @query_filters,
|
73
|
+
post_filter: @post_filters,
|
74
|
+
allow: @allowed
|
75
|
+
}
|
76
|
+
policy
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
class TaskRouterUtils
|
81
|
+
TASK_ROUTER_VERSION = 'v1'.freeze
|
82
|
+
TASK_ROUTER_BASE_URL = 'https://taskrouter.twilio.com'.freeze
|
83
|
+
TASK_ROUTER_WEBSOCKET_BASE_URL = 'https://event-bridge.twilio.com/v1/wschannels'.freeze
|
84
|
+
|
85
|
+
def self.workspaces
|
86
|
+
[TASK_ROUTER_BASE_URL, TASK_ROUTER_VERSION, 'Workspaces'].join('/')
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.workspace(worskspace_sid)
|
90
|
+
[TASK_ROUTER_BASE_URL, TASK_ROUTER_VERSION, 'Workspaces', worskspace_sid].join('/')
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.all_workspaces
|
94
|
+
[TASK_ROUTER_BASE_URL, TASK_ROUTER_VERSION, 'Workspaces', '**'].join('/')
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.tasks(workspace_sid)
|
98
|
+
[workspace(workspace_sid), 'Tasks'].join('/')
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.task(workspace_sid, tasks_sid)
|
102
|
+
[workspace(workspace_sid), 'Tasks', tasks_sid].join('/')
|
103
|
+
end
|
104
|
+
|
105
|
+
def self.all_tasks(workspace_sid)
|
106
|
+
[workspace(workspace_sid), 'Tasks', '**'].join('/')
|
107
|
+
end
|
108
|
+
|
109
|
+
def self.task_queues(workspace_sid)
|
110
|
+
[workspace(workspace_sid), 'TaskQueues'].join('/')
|
111
|
+
end
|
112
|
+
|
113
|
+
def self.task_queue(workspace_sid, taskqueue_sid)
|
114
|
+
[workspace(workspace_sid), 'TaskQueues', taskqueue_sid].join('/')
|
115
|
+
end
|
116
|
+
|
117
|
+
def self.all_task_queues(workspace_sid)
|
118
|
+
[workspace(workspace_sid), 'TaskQueues', '**'].join('/')
|
119
|
+
end
|
120
|
+
|
121
|
+
def self.activities(workspace_sid)
|
122
|
+
[workspace(workspace_sid), 'Activities'].join('/')
|
123
|
+
end
|
124
|
+
|
125
|
+
def self.activity(workspace_sid, activity_sid)
|
126
|
+
[workspace(workspace_sid), 'Activities', activity_sid].join('/')
|
127
|
+
end
|
128
|
+
|
129
|
+
def self.all_activities(workspace_sid)
|
130
|
+
[workspace(workspace_sid), 'Activities', '**'].join('/')
|
131
|
+
end
|
132
|
+
|
133
|
+
def self.workers(workspace_sid)
|
134
|
+
[workspace(workspace_sid), 'Workers'].join('/')
|
135
|
+
end
|
136
|
+
|
137
|
+
def self.worker(workspace_sid, worker_sid)
|
138
|
+
[workspace(workspace_sid), 'Workers', worker_sid].join('/')
|
139
|
+
end
|
140
|
+
|
141
|
+
def self.all_workers(workspace_sid)
|
142
|
+
[workspace(workspace_sid), 'Workers', '**'].join('/')
|
143
|
+
end
|
144
|
+
|
145
|
+
def self.reservations(workspace_sid, worker_sid)
|
146
|
+
[worker(workspace_sid, worker_sid), 'Reservations'].join('/')
|
147
|
+
end
|
148
|
+
|
149
|
+
def self.reservation(workspace_sid, worker_sid, reservation_sid)
|
150
|
+
[worker(workspace_sid, worker_sid), 'Reservations', reservation_sid].join('/')
|
151
|
+
end
|
152
|
+
|
153
|
+
def self.all_reservations(workspace_sid, worker_sid)
|
154
|
+
[worker(workspace_sid, worker_sid), 'Reservations', '**'].join('/')
|
155
|
+
end
|
156
|
+
|
157
|
+
def self.web_socket_policies(account_sid, channel_sid)
|
158
|
+
url = [TASK_ROUTER_WEBSOCKET_BASE_URL, account_sid, channel_sid].join('/')
|
159
|
+
get = Policy.new(url, 'GET', true)
|
160
|
+
post = Policy.new(url, 'POST', true)
|
161
|
+
[get, post]
|
162
|
+
end
|
163
|
+
|
164
|
+
def self.worker_policies(workspace_sid, worker_sid)
|
165
|
+
activities = Policy.new(self.activities(workspace_sid), 'GET', true)
|
166
|
+
tasks = Policy.new(all_tasks(workspace_sid), 'GET', true)
|
167
|
+
reservations = Policy.new(all_reservations(workspace_sid, worker_sid), 'GET', true)
|
168
|
+
fetch = Policy.new(worker(workspace_sid, worker_sid), 'GET', true)
|
169
|
+
[activities, tasks, reservations, fetch]
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|