Class: Larynx::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/larynx/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#bodyObject (readonly)

Returns the value of attribute body.



3
4
5
# File 'lib/larynx/response.rb', line 3

def body
  @body
end

#headerObject (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

Returns:

  • (Boolean)


13
14
15
# File 'lib/larynx/response.rb', line 13

def answered?
  executed? && command_name == 'answer' #event_name == 'CHANNEL_ANSWER'
end

#command_nameObject



41
42
43
# File 'lib/larynx/response.rb', line 41

def command_name
  @body[:application] if @body
end

#disconnect?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/larynx/response.rb', line 57

def disconnect?
  @header[:content_type] == 'text/disconnect-notice'
end

#dtmf?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/larynx/response.rb', line 49

def dtmf?
  @body[:event_name] == 'DTMF' if @body
end

#error?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/larynx/response.rb', line 29

def error?
  @header[:reply_text] =~ /ERR/
end

#event?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/larynx/response.rb', line 21

def event?
  @header[:content_type] == 'text/event-plain'
end

#event_nameObject



45
46
47
# File 'lib/larynx/response.rb', line 45

def event_name
  @body[:event_name] if @body
end

#executed?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/larynx/response.rb', line 37

def executed?
  event_name == 'CHANNEL_EXECUTE_COMPLETE'
end

#executing?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/larynx/response.rb', line 33

def executing?
  event_name == 'CHANNEL_EXECUTE'
end

#ok?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/larynx/response.rb', line 25

def ok?
  @header[:reply_text] =~ /\+OK/
end

#reply?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/larynx/response.rb', line 17

def reply?
  @header[:content_type] == 'command/reply'
end

#speech?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/larynx/response.rb', line 53

def speech?
  @body[:event_name] == 'DETECTED_SPEECH' if @body
end