Class: RubyAMI::Response
- Inherits:
-
Object
- Object
- RubyAMI::Response
- Defined in:
- lib/ruby_ami/response.rb
Overview
This is the object containing a response from Asterisk.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#events ⇒ Object
For “Response: Follows” sections.
-
#text_body ⇒ Object
For “Response: Follows” sections.
Class Method Summary collapse
Instance Method Summary collapse
- #[](arg) ⇒ Object
- #[]=(key, value) ⇒ Object
- #action_id ⇒ Object
- #eql?(o, *fields) ⇒ Boolean (also: #==)
- #has_text_body? ⇒ Boolean
- #headers ⇒ Object
-
#initialize(headers = {}) ⇒ Response
constructor
A new instance of Response.
- #inspect ⇒ Object
- #inspect_attributes ⇒ Object
- #merge_headers!(hash) ⇒ Object
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
#events ⇒ Object
For “Response: Follows” sections
15 16 17 |
# File 'lib/ruby_ami/response.rb', line 15 def events @events end |
#text_body ⇒ Object
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_id ⇒ Object
43 44 45 |
# File 'lib/ruby_ami/response.rb', line 43 def action_id @headers['ActionID'] end |
#eql?(o, *fields) ⇒ Boolean Also known as: ==
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
23 24 25 |
# File 'lib/ruby_ami/response.rb', line 23 def has_text_body? !!@text_body end |
#headers ⇒ Object
27 28 29 |
# File 'lib/ruby_ami/response.rb', line 27 def headers @headers.clone end |
#inspect ⇒ Object
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_attributes ⇒ Object
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 |