Sha256: c4b8c4e83c9db6eb08398a5ec8a63cf8e96042a68ca9005a06bdf9fda6e2ae85

Contents?: true

Size: 1.16 KB

Versions: 4

Compression:

Stored size: 1.16 KB

Contents

module Larynx
  class Response
    attr_reader :header, :body

    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

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

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

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

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

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

    def executing?
      event_name == 'CHANNEL_EXECUTE'
    end

    def executed?
      event_name == 'CHANNEL_EXECUTE_COMPLETE'
    end

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

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

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

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

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
larynx-0.1.6 lib/larynx/response.rb
larynx-0.1.5 lib/larynx/response.rb
larynx-0.1.4 lib/larynx/response.rb
larynx-0.1.3 lib/larynx/response.rb