Skip to content

Commit

Permalink
Merging commits from apardo fork - Added Status AMI command
Browse files Browse the repository at this point in the history
  • Loading branch information
Emiliano Della Casa committed Nov 7, 2013
2 parents 6c2cf80 + e54990a commit a85e40d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 13 additions & 2 deletions lib/ruby-asterisk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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|
Expand Down
6 changes: 6 additions & 0 deletions lib/ruby-asterisk/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"]
Expand Down

0 comments on commit a85e40d

Please sign in to comment.