Class: Adhearsion::VoIP::Asterisk::Manager::ManagerInterface::ManagerInterfaceAction
- Inherits:
-
Object
- Object
- Adhearsion::VoIP::Asterisk::Manager::ManagerInterface::ManagerInterfaceAction
- Defined in:
- lib/adhearsion/voip/asterisk/manager_interface.rb
Overview
Each time ManagerInterface#send_action is invoked, a new ManagerInterfaceAction is instantiated.
Instance Attribute Summary collapse
-
#action_id ⇒ Object
readonly
Returns the value of attribute action_id.
-
#causal_event_terminator_name ⇒ Object
readonly
Returns the value of attribute causal_event_terminator_name.
-
#future_resource ⇒ Object
readonly
Returns the value of attribute future_resource.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#has_causal_events? ⇒ Boolean
Some AMI actions effectively respond with many events which collectively constitute the actual response.
-
#initialize(name, headers = {}) ⇒ ManagerInterfaceAction
constructor
A new instance of ManagerInterfaceAction.
-
#new_action_id ⇒ String
Abstracts the generation of new ActionIDs.
-
#replies_with_action_id? ⇒ Boolean
Used internally by ManagerInterface for the actions in AMI which break the protocol’s definition and do not reply with an ActionID.
-
#response ⇒ Object
If the response has simply not been received yet from Asterisk, the calling Thread will block until it comes in.
-
#to_s ⇒ Object
Converts this action into a protocol-valid String, ready to be sent over a socket.
Constructor Details
#initialize(name, headers = {}) ⇒ ManagerInterfaceAction
Returns a new instance of ManagerInterfaceAction.
646 647 648 649 650 651 652 |
# File 'lib/adhearsion/voip/asterisk/manager_interface.rb', line 646 def initialize(name, headers={}) @name = name.to_s.downcase.freeze @headers = headers.stringify_keys.freeze @action_id = new_action_id.freeze @future_resource = FutureResource.new @causal_event_terminator_name = ManagerInterface.causal_event_terminator_name_for name end |
Instance Attribute Details
#action_id ⇒ Object (readonly)
Returns the value of attribute action_id.
645 646 647 |
# File 'lib/adhearsion/voip/asterisk/manager_interface.rb', line 645 def action_id @action_id end |
#causal_event_terminator_name ⇒ Object (readonly)
Returns the value of attribute causal_event_terminator_name.
645 646 647 |
# File 'lib/adhearsion/voip/asterisk/manager_interface.rb', line 645 def causal_event_terminator_name @causal_event_terminator_name end |
#future_resource ⇒ Object (readonly)
Returns the value of attribute future_resource.
645 646 647 |
# File 'lib/adhearsion/voip/asterisk/manager_interface.rb', line 645 def future_resource @future_resource end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
645 646 647 |
# File 'lib/adhearsion/voip/asterisk/manager_interface.rb', line 645 def headers @headers end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
645 646 647 |
# File 'lib/adhearsion/voip/asterisk/manager_interface.rb', line 645 def name @name end |
Instance Method Details
#has_causal_events? ⇒ Boolean
Some AMI actions effectively respond with many events which collectively constitute the actual response. These Must be handled specially by the protocol parser, so this method helps inform the parser.
666 667 668 |
# File 'lib/adhearsion/voip/asterisk/manager_interface.rb', line 666 def has_causal_events? ManagerInterface.has_causal_events?(@name, @headers) end |
#new_action_id ⇒ String
Abstracts the generation of new ActionIDs. This could be implemented virutally any way, provided each invocation returns something unique, so this will generate a GUID and return it.
676 677 678 |
# File 'lib/adhearsion/voip/asterisk/manager_interface.rb', line 676 def new_action_id new_guid # Implemented in lib/adhearsion/foundation/pseudo_guid.rb end |
#replies_with_action_id? ⇒ Boolean
Used internally by ManagerInterface for the actions in AMI which break the protocol’s definition and do not reply with an ActionID.
658 659 660 |
# File 'lib/adhearsion/voip/asterisk/manager_interface.rb', line 658 def replies_with_action_id? ManagerInterface.replies_with_action_id?(@name, @headers) end |
#response ⇒ Object
If the response has simply not been received yet from Asterisk, the calling Thread will block until it comes in. Once the response comes in, subsequent calls immediately return a reference to the ManagerInterfaceResponse object.
696 697 698 |
# File 'lib/adhearsion/voip/asterisk/manager_interface.rb', line 696 def response future_resource.resource end |
#to_s ⇒ Object
Converts this action into a protocol-valid String, ready to be sent over a socket.
683 684 685 686 687 688 689 |
# File 'lib/adhearsion/voip/asterisk/manager_interface.rb', line 683 def to_s @textual_representation ||= ( "Action: #{@name}\r\nActionID: #{@action_id}\r\n" + @headers.map { |(key,value)| "#{key}: #{value}" }.join("\r\n") + (@headers.any? ? "\r\n\r\n" : "\r\n") ) end |