class TwimlTemplate::Response

Constants

MESSAGING_VERBS
VOICE_VERBS

Public Class Methods

new() { |self| ... } click to toggle source
# File lib/twiml_template/response.rb, line 6
def initialize
  @voice_response = Twilio::TwiML::VoiceResponse.new
  @messaging_response = Twilio::TwiML::MessagingResponse.new

  yield(self) if block_given?
end

Public Instance Methods

method_missing(method, *args, &block) click to toggle source
# File lib/twiml_template/response.rb, line 18
def method_missing(method, *args, &block)
  if (respond_to?(method))
    if (MESSAGING_VERBS.include?(method) && @messaging_response)
      if ((MESSAGING_VERBS - VOICE_VERBS).include?(method))
        @voice_response = nil
      end
      @messaging_response.send(method, *args, &block)
    end
    if (VOICE_VERBS.include?(method) && @voice_response)
      if ((VOICE_VERBS - MESSAGING_VERBS).include?(method))
        @messaging_response = nil
      end
      @voice_response.send(method, *args, &block)
    end
  else
    raise ArgumentError.new("Method `#{method}` doesn't exist.")
  end
  return @messaging_response || @voice_response
end
respond_to?(method, include_private = false) click to toggle source
Calls superclass method
# File lib/twiml_template/response.rb, line 38
def respond_to?(method, include_private = false)
  verbs = []
  verbs = verbs | MESSAGING_VERBS if @messaging_response
  verbs = verbs | VOICE_VERBS if @voice_response
  verbs.include?(method.to_sym) || super
end
to_xml() click to toggle source
# File lib/twiml_template/response.rb, line 13
def to_xml
  twiml_response = @messaging_response || @voice_response
  twiml_response.to_xml
end