Class: RubyAMI::Response

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

Overview

This is the object containing a response from Asterisk.

Direct Known Subclasses

Event

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(headers = {}) ⇒ Response

Returns a new instance of Response.



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

def initialize(headers = {})
  @headers = headers
  @events = []
end

Instance Attribute Details

#eventsObject

For “Response: Follows” sections



15
16
17
# File 'lib/ruby_ami/response.rb', line 15

def events
  @events
end

#text_bodyObject

For “Response: Follows” sections



15
16
17
# File 'lib/ruby_ami/response.rb', line 15

def text_body
  @text_body
end

Class Method Details

.from_immediate_response(text) ⇒ Object



8
9
10
11
12
# File 'lib/ruby_ami/response.rb', line 8

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

Instance Method Details

#[](arg) ⇒ Object



35
36
37
# File 'lib/ruby_ami/response.rb', line 35

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

#[]=(key, value) ⇒ Object



39
40
41
# File 'lib/ruby_ami/response.rb', line 39

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

#action_idObject



43
44
45
# File 'lib/ruby_ami/response.rb', line 43

def action_id
  @headers['ActionID']
end

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

Returns:

  • (Boolean)


55
56
57
# File 'lib/ruby_ami/response.rb', line 55

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)


23
24
25
# File 'lib/ruby_ami/response.rb', line 23

def has_text_body?
  !!@text_body
end

#headersObject



27
28
29
# File 'lib/ruby_ami/response.rb', line 27

def headers
  @headers.clone
end

#inspectObject



47
48
49
# File 'lib/ruby_ami/response.rb', line 47

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

#inspect_attributesObject



51
52
53
# File 'lib/ruby_ami/response.rb', line 51

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

#merge_headers!(hash) ⇒ Object



31
32
33
# File 'lib/ruby_ami/response.rb', line 31

def merge_headers!(hash)
  @headers.merge!(hash)
end