Class: Freeswitch::ESL::Protocol::Message
- Inherits:
-
Object
- Object
- Freeswitch::ESL::Protocol::Message
- Defined in:
- lib/freeswitch/esl/protocol/message.rb
Overview
Represents a raw ESL protocol message (headers + optional body).
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #content_type ⇒ Object
- #error_message ⇒ Object
-
#initialize(headers, body = nil) ⇒ Message
constructor
A new instance of Message.
- #reply_text ⇒ Object
- #successful? ⇒ Boolean
Constructor Details
#initialize(headers, body = nil) ⇒ Message
Returns a new instance of Message.
10 11 12 13 |
# File 'lib/freeswitch/esl/protocol/message.rb', line 10 def initialize(headers, body = nil) @headers = headers.freeze @body = body&.freeze end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
8 9 10 |
# File 'lib/freeswitch/esl/protocol/message.rb', line 8 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
8 9 10 |
# File 'lib/freeswitch/esl/protocol/message.rb', line 8 def headers @headers end |
Instance Method Details
#[](key) ⇒ Object
15 16 17 |
# File 'lib/freeswitch/esl/protocol/message.rb', line 15 def [](key) headers[key] end |
#content_type ⇒ Object
19 20 21 |
# File 'lib/freeswitch/esl/protocol/message.rb', line 19 def content_type headers["Content-Type"] end |
#error_message ⇒ Object
35 36 37 38 |
# File 'lib/freeswitch/esl/protocol/message.rb', line 35 def text = content_type == "api/response" ? body : reply_text text&.start_with?("-ERR") ? text.sub(/\A-ERR\s*/, "").strip : nil end |
#reply_text ⇒ Object
23 24 25 |
# File 'lib/freeswitch/esl/protocol/message.rb', line 23 def reply_text headers["Reply-Text"] end |
#successful? ⇒ Boolean
27 28 29 30 31 32 33 |
# File 'lib/freeswitch/esl/protocol/message.rb', line 27 def successful? if content_type == "api/response" body&.start_with?("+OK") else reply_text&.start_with?("+OK") end end |