Class: Asterisk::Action

Inherits:
Object
  • Object
show all
Includes:
MessageHelper
Defined in:
lib/asterisk/action.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from MessageHelper

#add_line, #ami_lines, #camelize, included

Constructor Details

#initialize(command, options = {}) ⇒ Action

Returns a new instance of Action.



8
9
10
11
12
# File 'lib/asterisk/action.rb', line 8

def initialize(command, options={})
  @command = command
  @options = options
  @options[:action_id] = Random.rand(99999999) unless @options[:action_id]
end

Class Method Details

.parse(str) ⇒ Object



14
15
16
17
# File 'lib/asterisk/action.rb', line 14

def self.parse(str)
  hash = self.parse_lines(str)
  Asterisk::Action.new(hash.delete(:action), hash)
end

Instance Method Details

#action_idObject



24
25
26
# File 'lib/asterisk/action.rb', line 24

def action_id
  @options[:action_id]
end

#send(connection) ⇒ Object

send the ami action



20
21
22
# File 'lib/asterisk/action.rb', line 20

def send(connection)
  connection.write(self.to_ami)
end

#to_amiObject

convert the action to ami string to send down wire



29
30
31
# File 'lib/asterisk/action.rb', line 29

def to_ami
  ami_lines(@command, @options)
end

#to_hashObject



33
34
35
# File 'lib/asterisk/action.rb', line 33

def to_hash
  {:action => @command}.merge(@options)
end