Class: TwilioTestToolkit::CallScope
- Inherits:
-
Object
- Object
- TwilioTestToolkit::CallScope
- Defined in:
- lib/twilio-test-toolkit/call_scope.rb
Overview
Models a scope within a call.
Direct Known Subclasses
Class Method Summary collapse
-
.has_element(el, options = {}) ⇒ Object
Note that el is case sensitive and must match the desired TwiML element.
Instance Method Summary collapse
-
#current_path ⇒ Object
Some basic accessors.
- #follow_redirect(options = {}) ⇒ Object
- #follow_redirect!(options = {}) ⇒ Object
-
#gather? ⇒ Boolean
Stuff for gatherers.
- #gather_action ⇒ Object
- #gather_finish_on_key ⇒ Object
- #gather_method ⇒ Object
-
#has_redirect_to?(url) ⇒ Boolean
Stuff for redirects.
-
#method_missing(meth, *args, &block) ⇒ Object
Make this easier to support TwiML elements…
- #press(digits) ⇒ Object
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
- #response_xml ⇒ Object
- #root_call ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
Make this easier to support TwiML elements…
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/twilio-test-toolkit/call_scope.rb', line 72 def method_missing(meth, *args, &block) # support any check for a given attribute on a given element # # eg. has_action_on_dial?, has_method_on_sip?, etc. # # Attribute-checking appears to be case-sensitive, which x means: # # has_finishOnKey_on_record?("#") # # I'm not crazy about this mixed case, so we can also do a more # Rubyish way: # # has_finish_on_key_on_record?("#") # if meth.to_s =~ /^has_([a-zA-Z_]+)_on_([a-zA-Z]+)\?$/ has_attr_on_element?($2, $1, *args, &block) # support any check for the existence of a given element # with an optional check on the inner_text. elsif meth.to_s =~ /^has_([a-zA-Z]+)\?$/ has_element?($1, *args, &block) # get a given element node elsif meth.to_s =~ /^get_([a-z]+)_node$/ get_element_node($1, *args, &block) # run a block within a given node context elsif meth.to_s =~ /^within_([a-z]+)$/ within_element($1, *args, &block) else super # You *must* call super if you don't handle the # method, otherwise you'll mess up Ruby's method # lookup. end end |
Class Method Details
.has_element(el, options = {}) ⇒ Object
Note that el is case sensitive and must match the desired TwiML element. eg. Play (correct) vs play (incorrect).
7 8 9 10 11 |
# File 'lib/twilio-test-toolkit/call_scope.rb', line 7 def self.has_element(el, = {}) define_method "has_#{el.downcase}?" do |inner = nil| return has_element?(el, inner, ) end end |
Instance Method Details
#current_path ⇒ Object
Some basic accessors
114 115 116 |
# File 'lib/twilio-test-toolkit/call_scope.rb', line 114 def current_path @current_path end |
#follow_redirect(options = {}) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/twilio-test-toolkit/call_scope.rb', line 27 def follow_redirect( = {}) el = get_redirect_node raise "No redirect" if el.nil? return CallScope.from_request(self, el.text, { :method =>el[:method]}.merge()) end |
#follow_redirect!(options = {}) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/twilio-test-toolkit/call_scope.rb', line 34 def follow_redirect!( = {}) el = get_redirect_node raise "No redirect" if el.nil? request_for_twiml!(normalize_redirect_path(el.text), { :method => el[:method] }.merge()) end |
#gather? ⇒ Boolean
Stuff for gatherers
42 43 44 |
# File 'lib/twilio-test-toolkit/call_scope.rb', line 42 def gather? @xml.name == "Gather" end |
#gather_action ⇒ Object
46 47 48 49 |
# File 'lib/twilio-test-toolkit/call_scope.rb', line 46 def gather_action raise "Not a gather" unless gather? return @xml["action"] end |
#gather_finish_on_key ⇒ Object
56 57 58 59 |
# File 'lib/twilio-test-toolkit/call_scope.rb', line 56 def gather_finish_on_key raise "Not a gather" unless gather? return @xml["finishOnKey"] || '#' # '#' is the default finish key if not specified end |
#gather_method ⇒ Object
51 52 53 54 |
# File 'lib/twilio-test-toolkit/call_scope.rb', line 51 def gather_method raise "Not a gather" unless gather? return @xml["method"] end |
#has_redirect_to?(url) ⇒ Boolean
Stuff for redirects
21 22 23 24 25 |
# File 'lib/twilio-test-toolkit/call_scope.rb', line 21 def has_redirect_to?(url) el = get_redirect_node return false if el.nil? return normalize_redirect_path(el.text) == normalize_redirect_path(url) end |
#press(digits) ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/twilio-test-toolkit/call_scope.rb', line 61 def press(digits) raise "Not a gather" unless gather? # Fetch the path and then post path = gather_action # Update the root call root_call.request_for_twiml!(path, :digits => digits, :method => gather_method, :finish_on_key => gather_finish_on_key) end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
109 110 111 |
# File 'lib/twilio-test-toolkit/call_scope.rb', line 109 def respond_to_missing?(method_name, include_private = false) method_name.to_s.match(/^(has_|get_[a-z]+_node|within_)/) || super end |
#response_xml ⇒ Object
118 119 120 |
# File 'lib/twilio-test-toolkit/call_scope.rb', line 118 def response_xml @response_xml end |
#root_call ⇒ Object
122 123 124 |
# File 'lib/twilio-test-toolkit/call_scope.rb', line 122 def root_call @root_call end |