Sha256: 5c49d1c2f6933221a8ee7fd9b535bf398fe079c1c134d7c8cab020c8c378e8a5

Contents?: true

Size: 1016 Bytes

Versions: 2

Compression:

Stored size: 1016 Bytes

Contents

# frozen_string_literal: true

module TwilioBase
  module Routers
    module Voice
      class Base
        include Rails.application.routes.url_helpers

        def initialize(protocol:)
          self.protocol = protocol
        end

        def route
          yield_response = yield if block_given?

          (yield_response || voice_response).dial(dial_attribues) do |dial|
            dial.public_send(
              protocol.name,
              protocol.endpoint,
              status_callback_event: protocol.status_callback_events,
              status_callback: protocol.status_callback_url
            )
          end.to_s
        end

        private

        attr_accessor :protocol

        def voice_response
          @voice_response ||= Twilio::TwiML::VoiceResponse.new
        end

        def dial_attribues
          {
            action: protocol.action_url,
            caller_id: protocol.caller_uuid,
            timeout: protocol.timeout
          }
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
twilio_base-1.9.0 app/services/twilio_base/routers/voice/base.rb
twilio_base-1.8.0 app/services/twilio_base/routers/voice/base.rb