Sha256: 9f583e5d4708eb5d38f17fd0eaccd51fcc0f091272cbdda289c19f58547103d0

Contents?: true

Size: 996 Bytes

Versions: 5

Compression:

Stored size: 996 Bytes

Contents

require 'builder'
Dir[File.dirname(__FILE__) + '/verbs/*'].each {|file|
  require_relative file
}

SSML_REGEX = /<([a-zA-Z\/\/].*?)>/
SPEAK_SENTENCE_REGEX = /<SpeakSentence.*?>.*?<\/SpeakSentence>/

module Bandwidth 
  module Voice 
    class Response
      # Initializer
      # @param verbs [Array] optional list of verbs to include into response
      def initialize(verbs = nil)
        @verbs = verbs || []
      end

      # Return BXML representaion of this response
      def to_bxml()
        xml = Builder::XmlMarkup.new()
        xml.instruct!(:xml, :version=>'1.0', :encoding=>'UTF-8')
        xml.Response do
          @verbs.each {|verb| verb.to_bxml(xml)}
        end
        xml.target!().gsub(SPEAK_SENTENCE_REGEX){|s|s.gsub(SSML_REGEX, '<\1>')}
      end

      # Add one or more verbs to this response
      def push(*verbs)
        @verbs.push(*verbs)
      end

      # Add a verb to this response
      def <<(verb)
        @verbs << verb
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
bandwidth-sdk-2.0.0 lib/bandwidth/voice_lib/bxml/bxml.rb
bandwidth-sdk-1.0.2 lib/bandwidth/voice_lib/bxml/bxml.rb
bandwidth-sdk-1.0.1 lib/bandwidth/voice_lib/bxml/bxml.rb
bandwidth-sdk-1.0.0 lib/bandwidth/voice_lib/bxml/bxml.rb
bandwidth-sdk-1.0.0.pre lib/bandwidth/voice_lib/bxml/bxml.rb