diff --git a/README.md b/README.md index 7d1ed7b..bdd75bc 100644 --- a/README.md +++ b/README.md @@ -138,6 +138,13 @@ To get a list of sip peers (equivalent to "sip show peers" call on the asterisk @ami.sip_peers ``` +### STATUS + +To get a status of a single channel or for all channels +```ruby + @ami.status +``` + ### THE RESPONSE OBJECT The response object contains all information about all data received from Asterisk. Here follows a list of all object's properties: diff --git a/lib/ruby-asterisk.rb b/lib/ruby-asterisk.rb index e2b7044..4562591 100644 --- a/lib/ruby-asterisk.rb +++ b/lib/ruby-asterisk.rb @@ -92,8 +92,8 @@ def parked_calls Response.new("ParkedCalls",request.response_data) end - def extension_state(exten,context) - request = Request.new("ExtensionState",{"Exten" => exten, "Context" => context}) + def extension_state(exten, context, action_id=nil) + request = Request.new("ExtensionState",{"Exten" => exten, "Context" => context, "ActionID" => action_id}) request.commands.each do |command| @session.write(command) end @@ -125,6 +125,17 @@ def skinny_lines Response.new("SKINNYlines",request.response_data) end + def status(channel=nil,action_id=nil) + request = Request.new("Status",{"Channel" => channel, "ActionID" => action_id}) + request.commands.each do |command| + @session.write(command) + end + @session.waitfor("String" => "ActionID: "+request.action_id, "Timeout" => 3) do |data| + request.response_data << data + end + Response.new("Status",request.response_data) + end + def originate(caller,context,callee,priority,variable=nil) request = Request.new("Originate",{"Channel" => caller, "Context" => context, "Exten" => callee, "Priority" => priority, "Callerid" => caller, "Timeout" => "30000", "Variable" => variable }) request.commands.each do |command| diff --git a/lib/ruby-asterisk/response.rb b/lib/ruby-asterisk/response.rb index 15b5725..bba6a44 100644 --- a/lib/ruby-asterisk/response.rb +++ b/lib/ruby-asterisk/response.rb @@ -45,6 +45,8 @@ def _parse_data(response) self._parse_originate(response) when "MeetMeList" self._parse_meet_me_list(response) + when "Status" + self._parse_status(response) when "ExtensionState" self._parse_extension_state(response) when "SKINNYdevices" @@ -110,6 +112,10 @@ def _parse_event_mask(response) _data = self._parse_objects(response, :event_mask, "Ping:") end + def _parse_status(response) + self._parse_objects(response, :status, "Event: Status") + end + def _convert_status(_data) _data[:hints].each do |hint| case hint["Status"]