sevenscale-adhearsion 0.7.1003 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +8 -2
- data/EVENTS +11 -0
- data/Rakefile +92 -26
- data/adhearsion.gemspec +131 -23
- data/app_generators/ahn/ahn_generator.rb +21 -7
- data/app_generators/ahn/templates/.ahnrc +10 -4
- data/app_generators/ahn/templates/Rakefile +7 -2
- data/app_generators/ahn/templates/components/ami_remote/ami_remote.rb +15 -0
- data/app_generators/ahn/templates/components/disabled/HOW_TO_ENABLE +7 -0
- data/app_generators/ahn/templates/components/disabled/stomp_gateway/README.markdown +47 -0
- data/app_generators/ahn/templates/components/disabled/stomp_gateway/config.yml +12 -0
- data/app_generators/ahn/templates/components/disabled/stomp_gateway/stomp_gateway.rb +34 -0
- data/app_generators/ahn/templates/components/simon_game/{lib/simon_game.rb → simon_game.rb} +14 -19
- data/app_generators/ahn/templates/config/startup.rb +3 -6
- data/app_generators/ahn/templates/dialplan.rb +2 -3
- data/app_generators/ahn/templates/events.rb +32 -6
- data/bin/jahn +10 -0
- data/examples/asterisk_manager_interface/standalone.rb +51 -0
- data/lib/adhearsion/cli.rb +140 -23
- data/lib/adhearsion/component_manager/component_tester.rb +55 -0
- data/lib/adhearsion/component_manager/spec_framework.rb +24 -0
- data/lib/adhearsion/component_manager.rb +169 -238
- data/lib/adhearsion/events_support.rb +59 -237
- data/lib/adhearsion/{core_extensions → foundation}/all.rb +0 -0
- data/lib/adhearsion/{blank_slate.rb → foundation/blank_slate.rb} +0 -0
- data/lib/adhearsion/{core_extensions → foundation}/custom_daemonizer.rb +0 -0
- data/lib/adhearsion/foundation/event_socket.rb +203 -0
- data/lib/adhearsion/foundation/future_resource.rb +36 -0
- data/lib/adhearsion/{core_extensions → foundation}/global.rb +0 -0
- data/lib/adhearsion/{core_extensions → foundation}/metaprogramming.rb +0 -0
- data/lib/adhearsion/foundation/numeric.rb +13 -0
- data/lib/adhearsion/foundation/pseudo_guid.rb +10 -0
- data/lib/adhearsion/{core_extensions → foundation}/relationship_properties.rb +2 -0
- data/lib/adhearsion/foundation/string.rb +26 -0
- data/lib/adhearsion/foundation/synchronized_hash.rb +96 -0
- data/lib/adhearsion/{core_extensions → foundation}/thread_safety.rb +0 -0
- data/lib/adhearsion/host_definitions.rb +5 -1
- data/lib/adhearsion/initializer/asterisk.rb +33 -11
- data/lib/adhearsion/initializer/configuration.rb +58 -6
- data/lib/adhearsion/initializer/database.rb +3 -46
- data/lib/adhearsion/initializer/drb.rb +9 -3
- data/lib/adhearsion/initializer/freeswitch.rb +3 -3
- data/lib/adhearsion/initializer/rails.rb +1 -1
- data/lib/adhearsion/initializer.rb +213 -87
- data/lib/adhearsion/tasks/deprecations.rb +59 -0
- data/lib/adhearsion/tasks.rb +2 -1
- data/lib/adhearsion/version.rb +3 -3
- data/lib/adhearsion/voip/asterisk/agi_server.rb +6 -6
- data/lib/adhearsion/voip/asterisk/commands.rb +100 -2
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rb +1754 -0
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb +286 -0
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_messages.rb +78 -0
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl +87 -0
- data/lib/adhearsion/voip/asterisk/manager_interface.rb +562 -0
- data/lib/adhearsion/voip/asterisk/super_manager.rb +19 -0
- data/lib/adhearsion/voip/asterisk.rb +1 -8
- data/lib/adhearsion/voip/call.rb +5 -1
- data/lib/adhearsion/voip/dial_plan.rb +74 -61
- data/lib/adhearsion/voip/dsl/dialing_dsl.rb +1 -1
- data/lib/adhearsion/voip/dsl/dialplan/parser.rb +2 -6
- data/lib/adhearsion/voip/dsl/numerical_string.rb +2 -2
- data/lib/adhearsion/voip/freeswitch/oes_server.rb +2 -2
- data/lib/adhearsion.rb +16 -11
- data/lib/theatre/README.markdown +64 -0
- data/lib/theatre/callback_definition_loader.rb +84 -0
- data/lib/theatre/guid.rb +23 -0
- data/lib/theatre/invocation.rb +121 -0
- data/lib/theatre/namespace_manager.rb +153 -0
- data/lib/theatre/version.rb +2 -0
- data/lib/theatre.rb +151 -0
- metadata +60 -147
- data/Manifest.txt +0 -151
- data/README.txt +0 -5
- data/ahn_generators/component/USAGE +0 -5
- data/ahn_generators/component/component_generator.rb +0 -57
- data/ahn_generators/component/templates/configuration.rb +0 -0
- data/ahn_generators/component/templates/lib/lib.rb.erb +0 -3
- data/ahn_generators/component/templates/test/test.rb.erb +0 -12
- data/ahn_generators/component/templates/test/test_helper.rb +0 -14
- data/app_generators/ahn/templates/components/simon_game/configuration.rb +0 -0
- data/app_generators/ahn/templates/components/simon_game/test/test_helper.rb +0 -14
- data/app_generators/ahn/templates/components/simon_game/test/test_simon_game.rb +0 -31
- data/lib/adhearsion/core_extensions/array.rb +0 -0
- data/lib/adhearsion/core_extensions/guid.rb +0 -5
- data/lib/adhearsion/core_extensions/hash.rb +0 -0
- data/lib/adhearsion/core_extensions/numeric.rb +0 -4
- data/lib/adhearsion/core_extensions/proc.rb +0 -0
- data/lib/adhearsion/core_extensions/pseudo_uuid.rb +0 -11
- data/lib/adhearsion/core_extensions/publishable.rb +0 -73
- data/lib/adhearsion/core_extensions/string.rb +0 -26
- data/lib/adhearsion/core_extensions/thread.rb +0 -13
- data/lib/adhearsion/core_extensions/time.rb +0 -0
- data/lib/adhearsion/distributed/gateways/dbus_gateway.rb +0 -0
- data/lib/adhearsion/distributed/gateways/osa_gateway.rb +0 -0
- data/lib/adhearsion/distributed/gateways/rest_gateway.rb +0 -9
- data/lib/adhearsion/distributed/gateways/soap_gateway.rb +0 -9
- data/lib/adhearsion/distributed/gateways/xmlrpc_gateway.rb +0 -9
- data/lib/adhearsion/distributed/peer_finder.rb +0 -0
- data/lib/adhearsion/distributed/remote_cli.rb +0 -0
- data/lib/adhearsion/hooks.rb +0 -57
- data/lib/adhearsion/initializer/paths.rb +0 -55
- data/lib/adhearsion/voip/asterisk/ami/actions.rb +0 -238
- data/lib/adhearsion/voip/asterisk/ami/machine.rb +0 -871
- data/lib/adhearsion/voip/asterisk/ami/machine.rl +0 -109
- data/lib/adhearsion/voip/asterisk/ami/parser.rb +0 -262
- data/lib/adhearsion/voip/asterisk/ami.rb +0 -147
- data/spec/fixtures/dialplan.rb +0 -3
- data/spec/initializer/test_configuration.rb +0 -267
- data/spec/initializer/test_loading.rb +0 -162
- data/spec/initializer/test_paths.rb +0 -43
- data/spec/sample.rb +0 -9
- data/spec/silence.rb +0 -10
- data/spec/test_ahn_command.rb +0 -149
- data/spec/test_code_quality.rb +0 -87
- data/spec/test_component_manager.rb +0 -97
- data/spec/test_constants.rb +0 -8
- data/spec/test_drb.rb +0 -104
- data/spec/test_events.rb +0 -136
- data/spec/test_helper.rb +0 -106
- data/spec/test_hooks.rb +0 -15
- data/spec/test_host_definitions.rb +0 -79
- data/spec/test_initialization.rb +0 -124
- data/spec/test_logging.rb +0 -80
- data/spec/test_relationship_properties.rb +0 -54
- data/spec/voip/asterisk/ami_response_definitions.rb +0 -23
- data/spec/voip/asterisk/config_file_generators/test_agents.rb +0 -253
- data/spec/voip/asterisk/config_file_generators/test_queues.rb +0 -325
- data/spec/voip/asterisk/config_file_generators/test_voicemail.rb +0 -306
- data/spec/voip/asterisk/menu_command/test_calculated_match.rb +0 -111
- data/spec/voip/asterisk/menu_command/test_matchers.rb +0 -98
- data/spec/voip/asterisk/mock_ami_server.rb +0 -176
- data/spec/voip/asterisk/test_agi_server.rb +0 -453
- data/spec/voip/asterisk/test_ami.rb +0 -227
- data/spec/voip/asterisk/test_commands.rb +0 -2006
- data/spec/voip/asterisk/test_config_manager.rb +0 -129
- data/spec/voip/dsl/dispatcher_spec_helper.rb +0 -45
- data/spec/voip/dsl/test_dialing_dsl.rb +0 -268
- data/spec/voip/dsl/test_dispatcher.rb +0 -82
- data/spec/voip/dsl/test_parser.rb +0 -87
- data/spec/voip/freeswitch/test_basic_connection_manager.rb +0 -39
- data/spec/voip/freeswitch/test_inbound_connection_manager.rb +0 -39
- data/spec/voip/freeswitch/test_oes_server.rb +0 -9
- data/spec/voip/test_call_routing.rb +0 -127
- data/spec/voip/test_dialplan_manager.rb +0 -442
- data/spec/voip/test_numerical_string.rb +0 -48
- data/spec/voip/test_phone_number.rb +0 -36
- data/test/test_ahn_generator.rb +0 -59
- data/test/test_component_generator.rb +0 -52
- data/test/test_generator_helper.rb +0 -20
@@ -1,111 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), *%w[.. .. .. test_helper])
|
2
|
-
require 'adhearsion/voip/menu_state_machine/calculated_match'
|
3
|
-
|
4
|
-
context 'CalculatedMatch' do
|
5
|
-
test "should make accessible the context name" do
|
6
|
-
Adhearsion::VoIP::CalculatedMatch.new(:match_payload => :foobar).match_payload.should.equal :foobar
|
7
|
-
end
|
8
|
-
test "should make accessible the original pattern" do
|
9
|
-
Adhearsion::VoIP::CalculatedMatch.new(:pattern => :something).pattern.should.equal :something
|
10
|
-
end
|
11
|
-
test "should make accessible the matched query" do
|
12
|
-
Adhearsion::VoIP::CalculatedMatch.new(:query => 123).query.should.equal 123
|
13
|
-
end
|
14
|
-
test '#type_of_match should return :exact, :potential, or nil' do
|
15
|
-
Adhearsion::VoIP::CalculatedMatch.new(:potential_matches => [1]).type_of_match.should.equal :potential
|
16
|
-
Adhearsion::VoIP::CalculatedMatch.new(:exact_matches => [3,3]).type_of_match.should.equal :exact
|
17
|
-
Adhearsion::VoIP::CalculatedMatch.new(:exact_matches => [8,3], :potential_matches => [0,9]).type_of_match.should.equal :exact
|
18
|
-
Adhearsion::VoIP::CalculatedMatch.new.type_of_match.should.equal nil
|
19
|
-
end
|
20
|
-
test '#exact_match? should return true if the match was exact' do
|
21
|
-
Adhearsion::VoIP::CalculatedMatch.new(:exact_matches => [0,3,5]).should.be.exact_match
|
22
|
-
end
|
23
|
-
|
24
|
-
test '#potential_match? should return true if the match was exact' do
|
25
|
-
Adhearsion::VoIP::CalculatedMatch.new(:potential_matches => [88,99,77]).should.be.potential_match
|
26
|
-
end
|
27
|
-
|
28
|
-
test '#exact_matches should return an array of exact matches' do
|
29
|
-
Adhearsion::VoIP::CalculatedMatch.new(:exact_matches => [0,3,5]).exact_matches.should == [0,3,5]
|
30
|
-
end
|
31
|
-
|
32
|
-
test '#potential_matches should return an array of potential matches' do
|
33
|
-
Adhearsion::VoIP::CalculatedMatch.new(:potential_matches => [88,99,77]).potential_matches.should == [88,99,77]
|
34
|
-
end
|
35
|
-
|
36
|
-
test '::failed_match! should return a match that *really* failed' do
|
37
|
-
failure = Adhearsion::VoIP::CalculatedMatch.failed_match! 10..20, 30, :match_payload_does_not_matter
|
38
|
-
failure.should.not.be.exact_match
|
39
|
-
failure.should.not.be.potential_match
|
40
|
-
failure.type_of_match.should.be nil
|
41
|
-
|
42
|
-
failure.match_payload.should.equal :match_payload_does_not_matter
|
43
|
-
failure.pattern.should == (10..20)
|
44
|
-
failure.query.should == 30
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
context 'CalculatedMatchCollection' do
|
50
|
-
|
51
|
-
include CalculatedMatchCollectionTestHelper
|
52
|
-
|
53
|
-
attr_reader :collection
|
54
|
-
before:each do
|
55
|
-
@collection = Adhearsion::VoIP::CalculatedMatchCollection.new
|
56
|
-
end
|
57
|
-
|
58
|
-
test 'the <<() method should collect the potential matches into the actual_potential_matches Array' do
|
59
|
-
mock_matches_array_1 = [:foo, :bar, :qaz],
|
60
|
-
mock_matches_array_2 = [10,20,30]
|
61
|
-
mock_matches_1 = mock_with_potential_matches mock_matches_array_1
|
62
|
-
mock_matches_2 = mock_with_potential_matches mock_matches_array_2
|
63
|
-
|
64
|
-
collection << mock_matches_1
|
65
|
-
collection.actual_potential_matches.should == mock_matches_array_1
|
66
|
-
|
67
|
-
collection << mock_matches_2
|
68
|
-
collection.actual_potential_matches.should == mock_matches_array_1 + mock_matches_array_2
|
69
|
-
end
|
70
|
-
|
71
|
-
test 'the <<() method should collect the exact matches into the actual_exact_matches Array' do
|
72
|
-
mock_matches_array_1 = [:blam, :blargh],
|
73
|
-
mock_matches_array_2 = [5,4,3,2,1]
|
74
|
-
mock_matches_1 = mock_with_exact_matches mock_matches_array_1
|
75
|
-
mock_matches_2 = mock_with_exact_matches mock_matches_array_2
|
76
|
-
|
77
|
-
collection << mock_matches_1
|
78
|
-
collection.actual_exact_matches.should == mock_matches_array_1
|
79
|
-
|
80
|
-
collection << mock_matches_2
|
81
|
-
collection.actual_exact_matches.should == mock_matches_array_1 + mock_matches_array_2
|
82
|
-
end
|
83
|
-
|
84
|
-
test "if any exact matches exist, the exact_match?() method should return true" do
|
85
|
-
collection << mock_with_exact_matches([1,2,3])
|
86
|
-
collection.should.be.exact_match
|
87
|
-
end
|
88
|
-
|
89
|
-
test "if any potential matches exist, the potential_match?() method should return true" do
|
90
|
-
collection << mock_with_potential_matches([1,2,3])
|
91
|
-
collection.should.be.potential_match
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
BEGIN {
|
96
|
-
module CalculatedMatchCollectionTestHelper
|
97
|
-
def mock_with_potential_matches(potential_matches)
|
98
|
-
Adhearsion::VoIP::CalculatedMatch.new :potential_matches => potential_matches
|
99
|
-
end
|
100
|
-
|
101
|
-
def mock_with_exact_matches(exact_matches)
|
102
|
-
Adhearsion::VoIP::CalculatedMatch.new :exact_matches => exact_matches
|
103
|
-
end
|
104
|
-
|
105
|
-
def mock_with_potential_and_exact_matches(potential_matches, exact_matches)
|
106
|
-
Adhearsion::VoIP::CalculatedMatch.new :potential_matches => potential_matches,
|
107
|
-
:exact_matches => exact_matches
|
108
|
-
end
|
109
|
-
|
110
|
-
end
|
111
|
-
}
|
@@ -1,98 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), *%w[.. .. .. test_helper])
|
2
|
-
require 'adhearsion/voip/menu_state_machine/menu_builder'
|
3
|
-
require 'adhearsion/voip/menu_state_machine/matchers'
|
4
|
-
|
5
|
-
context "MatchCalculator" do
|
6
|
-
test "the build_with_pattern() method should return an appropriate subclass instance based on the pattern's class" do
|
7
|
-
Adhearsion::VoIP::MatchCalculator.build_with_pattern(1..2, :main).should.be.instance_of Adhearsion::VoIP::RangeMatchCalculator
|
8
|
-
end
|
9
|
-
|
10
|
-
end
|
11
|
-
|
12
|
-
context "The RangeMatchCalculator" do
|
13
|
-
|
14
|
-
test "matching with a Range should handle the case of two potential matches in the range" do
|
15
|
-
digits_that_begin_with_eleven = [110..119, 1100..1111].map { |x| Array(x) }.flatten
|
16
|
-
|
17
|
-
calculator = Adhearsion::VoIP::RangeMatchCalculator.new 11..1111, :match_payload_doesnt_matter
|
18
|
-
match = calculator.match 11
|
19
|
-
match.exact_matches.should == [11]
|
20
|
-
match.potential_matches.should == digits_that_begin_with_eleven
|
21
|
-
end
|
22
|
-
|
23
|
-
test 'return values of #match should be an instance of CalculatedMatch' do
|
24
|
-
calculator = Adhearsion::VoIP::RangeMatchCalculator.new 1..9, :match_payload_doesnt_matter
|
25
|
-
calculator.match(0).should.be.instance_of Adhearsion::VoIP::CalculatedMatch
|
26
|
-
calculator.match(1000).should.be.instance_of Adhearsion::VoIP::CalculatedMatch
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
context "FixnumMatchCalculator" do
|
32
|
-
attr_reader :match_payload
|
33
|
-
before:each do
|
34
|
-
@match_payload = :main
|
35
|
-
end
|
36
|
-
|
37
|
-
test "a potential match scenario" do
|
38
|
-
calculator = Adhearsion::VoIP::FixnumMatchCalculator.new(444, match_payload)
|
39
|
-
match = calculator.match 4
|
40
|
-
match.should.be.potential_match
|
41
|
-
match.should.not.be.exact_match
|
42
|
-
match.potential_matches.should == [444]
|
43
|
-
end
|
44
|
-
|
45
|
-
test 'a multi-digit exact match scenario' do
|
46
|
-
calculator = Adhearsion::VoIP::FixnumMatchCalculator.new(5555, match_payload)
|
47
|
-
calculator.match(5555).should.be.exact_match
|
48
|
-
end
|
49
|
-
|
50
|
-
test 'a single-digit exact match scenario' do
|
51
|
-
calculator = Adhearsion::VoIP::FixnumMatchCalculator.new(1, match_payload)
|
52
|
-
calculator.match(1).should.be.exact_match
|
53
|
-
end
|
54
|
-
|
55
|
-
test 'the context name given to the calculator should be passed on to the CalculatedMatch' do
|
56
|
-
match_payload = :icanhascheezburger
|
57
|
-
calculator = Adhearsion::VoIP::FixnumMatchCalculator.new(1337, match_payload)
|
58
|
-
calculator.match(1337).match_payload.should.equal match_payload
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
context "StringMatchCalculator" do
|
64
|
-
|
65
|
-
attr_reader :match_payload
|
66
|
-
before:each do
|
67
|
-
@match_payload = :doesnt_matter
|
68
|
-
end
|
69
|
-
|
70
|
-
test "numerical digits mixed with special digits" do
|
71
|
-
|
72
|
-
%w[5*11#3 5*** ###].each do |str|
|
73
|
-
calculator = Adhearsion::VoIP::StringMatchCalculator.new(str, match_payload)
|
74
|
-
|
75
|
-
match_case = calculator.match str[0,2]
|
76
|
-
|
77
|
-
match_case.should.not.be.exact_match
|
78
|
-
match_case.should.be.potential_match
|
79
|
-
match_case.potential_matches.should == [str]
|
80
|
-
|
81
|
-
match_case = calculator.match str
|
82
|
-
match_case.should.be.exact_match
|
83
|
-
match_case.should.not.be.potential_match
|
84
|
-
match_case.exact_matches.should == [str]
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
test "matching the special DTMF characters such as * and #" do
|
89
|
-
%w[* #].each do |special_digit|
|
90
|
-
calculator = Adhearsion::VoIP::StringMatchCalculator.new(special_digit, match_payload)
|
91
|
-
match_case = calculator.match special_digit
|
92
|
-
match_case.should.not.be.potential_match
|
93
|
-
match_case.should.be.exact_match
|
94
|
-
match_case.exact_matches.first.should == special_digit
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
end
|
@@ -1,176 +0,0 @@
|
|
1
|
-
class AmiServer
|
2
|
-
class AMIResponseHelper
|
3
|
-
class << self
|
4
|
-
def bad_login_response
|
5
|
-
{ "Response" => "Error", "Message" => "Authentication failed" }
|
6
|
-
end
|
7
|
-
|
8
|
-
def good_login_response
|
9
|
-
{ "Response" => "Success", "Message" => "Authentication accepted" }
|
10
|
-
end
|
11
|
-
|
12
|
-
def follows_response
|
13
|
-
{ "Response" => "Follows", "Privilege" => "Command" }
|
14
|
-
end
|
15
|
-
|
16
|
-
def bad_dbget_response
|
17
|
-
{ "Response" => "Error", "Message" => "Database entry not found" }
|
18
|
-
end
|
19
|
-
|
20
|
-
def good_dbget_response
|
21
|
-
{ "Response" => "Success", "Message" => "Result will follow" }
|
22
|
-
end
|
23
|
-
|
24
|
-
def dbput_response
|
25
|
-
{ "Response" => "Success", "Message" => "Updated database successfully" }
|
26
|
-
end
|
27
|
-
|
28
|
-
def dbget_event_response
|
29
|
-
{ "Event" => "DBGetResponse" }
|
30
|
-
end
|
31
|
-
|
32
|
-
def queue_status_response
|
33
|
-
{ "Response" => "Success", "Message" => "Queue status will follow" }
|
34
|
-
end
|
35
|
-
|
36
|
-
def queue_status_event_complete_response
|
37
|
-
{ "Event" => "QueueStatusComplete" }
|
38
|
-
end
|
39
|
-
|
40
|
-
def queue_status_event_params_response
|
41
|
-
{ "Event" => "QueueParams", "Queue" => "default", "Max" => 0, "Min" => 0, "Holdtime" => 0,
|
42
|
-
"Completed" => 0, "Abandoned" => 0, "ServiceLevel" => 0, "ServiceLevelPerf" => 0 }
|
43
|
-
end
|
44
|
-
|
45
|
-
def events_on_response
|
46
|
-
{ "Response" => "Events On" }
|
47
|
-
end
|
48
|
-
|
49
|
-
def events_off_response
|
50
|
-
{ "Response" => "Events Off" }
|
51
|
-
end
|
52
|
-
|
53
|
-
def ping_response
|
54
|
-
{ "Response" => "Pong" }
|
55
|
-
end
|
56
|
-
|
57
|
-
def unrecognized_action
|
58
|
-
{ "Response" => "Error", "Message" => "Invalid/unknown command" }
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def initialize(*args)
|
64
|
-
@closed = false
|
65
|
-
@buffer = ""
|
66
|
-
@db = {}
|
67
|
-
extend MonitorMixin
|
68
|
-
fill(prompt, 1)
|
69
|
-
end
|
70
|
-
|
71
|
-
def closed?
|
72
|
-
@closed
|
73
|
-
end
|
74
|
-
|
75
|
-
def close
|
76
|
-
@closed = true
|
77
|
-
end
|
78
|
-
|
79
|
-
def read_nonblock(count)
|
80
|
-
str = @buffer.slice!(0..count-1)
|
81
|
-
raise Errno::EAGAIN if str == ""
|
82
|
-
str
|
83
|
-
end
|
84
|
-
|
85
|
-
def gets
|
86
|
-
@buffer.slice!(0..-1)
|
87
|
-
end
|
88
|
-
|
89
|
-
def write(str)
|
90
|
-
raise ArgumentError, "malformed request" if not str.ends_with?("\r\n\r\n")
|
91
|
-
args = str.split("\r\n").inject({}) { |accum, str| accum.merge!(YAML.load(str)) }
|
92
|
-
actionid = args['actionid']
|
93
|
-
case args['action']
|
94
|
-
when "login"
|
95
|
-
if args['username'] == username and args['secret'] == password
|
96
|
-
fill(response(actionid, AMIResponseHelper.good_login_response))
|
97
|
-
else
|
98
|
-
fill(response(actionid, AMIResponseHelper.bad_login_response))
|
99
|
-
end
|
100
|
-
when "queues"
|
101
|
-
fill("No Members\nNo Callers\r\n")
|
102
|
-
when "command"
|
103
|
-
case args['command']
|
104
|
-
when "show channels"
|
105
|
-
fill(response(actionid, AMIResponseHelper.follows_response), 1)
|
106
|
-
fill("Channel (Context Extension Pri ) State Appl. Data\n0 active channel(s)\n--END COMMAND--")
|
107
|
-
when "meetme list"
|
108
|
-
fill(response(actionid, AMIResponseHelper.follows_response), 1)
|
109
|
-
str = []
|
110
|
-
str << "Usage: meetme (un)lock|(un)mute|kick|list [concise] "
|
111
|
-
str << " Executes a command for the conference or on a conferee"
|
112
|
-
str << "--END COMMAND--"
|
113
|
-
fill(str.join("\n"))
|
114
|
-
else
|
115
|
-
fill(response(actionid, AMIResponseHelper.follows_response), 1)
|
116
|
-
fill("No such command '#{args['command']}' (type 'help' for help)\n--END COMMAND--")
|
117
|
-
end
|
118
|
-
when "dbget"
|
119
|
-
if not @db.has_key?(args['family']) or not @db[args['family']].has_key?(args['key'])
|
120
|
-
fill(response(actionid, AMIResponseHelper.bad_dbget_response))
|
121
|
-
else
|
122
|
-
val = @db[args['family']][args['key']]
|
123
|
-
fill(response(actionid, AMIResponseHelper.good_dbget_response))
|
124
|
-
fill(response(actionid, {
|
125
|
-
:Family => args['family'],
|
126
|
-
:Key => args['key'],
|
127
|
-
:Val => val }.merge!(AMIResponseHelper.dbget_event_response)))
|
128
|
-
end
|
129
|
-
when "dbput"
|
130
|
-
@db[args['family']] ||= {}
|
131
|
-
@db[args['family']][args['key']] = args['val']
|
132
|
-
fill(response(actionid, AMIResponseHelper.dbput_response))
|
133
|
-
when "queuestatus"
|
134
|
-
fill(response(actionid, AMIResponseHelper.queue_status_response))
|
135
|
-
fill(response(actionid, AMIResponseHelper.queue_status_event_params_response))
|
136
|
-
fill(response(actionid, AMIResponseHelper.queue_status_event_complete_response))
|
137
|
-
when "events"
|
138
|
-
if args['eventmask'] !~ /^on$/i
|
139
|
-
if args['eventmask'] =~ /^off$/i
|
140
|
-
fill(response(actionid, AMIResponseHelper.events_off_response))
|
141
|
-
else
|
142
|
-
fill(response(actionid, AMIResponseHelper.events_on_response))
|
143
|
-
end
|
144
|
-
end
|
145
|
-
when "ping"
|
146
|
-
fill(response(actionid, AMIResponseHelper.ping_response))
|
147
|
-
else
|
148
|
-
# raise ArgumentError, "Unknown action #{args['action']}"
|
149
|
-
fill(response(actionid, AMIResponseHelper.unrecognized_action))
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
private
|
154
|
-
|
155
|
-
def response(action_id, args = {})
|
156
|
-
resp = []
|
157
|
-
resp << "Response: #{args.delete('Response')}" if args['Response']
|
158
|
-
resp << "Privilege: #{args.delete('Privilege')}" if args['Privilege']
|
159
|
-
resp << "Event: #{args.delete('Event')}" if args['Event']
|
160
|
-
resp << "ActionID: #{action_id}"
|
161
|
-
resp << "Message: #{args.delete('Message')}" if args['Message']
|
162
|
-
args.inject(resp) do |accum, pair|
|
163
|
-
accum << "#{pair[0]}: #{pair[1]}"
|
164
|
-
end
|
165
|
-
resp.join("\r\n")
|
166
|
-
end
|
167
|
-
|
168
|
-
def fill(line, blanks=2)
|
169
|
-
@buffer += line
|
170
|
-
@buffer += "\r\n" * blanks
|
171
|
-
end
|
172
|
-
|
173
|
-
def prompt; "Asterisk Call Manager/1.0" end
|
174
|
-
def username; "admin" end
|
175
|
-
def password; "password" end
|
176
|
-
end
|