Sha256: 5ef0e4e4aadab665478d7e244c4abf2e22e9866f804fbcbbeef2272bfaf6bc79

Contents?: true

Size: 1.44 KB

Versions: 2

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

module TwilioBase
  module Protocols
    module Voice
      class Base
        include ::Helpers::Protocols

        ANONYMOUS_NUMBER = '+266696687'
        STATUS_CALLBACK_EVENTS = %w[initiated ringing answered completed].freeze

        def initialize(params: {}, to:)
          self.params = params
          self.to = to

          raise 'To cannot be blank' if to.blank?
        end

        def action_url
          params[:action_url]
        end

        def action_url_attributes
          { endpoint: to }
        end

        def caller_uuid
          mpoa.presence || ANONYMOUS_NUMBER
        end

        def endpoint
          to
        end

        def name
          :number
        end

        def status_callback_events
          STATUS_CALLBACK_EVENTS.join(' ')
        end

        def status_callback_url
          params[:status_callback_url]
        end

        def timeout
          params[:timeout]
        end

        def wait_url
          params[:wait_url]
        end

        def routing_method
          :dial
        end

        def routing_attributes
          dial_attribues
        end

        private

        attr_accessor :params, :to

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

        def mpoa
          extract_mpoa(params[:caller_uuid])
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
twilio_base-1.11.1101 app/services/twilio_base/protocols/voice/base.rb
twilio_base-1.11.11 app/services/twilio_base/protocols/voice/base.rb