# frozen_string_literal: true module TwilioBase module Protocols module Voice class Sip < Base def endpoint "sip:#{sip_endpoint}?#{parsed_headers}" end def name :sip end private def parsed_headers hash = headers.each_with_object({}) do |(k, v), obj| key = "X-#{k.to_s.camelize}" value = v.presence || '-' obj[key] = value end Addressable::URI.new(query_values: hash).query end def headers params[:headers].is_a?(Hash) ? params[:headers] : {} end def sip_endpoint sip_whip end def sip_whip @sip_whip ||= sip_endpoints.sample.to_s.strip end def sip_endpoints value = Array(to) value.flat_map { |v| v.split(',') } end end end end end