Module: Sinatra::Asterisk
- Defined in:
- lib/sinatra/asterisk.rb,
lib/sinatra/asterisk/utils.rb,
lib/sinatra/asterisk/version.rb
Defined Under Namespace
Modules: Helpers, Utils
Classes: SinatraAgiScript, SinatraManagerEventListener
Constant Summary
collapse
- VERSION =
"0.0.3"
Instance Method Summary
collapse
Instance Method Details
#agi(uri_pattern = nil, conditions = {}, &block) ⇒ Object
118
119
120
121
|
# File 'lib/sinatra/asterisk.rb', line 118
def agi(uri_pattern = nil, conditions = {}, &block)
uri_pattern = Regexp::new(uri_pattern) if uri_pattern && !uri_pattern.respond_to?(:match)
agi_handlers << [uri_pattern, conditions, Proc::new(&block)]
end
|
#connect_to_manager(hostname, username, password) ⇒ Object
104
105
106
107
108
109
110
111
|
# File 'lib/sinatra/asterisk.rb', line 104
def connect_to_manager(hostname, username, password)
factory = ManagerConnectionFactory::new(hostname, username, password)
manager_connection = factory.createManagerConnection
initialize_manager_event_listener(manager_connection)
manager_connection.login
set :manager, manager_connection
end
|
#initialize_manager_event_listener(manager_connection) ⇒ Object
113
114
115
116
|
# File 'lib/sinatra/asterisk.rb', line 113
def initialize_manager_event_listener(manager_connection)
@manager_event_listener = SinatraManagerEventListener::new(event_handlers, settings)
manager_connection.addEventListener(@manager_event_listener)
end
|
#on_event(event_class = nil, &block) ⇒ Object
123
124
125
|
# File 'lib/sinatra/asterisk.rb', line 123
def on_event(event_class = nil, &block)
event_handlers << [event_class, Proc::new(&block)]
end
|
#start_agi_server(port = 4573) ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/sinatra/asterisk.rb', line 85
def start_agi_server(port = 4573)
@agi_script = SinatraAgiScript::new
@agi_script.agi_handlers = agi_handlers
@agi_script.sinatra_app = settings
@agi_server = DefaultAgiServer::new()
@agi_server.port = port
@agi_server.mappingStrategy = @agi_script
Thread.new do
begin
@agi_server.startup
rescue => e
puts "ERROR: #{e}: #{e.backtrace.join("\n")}"
end
end
end
|