Class: Larynx::Response
- Inherits:
-
Object
- Object
- Larynx::Response
- Defined in:
- lib/larynx/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
Instance Method Summary collapse
- #answered? ⇒ Boolean
- #command_name ⇒ Object
- #disconnect? ⇒ Boolean
- #dtmf? ⇒ Boolean
- #error? ⇒ Boolean
- #event? ⇒ Boolean
- #event_name ⇒ Object
- #executed? ⇒ Boolean
- #executing? ⇒ Boolean
-
#initialize(header, body) ⇒ Response
constructor
A new instance of Response.
- #ok? ⇒ Boolean
- #reply? ⇒ Boolean
- #speech? ⇒ Boolean
Constructor Details
#initialize(header, body) ⇒ Response
Returns a new instance of Response.
5 6 7 8 9 10 11 |
# File 'lib/larynx/response.rb', line 5 def initialize(header, body) @header = CallHandler.headers_2_hash(header) if body @body = body.match(/:/) ? CallHandler.headers_2_hash(body) : body @body.each {|k,v| v.chomp! if v.is_a?(String)} end end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
3 4 5 |
# File 'lib/larynx/response.rb', line 3 def body @body end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
3 4 5 |
# File 'lib/larynx/response.rb', line 3 def header @header end |
Instance Method Details
#answered? ⇒ Boolean
13 14 15 |
# File 'lib/larynx/response.rb', line 13 def answered? executed? && command_name == 'answer' #event_name == 'CHANNEL_ANSWER' end |
#command_name ⇒ Object
41 42 43 |
# File 'lib/larynx/response.rb', line 41 def command_name @body[:application] if @body end |
#disconnect? ⇒ Boolean
57 58 59 |
# File 'lib/larynx/response.rb', line 57 def disconnect? @header[:content_type] == 'text/disconnect-notice' end |
#dtmf? ⇒ Boolean
49 50 51 |
# File 'lib/larynx/response.rb', line 49 def dtmf? @body[:event_name] == 'DTMF' if @body end |
#error? ⇒ Boolean
29 30 31 |
# File 'lib/larynx/response.rb', line 29 def error? @header[:reply_text] =~ /ERR/ end |
#event? ⇒ Boolean
21 22 23 |
# File 'lib/larynx/response.rb', line 21 def event? @header[:content_type] == 'text/event-plain' end |
#event_name ⇒ Object
45 46 47 |
# File 'lib/larynx/response.rb', line 45 def event_name @body[:event_name] if @body end |
#executed? ⇒ Boolean
37 38 39 |
# File 'lib/larynx/response.rb', line 37 def executed? event_name == 'CHANNEL_EXECUTE_COMPLETE' end |
#executing? ⇒ Boolean
33 34 35 |
# File 'lib/larynx/response.rb', line 33 def executing? event_name == 'CHANNEL_EXECUTE' end |
#ok? ⇒ Boolean
25 26 27 |
# File 'lib/larynx/response.rb', line 25 def ok? @header[:reply_text] =~ /\+OK/ end |
#reply? ⇒ Boolean
17 18 19 |
# File 'lib/larynx/response.rb', line 17 def reply? @header[:content_type] == 'command/reply' end |
#speech? ⇒ Boolean
53 54 55 |
# File 'lib/larynx/response.rb', line 53 def speech? @body[:event_name] == 'DETECTED_SPEECH' if @body end |