Class: Freeswitch::ESL::Protocol::Event
- Inherits:
-
Object
- Object
- Freeswitch::ESL::Protocol::Event
- Defined in:
- lib/freeswitch/esl/protocol/event.rb
Overview
Represents a FreeSWITCH event received in JSON format.
Constant Summary collapse
- ERROR_BODY_PREFIX =
/\A\s*-(ERR|USAGE)\b/
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
-
#[](key) ⇒ Object?
Returns the raw value stored in the event payload for the given key.
-
#api_command ⇒ String?
Returns the command executed by a synchronous API event.
-
#bg_job_event? ⇒ Boolean
Returns whether the event represents a bgapi job completion.
-
#body ⇒ String?
Returns the optional event body payload.
-
#calling_file ⇒ String?
Returns the FreeSWITCH source file that emitted the event.
-
#calling_function ⇒ String?
Returns the FreeSWITCH source function that emitted the event.
-
#calling_line_number ⇒ String?
Returns the FreeSWITCH source line number that emitted the event.
-
#channel_variable(name) ⇒ String?
Returns the value of a channel variable exported in the event payload.
-
#core_uuid ⇒ String?
Returns the UUID of the emitting FreeSWITCH core instance.
-
#date_gmt ⇒ String?
Returns the event timestamp formatted in GMT.
-
#date_local ⇒ String?
Returns the event timestamp formatted in the server local timezone.
-
#error? ⇒ Boolean
Returns whether the event body represents an ESL command error.
-
#hostname ⇒ String?
Returns the hostname reported by the FreeSWITCH node.
-
#info ⇒ String?
Returns the human-readable informational text attached to the event.
-
#initialize(raw_json) ⇒ Event
constructor
A new instance of Event.
-
#ipv4 ⇒ String?
Returns the IPv4 address advertised by FreeSWITCH.
-
#ipv6 ⇒ String?
Returns the IPv6 address advertised by FreeSWITCH.
-
#job_command ⇒ String?
Returns the command executed by the background job.
-
#job_uuid ⇒ String?
Returns the UUID assigned to a background job.
-
#name ⇒ String?
Returns the canonical FreeSWITCH event name.
-
#sequence ⇒ String?
Returns the monotonic event sequence assigned by FreeSWITCH.
-
#subclass ⇒ String?
Returns the event subclass when the event provides one.
-
#switchname ⇒ String?
Returns the logical FreeSWITCH switch name.
-
#timestamp ⇒ String?
Returns the raw FreeSWITCH event timestamp.
-
#uuid ⇒ String?
Returns the channel UUID associated with the event.
Constructor Details
#initialize(raw_json) ⇒ Event
Returns a new instance of Event.
14 15 16 |
# File 'lib/freeswitch/esl/protocol/event.rb', line 14 def initialize(raw_json) @data = JSON.parse(raw_json).freeze end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
12 13 14 |
# File 'lib/freeswitch/esl/protocol/event.rb', line 12 def data @data end |
Instance Method Details
#[](key) ⇒ Object?
Returns the raw value stored in the event payload for the given key.
20 21 22 |
# File 'lib/freeswitch/esl/protocol/event.rb', line 20 def [](key) data[key] end |
#api_command ⇒ String?
Returns the command executed by a synchronous API event.
128 129 130 |
# File 'lib/freeswitch/esl/protocol/event.rb', line 128 def api_command data["API-Command"] end |
#bg_job_event? ⇒ Boolean
Returns whether the event represents a bgapi job completion.
146 147 148 |
# File 'lib/freeswitch/esl/protocol/event.rb', line 146 def bg_job_event? name == "BACKGROUND_JOB" end |
#body ⇒ String?
Returns the optional event body payload.
140 141 142 |
# File 'lib/freeswitch/esl/protocol/event.rb', line 140 def body data["_body"] end |
#calling_file ⇒ String?
Returns the FreeSWITCH source file that emitted the event.
86 87 88 |
# File 'lib/freeswitch/esl/protocol/event.rb', line 86 def calling_file data["Event-Calling-File"] end |
#calling_function ⇒ String?
Returns the FreeSWITCH source function that emitted the event.
92 93 94 |
# File 'lib/freeswitch/esl/protocol/event.rb', line 92 def calling_function data["Event-Calling-Function"] end |
#calling_line_number ⇒ String?
Returns the FreeSWITCH source line number that emitted the event.
98 99 100 |
# File 'lib/freeswitch/esl/protocol/event.rb', line 98 def calling_line_number data["Event-Calling-Line-Number"] end |
#channel_variable(name) ⇒ String?
Returns the value of a channel variable exported in the event payload.
159 160 161 |
# File 'lib/freeswitch/esl/protocol/event.rb', line 159 def channel_variable(name) data["variable_#{name}"] end |
#core_uuid ⇒ String?
Returns the UUID of the emitting FreeSWITCH core instance.
32 33 34 |
# File 'lib/freeswitch/esl/protocol/event.rb', line 32 def core_uuid data["Core-UUID"] end |
#date_gmt ⇒ String?
Returns the event timestamp formatted in GMT.
74 75 76 |
# File 'lib/freeswitch/esl/protocol/event.rb', line 74 def date_gmt data["Event-Date-GMT"] end |
#date_local ⇒ String?
Returns the event timestamp formatted in the server local timezone.
68 69 70 |
# File 'lib/freeswitch/esl/protocol/event.rb', line 68 def date_local data["Event-Date-Local"] end |
#error? ⇒ Boolean
Returns whether the event body represents an ESL command error.
153 154 155 |
# File 'lib/freeswitch/esl/protocol/event.rb', line 153 def error? body&.match?(ERROR_BODY_PREFIX) || false end |
#hostname ⇒ String?
Returns the hostname reported by the FreeSWITCH node.
38 39 40 |
# File 'lib/freeswitch/esl/protocol/event.rb', line 38 def hostname data["FreeSWITCH-Hostname"] end |
#info ⇒ String?
Returns the human-readable informational text attached to the event.
134 135 136 |
# File 'lib/freeswitch/esl/protocol/event.rb', line 134 def info data["Event-Info"] end |
#ipv4 ⇒ String?
Returns the IPv4 address advertised by FreeSWITCH.
50 51 52 |
# File 'lib/freeswitch/esl/protocol/event.rb', line 50 def ipv4 data["FreeSWITCH-IPv4"] end |
#ipv6 ⇒ String?
Returns the IPv6 address advertised by FreeSWITCH.
56 57 58 |
# File 'lib/freeswitch/esl/protocol/event.rb', line 56 def ipv6 data["FreeSWITCH-IPv6"] end |
#job_command ⇒ String?
Returns the command executed by the background job.
122 123 124 |
# File 'lib/freeswitch/esl/protocol/event.rb', line 122 def job_command data["Job-Command"] end |
#job_uuid ⇒ String?
Returns the UUID assigned to a background job.
116 117 118 |
# File 'lib/freeswitch/esl/protocol/event.rb', line 116 def job_uuid data["Job-UUID"] end |
#name ⇒ String?
Returns the canonical FreeSWITCH event name.
26 27 28 |
# File 'lib/freeswitch/esl/protocol/event.rb', line 26 def name data["Event-Name"] end |
#sequence ⇒ String?
Returns the monotonic event sequence assigned by FreeSWITCH.
104 105 106 |
# File 'lib/freeswitch/esl/protocol/event.rb', line 104 def sequence data["Event-Sequence"] end |
#subclass ⇒ String?
Returns the event subclass when the event provides one.
62 63 64 |
# File 'lib/freeswitch/esl/protocol/event.rb', line 62 def subclass data["Event-Subclass"] end |
#switchname ⇒ String?
Returns the logical FreeSWITCH switch name.
44 45 46 |
# File 'lib/freeswitch/esl/protocol/event.rb', line 44 def switchname data["FreeSWITCH-Switchname"] end |
#timestamp ⇒ String?
Returns the raw FreeSWITCH event timestamp.
80 81 82 |
# File 'lib/freeswitch/esl/protocol/event.rb', line 80 def data["Event-Date-Timestamp"] end |
#uuid ⇒ String?
Returns the channel UUID associated with the event.
110 111 112 |
# File 'lib/freeswitch/esl/protocol/event.rb', line 110 def uuid data["Unique-ID"] end |