Class: RubyAMI::Response

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

Overview

This is the object containing a response from Asterisk.

Note: not all responses have an ActionID!

Direct Known Subclasses

Event

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeResponse

Returns a new instance of Response.



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

def initialize
  @headers = Hash.new
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



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

def action
  @action
end

#eventsObject (readonly)

Returns the value of attribute events.



19
20
21
# File 'lib/ruby_ami/response.rb', line 19

def events
  @events
end

#text_bodyObject

Returns the value of attribute text_body.



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

def text_body
  @text_body
end

Class Method Details

.from_immediate_response(text) ⇒ Object



10
11
12
13
14
# File 'lib/ruby_ami/response.rb', line 10

def from_immediate_response(text)
  new.tap do |instance|
    instance.text_body = text
  end
end

Instance Method Details

#[](arg) ⇒ Object



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

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

#[]=(key, value) ⇒ Object



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

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

#action_idObject



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

def action_id
  @headers['ActionID']
end

#eql?(o, *fields) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


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

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

#has_text_body?Boolean

Returns:

  • (Boolean)


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

def has_text_body?
  !!@text_body
end

#headersObject



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

def headers
  @headers.clone
end

#inspectObject



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

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

#inspect_attributesObject



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

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