Class: Punchblock::Connection::Asterisk

Inherits:
GenericConnection show all
Defined in:
lib/punchblock/connection/asterisk.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from GenericConnection

#not_ready!, #ready!

Constructor Details

#initialize(options = {}) ⇒ Asterisk

Returns a new instance of Asterisk.



9
10
11
12
13
# File 'lib/punchblock/connection/asterisk.rb', line 9

def initialize(options = {})
  @ami_client = RubyAMI::Client.new options.merge(:event_handler => lambda { |event| translator.handle_ami_event! event }, :logger => pb_logger)
  @translator = Translator::Asterisk.new @ami_client, self
  super()
end

Instance Attribute Details

#ami_clientObject (readonly)

Returns the value of attribute ami_client.



6
7
8
# File 'lib/punchblock/connection/asterisk.rb', line 6

def ami_client
  @ami_client
end

#event_handlerObject

Returns the value of attribute event_handler.



7
8
9
# File 'lib/punchblock/connection/asterisk.rb', line 7

def event_handler
  @event_handler
end

#translatorObject (readonly)

Returns the value of attribute translator.



6
7
8
# File 'lib/punchblock/connection/asterisk.rb', line 6

def translator
  @translator
end

Instance Method Details

#handle_event(event) ⇒ Object



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

def handle_event(event)
  event_handler.call event
end

#runObject



15
16
17
18
# File 'lib/punchblock/connection/asterisk.rb', line 15

def run
  pb_logger.debug "Starting the RubyAMI client"
  ami_client.start
end

#stopObject



20
21
22
23
# File 'lib/punchblock/connection/asterisk.rb', line 20

def stop
  translator.shutdown!
  ami_client.stop
end

#write(command, options) ⇒ Object



25
26
27
# File 'lib/punchblock/connection/asterisk.rb', line 25

def write(command, options)
  translator.execute_command! command, options
end