Sha256: c7029fda70c9758db5a95409ad82d68076349e80a5c709e12cc2b1224dc5ee32

Contents?: true

Size: 1.13 KB

Versions: 6

Compression:

Stored size: 1.13 KB

Contents

module RubyAMI
  ##
  # This is the object containing a response from Asterisk.
  #
  # Note: not all responses have an ActionID!
  #
  class Response
    class << self
      def from_immediate_response(text)
        new.tap do |instance|
          instance.text_body = text
        end
      end
    end

    attr_accessor :action,
                  :text_body  # For "Response: Follows" sections
    attr_reader   :events

    def initialize
      @headers = Hash.new
    end

    def has_text_body?
      !!@text_body
    end

    def headers
      @headers.clone
    end

    def [](arg)
      @headers[arg.to_s]
    end

    def []=(key,value)
      @headers[key.to_s] = value
    end

    def action_id
      @headers['ActionID']
    end

    def inspect
      "#<#{self.class} #{inspect_attributes.map { |c| "#{c}=#{self.__send__(c).inspect rescue nil}" }.compact * ', '}>"
    end

    def inspect_attributes
      [:headers, :text_body, :events, :action]
    end

    def eql?(o, *fields)
      o.is_a?(self.class) && (fields + inspect_attributes).all? { |f| self.__send__(f) == o.__send__(f) }
    end
    alias :== :eql?
  end
end # RubyAMI

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ruby_ami-1.2.3 lib/ruby_ami/response.rb
ruby_ami-1.2.2 lib/ruby_ami/response.rb
ruby_ami-1.2.1 lib/ruby_ami/response.rb
ruby_ami-1.2.0 lib/ruby_ami/response.rb
ruby_ami-1.1.2 lib/ruby_ami/response.rb
ruby_ami-1.1.1 lib/ruby_ami/response.rb