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,46 @@
|
|
1
|
+
module Rack
|
2
|
+
# Middleware that authenticates webhooks from Twilio using the request
|
3
|
+
# validator.
|
4
|
+
#
|
5
|
+
# The middleware takes an auth token with which to set up the request
|
6
|
+
# validator and any number of paths. When a path matches the incoming request
|
7
|
+
# path, the request will be checked for authentication.
|
8
|
+
#
|
9
|
+
# Example:
|
10
|
+
#
|
11
|
+
# require 'rack'
|
12
|
+
# use Rack::TwilioWebhookAuthentication, ENV['AUTH_TOKEN'], /\/messages/
|
13
|
+
#
|
14
|
+
# The above appends this middleware to the stack, using an auth token saved in
|
15
|
+
# the ENV and only against paths that match /\/messages/. If the request
|
16
|
+
# validates then it gets passed on to the action as normal. If the request
|
17
|
+
# doesn't validate then the middleware responds immediately with a 403 status.
|
18
|
+
|
19
|
+
class TwilioWebhookAuthentication
|
20
|
+
def initialize(app, auth_token, *paths, &auth_token_lookup)
|
21
|
+
@app = app
|
22
|
+
@auth_token = auth_token
|
23
|
+
define_singleton_method(:get_auth_token, auth_token_lookup) if block_given?
|
24
|
+
@path_regex = Regexp.union(paths)
|
25
|
+
end
|
26
|
+
|
27
|
+
def call(env)
|
28
|
+
return @app.call(env) unless env['PATH_INFO'].match(@path_regex)
|
29
|
+
request = Rack::Request.new(env)
|
30
|
+
original_url = request.url
|
31
|
+
params = request.post? ? request.POST : {}
|
32
|
+
auth_token = @auth_token || get_auth_token(params['AccountSid'])
|
33
|
+
validator = Twilio::Security::RequestValidator.new(auth_token)
|
34
|
+
signature = env['HTTP_X_TWILIO_SIGNATURE'] || ''
|
35
|
+
if validator.validate(original_url, params, signature)
|
36
|
+
@app.call(env)
|
37
|
+
else
|
38
|
+
[
|
39
|
+
403,
|
40
|
+
{ 'Content-Type' => 'text/plain' },
|
41
|
+
['Twilio Request Validation Failed.']
|
42
|
+
]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Twilio
|
2
|
+
module REST
|
3
|
+
class Domain
|
4
|
+
attr_reader :client
|
5
|
+
|
6
|
+
def initialize(client)
|
7
|
+
@client = client
|
8
|
+
@host = nil
|
9
|
+
@base_url = nil
|
10
|
+
@port = nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def absolute_url(uri)
|
14
|
+
"#{@base_url.chomp('/')}/#{uri.chomp('/').gsub(/^\//, '')}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def request(method, uri, params = {}, data = {}, headers = {}, auth = nil, timeout = nil)
|
18
|
+
url = uri.match(/^http/) ? uri : absolute_url(uri)
|
19
|
+
|
20
|
+
@client.request(
|
21
|
+
@host,
|
22
|
+
@port,
|
23
|
+
method,
|
24
|
+
url,
|
25
|
+
params,
|
26
|
+
data,
|
27
|
+
headers,
|
28
|
+
auth,
|
29
|
+
timeout
|
30
|
+
)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Twilio
|
2
|
+
module REST
|
3
|
+
class TwilioError < StandardError
|
4
|
+
attr_reader :message, :body
|
5
|
+
|
6
|
+
def initialize(message, body = nil)
|
7
|
+
@message = message
|
8
|
+
@body = body
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_s
|
12
|
+
"#{@message}: #{@body || 'no body'}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class RestError < TwilioError
|
17
|
+
attr_reader :message, :code, :status_code
|
18
|
+
|
19
|
+
def initialize(message, code, status_code)
|
20
|
+
@message = message
|
21
|
+
@code = code
|
22
|
+
@status_code = status_code
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_s
|
26
|
+
"[HTTP #{status_code}] #{code} : #{message}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
module Twilio
|
2
|
+
module REST
|
3
|
+
# Page Base Class
|
4
|
+
class Page
|
5
|
+
include Enumerable
|
6
|
+
|
7
|
+
META_KEYS = [
|
8
|
+
'end',
|
9
|
+
'first_page_uri',
|
10
|
+
'next_page_uri',
|
11
|
+
'last_page_uri',
|
12
|
+
'page',
|
13
|
+
'page_size',
|
14
|
+
'previous_page_uri',
|
15
|
+
'total',
|
16
|
+
'num_pages',
|
17
|
+
'start',
|
18
|
+
'uri'
|
19
|
+
].freeze
|
20
|
+
|
21
|
+
def initialize(version, response)
|
22
|
+
payload = process_response(response)
|
23
|
+
|
24
|
+
@version = version
|
25
|
+
@payload = payload
|
26
|
+
@solution = {}
|
27
|
+
@records = load_page(payload)
|
28
|
+
end
|
29
|
+
|
30
|
+
def process_response(response)
|
31
|
+
if response.status_code != 200
|
32
|
+
raise Twilio::REST::TwilioError.new('Unable to fetch page', response)
|
33
|
+
end
|
34
|
+
|
35
|
+
response.body
|
36
|
+
end
|
37
|
+
|
38
|
+
def load_page(payload)
|
39
|
+
if payload['meta'] && payload['meta']['key']
|
40
|
+
return payload[payload['meta']['key']]
|
41
|
+
else
|
42
|
+
keys = payload.keys
|
43
|
+
key = keys - META_KEYS
|
44
|
+
return payload[key.first] if key.size == 1
|
45
|
+
end
|
46
|
+
|
47
|
+
raise Twilio::REST::TwilioError, 'Page Records can not be deserialized'
|
48
|
+
end
|
49
|
+
|
50
|
+
def previous_page_url
|
51
|
+
if @payload['meta'] && @payload['meta']['previous_page_url']
|
52
|
+
return @version.domain.absolute_url(URI.parse(@payload['meta']['previous_page_url']).request_uri)
|
53
|
+
elsif @payload['previous_page_uri']
|
54
|
+
return @version.domain.absolute_url(@payload['previous_page_uri'])
|
55
|
+
end
|
56
|
+
|
57
|
+
nil
|
58
|
+
end
|
59
|
+
|
60
|
+
def next_page_url
|
61
|
+
if @payload['meta'] && @payload['meta']['next_page_url']
|
62
|
+
return @version.domain.absolute_url(URI.parse(@payload['meta']['next_page_url']).request_uri)
|
63
|
+
elsif @payload['next_page_uri']
|
64
|
+
return @version.domain.absolute_url(@payload['next_page_uri'])
|
65
|
+
end
|
66
|
+
|
67
|
+
nil
|
68
|
+
end
|
69
|
+
|
70
|
+
def get_instance(payload)
|
71
|
+
raise Twilio::REST::TwilioError, 'Page.get_instance() must be implemented in the derived class'
|
72
|
+
end
|
73
|
+
|
74
|
+
def previous_page
|
75
|
+
return nil unless previous_page_url
|
76
|
+
|
77
|
+
response = @version.domain.request('GET', previous_page_url)
|
78
|
+
|
79
|
+
self.class.new(@version, response, @solution)
|
80
|
+
end
|
81
|
+
|
82
|
+
def next_page
|
83
|
+
return nil unless next_page_url
|
84
|
+
|
85
|
+
response = @version.domain.request('GET', next_page_url)
|
86
|
+
|
87
|
+
self.class.new(@version, response, @solution)
|
88
|
+
end
|
89
|
+
|
90
|
+
def each
|
91
|
+
@records.each do |record|
|
92
|
+
yield get_instance(record)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def to_s
|
97
|
+
'#<Page>'
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Twilio
|
2
|
+
module REST
|
3
|
+
class ListResource
|
4
|
+
def initialize(version)
|
5
|
+
@version = version
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class InstanceContext
|
10
|
+
def initialize(version)
|
11
|
+
@version = version
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class InstanceResource
|
16
|
+
def initialize(version)
|
17
|
+
@version = version
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module Twilio
|
2
|
+
def self.serialize_iso8601_date(date)
|
3
|
+
if date.eql?(:unset)
|
4
|
+
date
|
5
|
+
elsif date.is_a?(Date)
|
6
|
+
date.iso8601
|
7
|
+
elsif date.is_a?(Time)
|
8
|
+
date.strftime('%Y-%m-%d')
|
9
|
+
elsif date.is_a?(String)
|
10
|
+
date
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.serialize_iso8601_datetime(date)
|
15
|
+
if date.eql?(:unset)
|
16
|
+
date
|
17
|
+
elsif date.is_a?(Date)
|
18
|
+
Time.new(date.year, date.month, date.day).utc.iso8601
|
19
|
+
elsif date.is_a?(Time)
|
20
|
+
date.utc.iso8601
|
21
|
+
elsif date.is_a?(String)
|
22
|
+
date
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.deserialize_rfc2822(date)
|
27
|
+
Time.rfc2822(date) unless date.nil?
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.deserialize_iso8601_date(date)
|
31
|
+
Date.parse(date) unless date.nil?
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.deserialize_iso8601_datetime(date)
|
35
|
+
Time.parse(date) unless date.nil?
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.serialize_object(object)
|
39
|
+
if object.is_a?(Hash) || object.is_a?(Array)
|
40
|
+
JSON.generate(object)
|
41
|
+
else
|
42
|
+
object
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.flatten(map, result = {}, previous = [])
|
47
|
+
map.each do |key, value|
|
48
|
+
if value.is_a? Hash
|
49
|
+
self.flatten(value, result, previous + [key])
|
50
|
+
else
|
51
|
+
result[(previous + [key]).join('.')] = value
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
result
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.prefixed_collapsible_map(map, prefix)
|
59
|
+
result = {}
|
60
|
+
if map.is_a? Hash
|
61
|
+
flattened = self.flatten(map)
|
62
|
+
result = {}
|
63
|
+
flattened.each do |key, value|
|
64
|
+
result[prefix + '.' + key] = value
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
result
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Twilio
|
2
|
+
class TwilioResponse
|
3
|
+
attr_accessor :status_code, :body
|
4
|
+
|
5
|
+
def initialize(status_code, body)
|
6
|
+
@status_code = status_code
|
7
|
+
body = '{}' if !body || body.empty?
|
8
|
+
@body = JSON.parse(body)
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_s
|
12
|
+
"[#{status_code}] #{body}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,164 @@
|
|
1
|
+
module Twilio
|
2
|
+
module REST
|
3
|
+
class Version
|
4
|
+
attr_accessor :domain
|
5
|
+
|
6
|
+
class RecordStream
|
7
|
+
include Enumerable
|
8
|
+
|
9
|
+
def initialize(page, limit: nil, page_limit: nil)
|
10
|
+
@page = page
|
11
|
+
@limit = limit
|
12
|
+
@page_limit = page_limit
|
13
|
+
end
|
14
|
+
|
15
|
+
def each
|
16
|
+
current_record = 0
|
17
|
+
current_page = 1
|
18
|
+
|
19
|
+
while @page
|
20
|
+
@page.each do |record|
|
21
|
+
yield record
|
22
|
+
current_record += 1
|
23
|
+
return nil if @limit && @limit <= current_record
|
24
|
+
end
|
25
|
+
|
26
|
+
return nil if @page_limit && @page_limit <= current_page
|
27
|
+
|
28
|
+
@page = @page.next_page
|
29
|
+
current_page += 1
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def initialize(domain)
|
35
|
+
@domain = domain
|
36
|
+
@version = nil
|
37
|
+
end
|
38
|
+
|
39
|
+
def absolute_url(uri)
|
40
|
+
@domain.absolute_url(relative_uri(uri))
|
41
|
+
end
|
42
|
+
|
43
|
+
def relative_uri(uri)
|
44
|
+
"#{@version.chomp('/').gsub(/^\//, '')}/#{uri.chomp('/').gsub(/^\//, '')}"
|
45
|
+
end
|
46
|
+
|
47
|
+
def request(method, uri, params = {}, data = {}, headers = {}, auth = nil, timeout = nil)
|
48
|
+
url = relative_uri(uri)
|
49
|
+
params = params.delete_if { |_k, v| v.nil? }
|
50
|
+
data = data
|
51
|
+
@domain.request(method, url, params, data, headers, auth, timeout)
|
52
|
+
end
|
53
|
+
|
54
|
+
def exception(response, header)
|
55
|
+
message = header
|
56
|
+
code = response.status_code
|
57
|
+
|
58
|
+
if response.body.key?('message')
|
59
|
+
message += ": #{response.body['message']}"
|
60
|
+
end
|
61
|
+
|
62
|
+
code = response.body['code'] if response.body.key?('code')
|
63
|
+
|
64
|
+
Twilio::REST::RestError.new(message, code, response.status_code)
|
65
|
+
end
|
66
|
+
|
67
|
+
def fetch(method, uri, params = {}, data = {}, headers = {}, auth = nil, timeout = nil)
|
68
|
+
response = request(
|
69
|
+
method,
|
70
|
+
uri,
|
71
|
+
params,
|
72
|
+
data,
|
73
|
+
headers,
|
74
|
+
auth,
|
75
|
+
timeout
|
76
|
+
)
|
77
|
+
|
78
|
+
if response.status_code < 200 || response.status_code >= 300
|
79
|
+
raise exception(response, 'Unable to fetch record')
|
80
|
+
end
|
81
|
+
|
82
|
+
response.body
|
83
|
+
end
|
84
|
+
|
85
|
+
def update(method, uri, params: {}, data: {}, headers: {}, auth: nil, timeout: nil)
|
86
|
+
response = request(
|
87
|
+
method,
|
88
|
+
uri,
|
89
|
+
params,
|
90
|
+
data,
|
91
|
+
headers,
|
92
|
+
auth,
|
93
|
+
timeout
|
94
|
+
)
|
95
|
+
|
96
|
+
if response.status_code < 200 || response.status_code >= 300
|
97
|
+
raise exception(response, 'Unable to update record')
|
98
|
+
end
|
99
|
+
|
100
|
+
response.body
|
101
|
+
end
|
102
|
+
|
103
|
+
def delete(method, uri, params = {}, data = {}, headers = {}, auth = nil, timeout = nil)
|
104
|
+
response = request(
|
105
|
+
method,
|
106
|
+
uri,
|
107
|
+
params,
|
108
|
+
data,
|
109
|
+
headers,
|
110
|
+
auth,
|
111
|
+
timeout
|
112
|
+
)
|
113
|
+
|
114
|
+
if response.status_code < 200 || response.status_code >= 300
|
115
|
+
raise exception(response, 'Unable to delete record')
|
116
|
+
end
|
117
|
+
|
118
|
+
response.status_code == 204
|
119
|
+
end
|
120
|
+
|
121
|
+
def read_limits(limit = nil, page_size = nil)
|
122
|
+
page_limit = nil
|
123
|
+
|
124
|
+
unless limit.nil?
|
125
|
+
# If there is no user-specified page_size, pick the most network efficient size
|
126
|
+
page_size = limit
|
127
|
+
page_limit = (limit / page_size.to_f).ceil
|
128
|
+
end
|
129
|
+
|
130
|
+
{
|
131
|
+
limit: limit || nil,
|
132
|
+
page_size: page_size || nil,
|
133
|
+
page_limit: page_limit
|
134
|
+
}
|
135
|
+
end
|
136
|
+
|
137
|
+
def page(method, uri, params = {}, data = {}, headers = {}, auth = nil, timeout = nil)
|
138
|
+
request(
|
139
|
+
method,
|
140
|
+
uri,
|
141
|
+
params,
|
142
|
+
data,
|
143
|
+
headers,
|
144
|
+
auth,
|
145
|
+
timeout
|
146
|
+
)
|
147
|
+
end
|
148
|
+
|
149
|
+
def stream(page, limit: nil, page_limit: nil)
|
150
|
+
RecordStream.new(page, limit: limit, page_limit: page_limit)
|
151
|
+
end
|
152
|
+
|
153
|
+
def create(method, uri, params: {}, data: {}, headers: {}, auth: nil, timeout: nil)
|
154
|
+
response = request(method, uri, params, data, headers, auth, timeout)
|
155
|
+
|
156
|
+
if response.status_code < 200 || response.status_code >= 300
|
157
|
+
raise exception(response, 'Unable to create record')
|
158
|
+
end
|
159
|
+
|
160
|
+
response.body
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
module Twilio
|
4
|
+
module HTTP
|
5
|
+
class Client
|
6
|
+
attr_accessor :adapter
|
7
|
+
|
8
|
+
def initialize(proxy_addr = nil, proxy_port = nil, proxy_user = nil, proxy_pass = nil, ssl_ca_file = nil)
|
9
|
+
@proxy_addr = proxy_addr
|
10
|
+
@proxy_port = proxy_port
|
11
|
+
@proxy_user = proxy_user
|
12
|
+
@proxy_pass = proxy_pass
|
13
|
+
@ssl_ca_file = ssl_ca_file
|
14
|
+
@adapter = Faraday.default_adapter
|
15
|
+
|
16
|
+
# Set default params encoder
|
17
|
+
Faraday::Utils.default_params_encoder = Faraday::FlatParamsEncoder
|
18
|
+
end
|
19
|
+
|
20
|
+
def request(host, port, method, url, params = {}, data = {}, headers = {}, auth = nil, timeout = nil)
|
21
|
+
@connection = Faraday.new(url: host + ':' + port.to_s, ssl: { verify: true }) do |f|
|
22
|
+
f.request :url_encoded
|
23
|
+
f.adapter @adapter
|
24
|
+
f.headers = headers
|
25
|
+
f.basic_auth(auth[0], auth[1])
|
26
|
+
if @proxy_addr
|
27
|
+
f.proxy '#{@proxy_user}:#{@proxy_pass}@#{@proxy_addr}:#{@proxy_port}'
|
28
|
+
end
|
29
|
+
f.options.open_timeout = timeout
|
30
|
+
f.options.timeout = timeout
|
31
|
+
end
|
32
|
+
|
33
|
+
response = @connection.send(method.downcase.to_sym, url, method == 'GET' ? params : data)
|
34
|
+
|
35
|
+
@last_response = response
|
36
|
+
if response.body && !response.body.empty?
|
37
|
+
object = response.body
|
38
|
+
elsif response.status == 400
|
39
|
+
object = { message: 'Bad request', code: 400 }.to_json
|
40
|
+
end
|
41
|
+
|
42
|
+
TwilioResponse.new(response.status, object)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|