adhearsion 2.6.4 → 3.0.0.beta1
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.
- checksums.yaml +4 -4
- data/.travis.yml +6 -9
- data/CHANGELOG.md +22 -7
- data/Gemfile +2 -0
- data/README.markdown +4 -5
- data/Rakefile +1 -2
- data/adhearsion.gemspec +19 -8
- data/features/cli_create.feature +19 -3
- data/features/step_definitions/cli_steps.rb +0 -11
- data/features/support/env.rb +3 -4
- data/lib/adhearsion.rb +48 -27
- data/lib/adhearsion/call.rb +34 -50
- data/lib/adhearsion/call_controller.rb +6 -12
- data/lib/adhearsion/call_controller/dial.rb +15 -53
- data/lib/adhearsion/call_controller/input.rb +39 -162
- data/lib/adhearsion/call_controller/input/ask_grammar_builder.rb +44 -0
- data/lib/adhearsion/call_controller/input/menu_builder.rb +136 -0
- data/lib/adhearsion/call_controller/input/prompt_builder.rb +78 -0
- data/lib/adhearsion/call_controller/input/result.rb +46 -0
- data/lib/adhearsion/call_controller/output.rb +48 -67
- data/lib/adhearsion/call_controller/output/abstract_player.rb +3 -3
- data/lib/adhearsion/call_controller/output/async_player.rb +3 -3
- data/lib/adhearsion/call_controller/output/player.rb +1 -1
- data/lib/adhearsion/call_controller/record.rb +23 -8
- data/lib/adhearsion/calls.rb +1 -1
- data/lib/adhearsion/cli_commands/ahn_command.rb +2 -65
- data/lib/adhearsion/cli_commands/thor_errors.rb +0 -6
- data/lib/adhearsion/configuration.rb +91 -39
- data/lib/adhearsion/core_ext/blather/stanza.rb +41 -0
- data/lib/adhearsion/core_ext/blather/stanza/presence.rb +13 -0
- data/lib/adhearsion/error.rb +5 -0
- data/lib/adhearsion/event.rb +21 -0
- data/lib/adhearsion/event/active_speaker.rb +11 -0
- data/lib/adhearsion/event/answered.rb +11 -0
- data/lib/adhearsion/event/asterisk.rb +10 -0
- data/lib/adhearsion/event/asterisk/ami.rb +34 -0
- data/lib/adhearsion/event/complete.rb +75 -0
- data/lib/adhearsion/event/dtmf.rb +11 -0
- data/lib/adhearsion/event/end.rb +22 -0
- data/lib/adhearsion/event/input_timers_started.rb +9 -0
- data/lib/adhearsion/event/joined.rb +17 -0
- data/lib/adhearsion/event/offer.rb +14 -0
- data/lib/adhearsion/event/ringing.rb +11 -0
- data/lib/adhearsion/event/started_speaking.rb +13 -0
- data/lib/adhearsion/event/stopped_speaking.rb +13 -0
- data/lib/adhearsion/event/unjoined.rb +17 -0
- data/lib/adhearsion/events.rb +47 -66
- data/lib/adhearsion/foundation.rb +0 -1
- data/lib/adhearsion/foundation/object.rb +0 -5
- data/lib/adhearsion/generators/app/app_generator.rb +4 -1
- data/lib/adhearsion/generators/app/templates/Gemfile.erb +2 -10
- data/lib/adhearsion/generators/app/templates/adhearsion.erb +9 -9
- data/lib/adhearsion/generators/app/templates/config.ru +7 -0
- data/lib/adhearsion/generators/app/templates/en.yml +4 -0
- data/lib/adhearsion/generators/app/templates/events.erb +2 -2
- data/lib/adhearsion/generators/app/templates/hello_world.wav +0 -0
- data/lib/adhearsion/generators/app/templates/simon_game.rb +2 -1
- data/lib/adhearsion/generators/app/templates/simon_game_spec.rb +2 -2
- data/lib/adhearsion/has_headers.rb +34 -0
- data/lib/adhearsion/http_server.rb +37 -0
- data/lib/adhearsion/initializer.rb +19 -153
- data/lib/adhearsion/logging.rb +6 -25
- data/lib/adhearsion/outbound_call.rb +5 -5
- data/lib/adhearsion/plugin.rb +1 -0
- data/lib/adhearsion/protocol_error.rb +26 -0
- data/lib/adhearsion/rayo.rb +30 -0
- data/lib/adhearsion/rayo/client.rb +62 -0
- data/lib/adhearsion/rayo/client/component_registry.rb +33 -0
- data/lib/adhearsion/rayo/command.rb +21 -0
- data/lib/adhearsion/rayo/command/accept.rb +16 -0
- data/lib/adhearsion/rayo/command/answer.rb +16 -0
- data/lib/adhearsion/rayo/command/dial.rb +57 -0
- data/lib/adhearsion/rayo/command/hangup.rb +16 -0
- data/lib/adhearsion/rayo/command/join.rb +43 -0
- data/lib/adhearsion/rayo/command/mute.rb +13 -0
- data/lib/adhearsion/rayo/command/redirect.rb +23 -0
- data/lib/adhearsion/rayo/command/reject.rb +40 -0
- data/lib/adhearsion/rayo/command/unjoin.rb +24 -0
- data/lib/adhearsion/rayo/command/unmute.rb +13 -0
- data/lib/adhearsion/rayo/command_node.rb +47 -0
- data/lib/adhearsion/rayo/component.rb +21 -0
- data/lib/adhearsion/rayo/component/asterisk.rb +13 -0
- data/lib/adhearsion/rayo/component/asterisk/agi.rb +14 -0
- data/lib/adhearsion/rayo/component/asterisk/agi/command.rb +46 -0
- data/lib/adhearsion/rayo/component/asterisk/ami.rb +14 -0
- data/lib/adhearsion/rayo/component/asterisk/ami/action.rb +61 -0
- data/lib/adhearsion/rayo/component/component_node.rb +90 -0
- data/lib/adhearsion/rayo/component/input.rb +186 -0
- data/lib/adhearsion/rayo/component/output.rb +471 -0
- data/lib/adhearsion/rayo/component/prompt.rb +53 -0
- data/lib/adhearsion/rayo/component/receive_fax.rb +26 -0
- data/lib/adhearsion/rayo/component/record.rb +165 -0
- data/lib/adhearsion/rayo/component/send_fax.rb +64 -0
- data/lib/adhearsion/rayo/component/stop.rb +11 -0
- data/lib/adhearsion/rayo/connection.rb +12 -0
- data/lib/adhearsion/rayo/connection/asterisk.rb +74 -0
- data/lib/adhearsion/rayo/connection/connected.rb +22 -0
- data/lib/adhearsion/rayo/connection/generic_connection.rb +22 -0
- data/lib/adhearsion/rayo/connection/xmpp.rb +198 -0
- data/lib/adhearsion/rayo/disconnected_error.rb +22 -0
- data/lib/adhearsion/{punchblock_plugin → rayo}/initializer.rb +19 -19
- data/lib/adhearsion/rayo/rayo_node.rb +127 -0
- data/lib/adhearsion/rayo/ref.rb +57 -0
- data/lib/adhearsion/statistics.rb +1 -1
- data/lib/adhearsion/tasks.rb +1 -2
- data/lib/adhearsion/tasks/configuration.rb +1 -1
- data/lib/adhearsion/tasks/environment.rb +0 -2
- data/lib/adhearsion/tasks/i18n.rb +49 -0
- data/lib/adhearsion/translator.rb +11 -0
- data/lib/adhearsion/translator/asterisk.rb +234 -0
- data/lib/adhearsion/translator/asterisk/agi_app.rb +17 -0
- data/lib/adhearsion/translator/asterisk/agi_command.rb +45 -0
- data/lib/adhearsion/translator/asterisk/ami_error_converter.rb +20 -0
- data/lib/adhearsion/translator/asterisk/call.rb +416 -0
- data/lib/adhearsion/translator/asterisk/channel.rb +43 -0
- data/lib/adhearsion/translator/asterisk/component.rb +88 -0
- data/lib/adhearsion/translator/asterisk/component/asterisk.rb +15 -0
- data/lib/adhearsion/translator/asterisk/component/asterisk/agi_command.rb +42 -0
- data/lib/adhearsion/translator/asterisk/component/asterisk/ami_action.rb +68 -0
- data/lib/adhearsion/translator/asterisk/component/composed_prompt.rb +76 -0
- data/lib/adhearsion/translator/asterisk/component/dtmf_recognizer.rb +137 -0
- data/lib/adhearsion/translator/asterisk/component/input.rb +34 -0
- data/lib/adhearsion/translator/asterisk/component/input_component.rb +90 -0
- data/lib/adhearsion/translator/asterisk/component/mrcp_native_prompt.rb +71 -0
- data/lib/adhearsion/translator/asterisk/component/mrcp_prompt.rb +55 -0
- data/lib/adhearsion/translator/asterisk/component/mrcp_recog_prompt.rb +165 -0
- data/lib/adhearsion/translator/asterisk/component/output.rb +233 -0
- data/lib/adhearsion/translator/asterisk/component/record.rb +101 -0
- data/lib/adhearsion/translator/asterisk/component/stop_by_redirect.rb +30 -0
- data/lib/adhearsion/translator/asterisk/unimrcp_app.rb +28 -0
- data/lib/adhearsion/uri_list.rb +21 -0
- data/lib/adhearsion/version.rb +1 -1
- data/spec/adhearsion/call_controller/dial_spec.rb +79 -1420
- data/spec/adhearsion/call_controller/input_spec.rb +1141 -237
- data/spec/adhearsion/call_controller/output/async_player_spec.rb +10 -10
- data/spec/adhearsion/call_controller/output/player_spec.rb +8 -8
- data/spec/adhearsion/call_controller/output_spec.rb +162 -215
- data/spec/adhearsion/call_controller/record_spec.rb +15 -16
- data/spec/adhearsion/call_controller_spec.rb +23 -40
- data/spec/adhearsion/call_spec.rb +123 -129
- data/spec/adhearsion/calls_spec.rb +3 -3
- data/spec/adhearsion/configuration_spec.rb +94 -108
- data/spec/adhearsion/event/answered_spec.rb +50 -0
- data/spec/adhearsion/event/asterisk/Find Results +402 -0
- data/spec/adhearsion/event/asterisk/ami_spec.rb +81 -0
- data/spec/adhearsion/event/complete_spec.rb +176 -0
- data/spec/adhearsion/event/dtmf_spec.rb +35 -0
- data/spec/adhearsion/event/end_spec.rb +85 -0
- data/spec/adhearsion/event/input_timers_started_spec.rb +19 -0
- data/spec/adhearsion/event/joined_spec.rb +53 -0
- data/spec/adhearsion/event/offer_spec.rb +106 -0
- data/spec/adhearsion/event/ringing_spec.rb +50 -0
- data/spec/adhearsion/event/started_speaking_spec.rb +37 -0
- data/spec/adhearsion/event/stopped_speaking_spec.rb +37 -0
- data/spec/adhearsion/event/unjoined_spec.rb +48 -0
- data/spec/adhearsion/event/untitled +0 -0
- data/spec/adhearsion/events_spec.rb +19 -45
- data/spec/adhearsion/initializer_spec.rb +12 -184
- data/spec/adhearsion/logging_spec.rb +5 -20
- data/spec/adhearsion/outbound_call_spec.rb +13 -13
- data/spec/adhearsion/plugin_spec.rb +3 -4
- data/spec/adhearsion/protocol_error_spec.rb +91 -0
- data/spec/adhearsion/rayo/client/component_registry_spec.rb +26 -0
- data/spec/adhearsion/rayo/client_spec.rb +134 -0
- data/spec/adhearsion/rayo/command/accept_spec.rb +63 -0
- data/spec/adhearsion/rayo/command/answer_spec.rb +73 -0
- data/spec/adhearsion/rayo/command/dial_spec.rb +156 -0
- data/spec/adhearsion/rayo/command/hangup_spec.rb +63 -0
- data/spec/adhearsion/rayo/command/join_spec.rb +158 -0
- data/spec/adhearsion/rayo/command/mute_spec.rb +32 -0
- data/spec/adhearsion/rayo/command/redirect_spec.rb +89 -0
- data/spec/adhearsion/rayo/command/reject_spec.rb +117 -0
- data/spec/adhearsion/rayo/command/unjoin_spec.rb +82 -0
- data/spec/adhearsion/rayo/command/unmute_spec.rb +32 -0
- data/spec/adhearsion/rayo/command_node_spec.rb +101 -0
- data/spec/adhearsion/rayo/component/asterisk/agi/command_spec.rb +111 -0
- data/spec/adhearsion/rayo/component/asterisk/ami/action_spec.rb +173 -0
- data/spec/adhearsion/rayo/component/component_node_spec.rb +110 -0
- data/spec/adhearsion/rayo/component/input_spec.rb +715 -0
- data/spec/adhearsion/rayo/component/output_spec.rb +1030 -0
- data/spec/adhearsion/rayo/component/prompt_spec.rb +171 -0
- data/spec/adhearsion/rayo/component/receive_fax_spec.rb +136 -0
- data/spec/adhearsion/rayo/component/record_spec.rb +497 -0
- data/spec/adhearsion/rayo/component/send_fax_spec.rb +144 -0
- data/spec/adhearsion/rayo/connection/asterisk_spec.rb +118 -0
- data/spec/adhearsion/rayo/connection/xmpp_spec.rb +449 -0
- data/spec/adhearsion/rayo/initializer_spec.rb +353 -0
- data/spec/adhearsion/rayo/ref_spec.rb +168 -0
- data/spec/adhearsion/rayo_spec.rb +7 -0
- data/spec/adhearsion/router/route_spec.rb +1 -1
- data/spec/adhearsion/statistics_spec.rb +2 -5
- data/spec/adhearsion/translator/asterisk/call_spec.rb +2047 -0
- data/spec/adhearsion/translator/asterisk/component/asterisk/agi_command_spec.rb +256 -0
- data/spec/adhearsion/translator/asterisk/component/asterisk/ami_action_spec.rb +151 -0
- data/spec/adhearsion/translator/asterisk/component/composed_prompt_spec.rb +257 -0
- data/spec/adhearsion/translator/asterisk/component/input_spec.rb +571 -0
- data/spec/adhearsion/translator/asterisk/component/mrcp_native_prompt_spec.rb +774 -0
- data/spec/adhearsion/translator/asterisk/component/mrcp_prompt_spec.rb +1244 -0
- data/spec/adhearsion/translator/asterisk/component/output_spec.rb +1850 -0
- data/spec/adhearsion/translator/asterisk/component/record_spec.rb +426 -0
- data/spec/adhearsion/translator/asterisk/component/stop_by_redirect_spec.rb +62 -0
- data/spec/adhearsion/translator/asterisk/component_spec.rb +83 -0
- data/spec/adhearsion/translator/asterisk_spec.rb +685 -0
- data/spec/adhearsion/uri_list_spec.rb +88 -0
- data/spec/adhearsion_spec.rb +89 -14
- data/spec/fixtures/locale/en.yml +13 -0
- data/spec/fixtures/locale/it.yml +13 -0
- data/spec/spec_helper.rb +18 -5
- data/spec/support/call_controller_test_helpers.rb +3 -2
- data/spec/support/initializer_stubs.rb +3 -1
- data/spec/support/punchblock_examples.rb +65 -0
- data/spec/support/punchblock_mocks.rb +12 -0
- metadata +412 -70
- data/features/cli_daemon.feature +0 -20
- data/features/cli_restart.feature +0 -52
- data/features/cli_stop.feature +0 -50
- data/lib/adhearsion/call_controller/menu_dsl.rb +0 -21
- data/lib/adhearsion/call_controller/menu_dsl/array_match_calculator.rb +0 -26
- data/lib/adhearsion/call_controller/menu_dsl/calculated_match.rb +0 -43
- data/lib/adhearsion/call_controller/menu_dsl/calculated_match_collection.rb +0 -45
- data/lib/adhearsion/call_controller/menu_dsl/fixnum_match_calculator.rb +0 -11
- data/lib/adhearsion/call_controller/menu_dsl/match_calculator.rb +0 -40
- data/lib/adhearsion/call_controller/menu_dsl/menu.rb +0 -207
- data/lib/adhearsion/call_controller/menu_dsl/menu_builder.rb +0 -92
- data/lib/adhearsion/call_controller/menu_dsl/range_match_calculator.rb +0 -60
- data/lib/adhearsion/call_controller/menu_dsl/string_match_calculator.rb +0 -25
- data/lib/adhearsion/call_controller/utility.rb +0 -77
- data/lib/adhearsion/foundation/custom_daemonizer.rb +0 -52
- data/lib/adhearsion/punchblock_plugin.rb +0 -63
- data/scripts/cloc-1.64.pl +0 -10483
- data/spec/adhearsion/call_controller/menu_dsl/array_match_calculator_spec.rb +0 -76
- data/spec/adhearsion/call_controller/menu_dsl/calculated_match_collection_spec.rb +0 -60
- data/spec/adhearsion/call_controller/menu_dsl/calculated_match_spec.rb +0 -61
- data/spec/adhearsion/call_controller/menu_dsl/fixnum_match_calculator_spec.rb +0 -39
- data/spec/adhearsion/call_controller/menu_dsl/match_calculator_spec.rb +0 -17
- data/spec/adhearsion/call_controller/menu_dsl/menu_builder_spec.rb +0 -165
- data/spec/adhearsion/call_controller/menu_dsl/menu_spec.rb +0 -420
- data/spec/adhearsion/call_controller/menu_dsl/range_match_calculator_spec.rb +0 -32
- data/spec/adhearsion/call_controller/menu_dsl/string_match_calculator_spec.rb +0 -40
- data/spec/adhearsion/call_controller/utility_spec.rb +0 -90
- data/spec/adhearsion/punchblock_plugin/initializer_spec.rb +0 -356
- data/spec/adhearsion/punchblock_plugin_spec.rb +0 -59
|
@@ -57,18 +57,8 @@ describe Adhearsion::Logging do
|
|
|
57
57
|
expect(::Logging.logger.root.appenders.select{|a| a.is_a?(::Logging::Appenders::Stdout)}.length).to eql(1)
|
|
58
58
|
end
|
|
59
59
|
|
|
60
|
-
it "initializes properly a Logging object with
|
|
61
|
-
Adhearsion::Logging.start(
|
|
62
|
-
expect(::Logging.logger.root.appenders.length).to eql(2)
|
|
63
|
-
expect(::Logging.logger.root.appenders.select{|a| a.is_a?(::Logging::Appenders::Stdout)}.length).to eql(1)
|
|
64
|
-
expect(::Logging.logger.root.appenders.select{|a| a.is_a?(::Logging::Appenders::File)}.length).to eql(1)
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
it "initializes properly a Logging object with appenders and log level as parameter" do
|
|
68
|
-
Adhearsion::Logging.start([::Logging.appenders.stdout, ::Logging.appenders.file('example.log')], :debug)
|
|
69
|
-
expect(::Logging.logger.root.appenders.length).to eql(2)
|
|
70
|
-
expect(::Logging.logger.root.appenders.select{|a| a.is_a?(::Logging::Appenders::Stdout)}.length).to eql(1)
|
|
71
|
-
expect(::Logging.logger.root.appenders.select{|a| a.is_a?(::Logging::Appenders::File)}.length).to eql(1)
|
|
60
|
+
it "initializes properly a Logging object with log level as parameter" do
|
|
61
|
+
Adhearsion::Logging.start(:debug)
|
|
72
62
|
expect(::Logging.logger.root.level).to eql(::Logging::LEVELS["debug"])
|
|
73
63
|
end
|
|
74
64
|
|
|
@@ -85,20 +75,15 @@ describe Adhearsion::Logging do
|
|
|
85
75
|
expect(_foo_logger.object_id).not_to eql(_bar_logger)
|
|
86
76
|
end
|
|
87
77
|
|
|
88
|
-
it 'should reopen logfiles' do
|
|
89
|
-
expect(::Logging).to receive(:reopen).once
|
|
90
|
-
Adhearsion::Logging.reopen_logs
|
|
91
|
-
end
|
|
92
|
-
|
|
93
78
|
it 'should toggle between :trace and the configured log level' do
|
|
94
|
-
orig_level = Adhearsion.config.
|
|
95
|
-
Adhearsion.config.
|
|
79
|
+
orig_level = Adhearsion.config.core.logging['level']
|
|
80
|
+
Adhearsion.config.core.logging['level'] = :warn
|
|
96
81
|
Adhearsion::Logging.level = :warn
|
|
97
82
|
Adhearsion::Logging.toggle_trace!
|
|
98
83
|
expect(Adhearsion::Logging.level).to eq(0)
|
|
99
84
|
Adhearsion::Logging.toggle_trace!
|
|
100
85
|
expect(Adhearsion::Logging.level).to eq(3)
|
|
101
|
-
Adhearsion.config.
|
|
86
|
+
Adhearsion.config.core.logging['level'] = orig_level
|
|
102
87
|
end
|
|
103
88
|
|
|
104
89
|
describe 'level changing' do
|
|
@@ -16,10 +16,10 @@ module Adhearsion
|
|
|
16
16
|
it { is_expected.to eq({}) }
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
let(:mock_client) { double '
|
|
19
|
+
let(:mock_client) { double 'Rayo Client', execute_command: true, new_call_uri: call_uri }
|
|
20
20
|
|
|
21
21
|
before do
|
|
22
|
-
|
|
22
|
+
Adhearsion::Rayo::Initializer.client = mock_client
|
|
23
23
|
Adhearsion.active_calls.clear
|
|
24
24
|
end
|
|
25
25
|
|
|
@@ -67,7 +67,7 @@ module Adhearsion
|
|
|
67
67
|
|
|
68
68
|
expect(Adhearsion.router).to receive(:handle).once.with(mock_call)
|
|
69
69
|
|
|
70
|
-
OutboundCall.originate(to) <<
|
|
70
|
+
OutboundCall.originate(to) << Adhearsion::Event::Answered.new
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
context "when a controller class is specified for the call" do
|
|
@@ -77,7 +77,7 @@ module Adhearsion
|
|
|
77
77
|
expect(mock_call).to receive(:dial).once.with(to, {})
|
|
78
78
|
expect(mock_call).to receive(:execute_controller).once.with kind_of(controller), kind_of(Proc)
|
|
79
79
|
call = OutboundCall.originate to, :controller => controller
|
|
80
|
-
call <<
|
|
80
|
+
call << Adhearsion::Event::Answered.new
|
|
81
81
|
end
|
|
82
82
|
|
|
83
83
|
it "should hangup the call after all controllers have executed" do
|
|
@@ -85,7 +85,7 @@ module Adhearsion
|
|
|
85
85
|
expect(mock_call).to receive(:hangup).once
|
|
86
86
|
|
|
87
87
|
call = OutboundCall.originate to, :controller => controller
|
|
88
|
-
call <<
|
|
88
|
+
call << Adhearsion::Event::Answered.new
|
|
89
89
|
sleep 0.5
|
|
90
90
|
end
|
|
91
91
|
|
|
@@ -95,7 +95,7 @@ module Adhearsion
|
|
|
95
95
|
expected_controller = controller.new mock_call, foo: 'bar'
|
|
96
96
|
expect(mock_call).to receive(:execute_controller).with(expected_controller, kind_of(Proc)).once
|
|
97
97
|
call = OutboundCall.originate to, :controller => controller, :controller_metadata => {:foo => 'bar'}
|
|
98
|
-
call <<
|
|
98
|
+
call << Adhearsion::Event::Answered.new
|
|
99
99
|
end
|
|
100
100
|
end
|
|
101
101
|
end
|
|
@@ -110,14 +110,14 @@ module Adhearsion
|
|
|
110
110
|
call = OutboundCall.originate to do
|
|
111
111
|
:foobar
|
|
112
112
|
end
|
|
113
|
-
call <<
|
|
113
|
+
call << Adhearsion::Event::Answered.new
|
|
114
114
|
end
|
|
115
115
|
end
|
|
116
116
|
|
|
117
117
|
context "when the dial fails" do
|
|
118
118
|
before do
|
|
119
119
|
expect(subject.wrapped_object).to receive(:write_command)
|
|
120
|
-
expect_any_instance_of(
|
|
120
|
+
expect_any_instance_of(Adhearsion::Rayo::Command::Dial).to receive(:response).and_return StandardError.new("User not registered")
|
|
121
121
|
end
|
|
122
122
|
|
|
123
123
|
after do
|
|
@@ -140,7 +140,7 @@ module Adhearsion
|
|
|
140
140
|
let(:response) { double 'Response' }
|
|
141
141
|
|
|
142
142
|
describe "for answered events" do
|
|
143
|
-
let(:event) {
|
|
143
|
+
let(:event) { Adhearsion::Event::Answered.new }
|
|
144
144
|
|
|
145
145
|
it "should trigger any on_answer callbacks set" do
|
|
146
146
|
expect(response).to receive(:call).once.with(event)
|
|
@@ -173,12 +173,12 @@ module Adhearsion
|
|
|
173
173
|
def expect_message_waiting_for_response(message, uri = call_uri)
|
|
174
174
|
expect(subject.wrapped_object).to receive(:write_and_await_response).once.with(message, 60, true) do |real_message|
|
|
175
175
|
real_message.request!
|
|
176
|
-
real_message.response =
|
|
176
|
+
real_message.response = Adhearsion::Rayo::Ref.new(uri: uri)
|
|
177
177
|
real_message
|
|
178
178
|
end
|
|
179
179
|
end
|
|
180
180
|
|
|
181
|
-
let(:expected_dial_command) {
|
|
181
|
+
let(:expected_dial_command) { Adhearsion::Rayo::Command::Dial.new(:to => to, :from => from, :uri => call_uri) }
|
|
182
182
|
|
|
183
183
|
context "while waiting for a response" do
|
|
184
184
|
before do
|
|
@@ -221,7 +221,7 @@ module Adhearsion
|
|
|
221
221
|
|
|
222
222
|
it "should set the dial command" do
|
|
223
223
|
subject.dial to, :from => from
|
|
224
|
-
expect(subject.dial_command).to eq(
|
|
224
|
+
expect(subject.dial_command).to eq(Adhearsion::Rayo::Command::Dial.new(:to => to, :from => from, :uri => call_uri, target_call_id: call_id, domain: domain, transport: transport))
|
|
225
225
|
end
|
|
226
226
|
|
|
227
227
|
it "should set the URI from the reference" do
|
|
@@ -296,7 +296,7 @@ module Adhearsion
|
|
|
296
296
|
context "when the dial fails" do
|
|
297
297
|
before do
|
|
298
298
|
expect(subject.wrapped_object).to receive(:write_command)
|
|
299
|
-
expect_any_instance_of(
|
|
299
|
+
expect_any_instance_of(Adhearsion::Rayo::Command::Dial).to receive(:response).and_return StandardError.new("User not registered")
|
|
300
300
|
end
|
|
301
301
|
|
|
302
302
|
after do
|
|
@@ -12,7 +12,7 @@ describe Adhearsion::Plugin do
|
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
before do
|
|
15
|
-
allow(Adhearsion::
|
|
15
|
+
allow(Adhearsion::Rayo::Initializer).to receive_messages :start => true
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
describe "inheritance" do
|
|
@@ -147,8 +147,7 @@ describe Adhearsion::Plugin do
|
|
|
147
147
|
it "should do nothing with a Plugin that has no init method call" do
|
|
148
148
|
FooBar = Class.new Adhearsion::Plugin
|
|
149
149
|
|
|
150
|
-
|
|
151
|
-
expect(Adhearsion::Plugin.initializers.size).to eq(1)
|
|
150
|
+
expect(Adhearsion::Plugin.initializers.size).to eq(0)
|
|
152
151
|
Adhearsion::Plugin.init_plugins
|
|
153
152
|
end
|
|
154
153
|
|
|
@@ -243,7 +242,7 @@ describe Adhearsion::Plugin do
|
|
|
243
242
|
it "should do nothing with a Plugin that has no run method call" do
|
|
244
243
|
FooBar = Class.new Adhearsion::Plugin
|
|
245
244
|
|
|
246
|
-
# May become 1 if
|
|
245
|
+
# May become 1 if Rayo defines a runner.
|
|
247
246
|
expect(Adhearsion::Plugin.runners.size).to eq(0)
|
|
248
247
|
Adhearsion::Plugin.run_plugins
|
|
249
248
|
end
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Adhearsion::ProtocolError do
|
|
6
|
+
let(:name) { :item_not_found }
|
|
7
|
+
let(:text) { 'Could not find call [id=f6d437f4-1e18-457b-99f8-b5d853f50347]' }
|
|
8
|
+
let(:call_id) { 'f6d437f4-1e18-457b-99f8-b5d853f50347' }
|
|
9
|
+
let(:component_id) { 'abc123' }
|
|
10
|
+
subject { described_class.new.setup name, text, call_id, component_id }
|
|
11
|
+
|
|
12
|
+
describe '#inspect' do
|
|
13
|
+
subject { super().inspect }
|
|
14
|
+
it { is_expected.to eq('#<Adhearsion::ProtocolError: name=:item_not_found text="Could not find call [id=f6d437f4-1e18-457b-99f8-b5d853f50347]" call_id="f6d437f4-1e18-457b-99f8-b5d853f50347" component_id="abc123">') }
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe ".exception" do
|
|
18
|
+
context "with no arguments" do
|
|
19
|
+
it "returns the original object" do
|
|
20
|
+
expect(described_class.exception).to eq(described_class.new)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
context "with self as the argument" do
|
|
25
|
+
it "returns the original object" do
|
|
26
|
+
expect(described_class.exception(subject)).to eq(described_class.new(subject.to_s))
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
context "with other values" do
|
|
31
|
+
it "returns a new object with the appropriate values" do
|
|
32
|
+
e = described_class.exception 'FooBar'
|
|
33
|
+
expect(e.name).to eq(nil)
|
|
34
|
+
expect(e.text).to eq(nil)
|
|
35
|
+
expect(e.call_id).to eq(nil)
|
|
36
|
+
expect(e.component_id).to eq(nil)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
describe "#exception" do
|
|
42
|
+
context "with no arguments" do
|
|
43
|
+
it "returns the original object" do
|
|
44
|
+
expect(subject.exception).to be subject
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
context "with self as the argument" do
|
|
49
|
+
it "returns the original object" do
|
|
50
|
+
expect(subject.exception(subject)).to be subject
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
context "with other values" do
|
|
55
|
+
it "returns a new object with the appropriate values" do
|
|
56
|
+
e = subject.exception("Boo")
|
|
57
|
+
expect(e.name).to eq(name)
|
|
58
|
+
expect(e.text).to eq(text)
|
|
59
|
+
expect(e.call_id).to eq(call_id)
|
|
60
|
+
expect(e.component_id).to eq(component_id)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
describe "comparison" do
|
|
66
|
+
context "with the same name, text, call ID and component ID" do
|
|
67
|
+
let(:comparison) { described_class.new.setup name, text, call_id, component_id }
|
|
68
|
+
it { is_expected.to eq(comparison) }
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
context "with a different name" do
|
|
72
|
+
let(:comparison) { described_class.new.setup :foo, text, call_id, component_id }
|
|
73
|
+
it { is_expected.not_to eq(comparison) }
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
context "with a different text" do
|
|
77
|
+
let(:comparison) { described_class.new.setup name, 'foo', call_id, component_id }
|
|
78
|
+
it { is_expected.not_to eq(comparison) }
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
context "with a different call ID" do
|
|
82
|
+
let(:comparison) { described_class.new.setup name, text, 'foo', component_id }
|
|
83
|
+
it { is_expected.not_to eq(comparison) }
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
context "with a different component ID" do
|
|
87
|
+
let(:comparison) { described_class.new.setup name, text, call_id, 'foo' }
|
|
88
|
+
it { is_expected.not_to eq(comparison) }
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
module Adhearsion
|
|
6
|
+
module Rayo
|
|
7
|
+
class Client
|
|
8
|
+
describe ComponentRegistry do
|
|
9
|
+
let(:uri) { 'abc123' }
|
|
10
|
+
let(:component) { double 'Component', source_uri: uri }
|
|
11
|
+
|
|
12
|
+
it 'should store components and allow lookup by ID' do
|
|
13
|
+
subject << component
|
|
14
|
+
expect(subject.find_by_uri(uri)).to be component
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'should allow deletion of components' do
|
|
18
|
+
subject << component
|
|
19
|
+
expect(subject.find_by_uri(uri)).to be component
|
|
20
|
+
subject.delete component
|
|
21
|
+
expect(subject.find_by_uri(uri)).to be_nil
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Adhearsion::Rayo::Client do
|
|
6
|
+
let(:connection) { Adhearsion::Rayo::Connection::XMPP.new :username => '1@call.rayo.net', :password => 1 }
|
|
7
|
+
|
|
8
|
+
subject { described_class.new :connection => connection }
|
|
9
|
+
|
|
10
|
+
describe '#connection' do
|
|
11
|
+
subject { super().connection }
|
|
12
|
+
it { is_expected.to be connection }
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
describe '#component_registry' do
|
|
16
|
+
subject { super().component_registry }
|
|
17
|
+
it { is_expected.to be_a described_class::ComponentRegistry }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
let(:call_id) { 'abc123' }
|
|
21
|
+
let(:mock_event) { double('Event').as_null_object }
|
|
22
|
+
let(:component_id) { 'abc123' }
|
|
23
|
+
let(:component_uri) { 'callid@server/abc123' }
|
|
24
|
+
let(:mock_component) { double 'Component', source_uri: component_uri }
|
|
25
|
+
let(:mock_command) { double 'Command' }
|
|
26
|
+
|
|
27
|
+
describe '#run' do
|
|
28
|
+
it 'should start up the connection' do
|
|
29
|
+
expect(connection).to receive(:run).once
|
|
30
|
+
subject.run
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
describe '#stop' do
|
|
35
|
+
it 'should stop the connection' do
|
|
36
|
+
expect(connection).to receive(:stop).once
|
|
37
|
+
subject.stop
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
describe '#send_message' do
|
|
42
|
+
it 'should send a message' do
|
|
43
|
+
args = [ "someone", "example.org", "Hello World!" ]
|
|
44
|
+
expect(connection).to receive(:send_message).with(*args).once
|
|
45
|
+
subject.send_message *args
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
describe '#new_call_uri' do
|
|
50
|
+
it 'should return the connection-specific fresh call ID' do
|
|
51
|
+
stub_uuids 'foobar'
|
|
52
|
+
expect(subject.new_call_uri).to eq('xmpp:foobar@call.rayo.net')
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it 'should handle connection events' do
|
|
57
|
+
expect(subject).to receive(:handle_event).with(mock_event).once
|
|
58
|
+
connection.event_handler.call mock_event
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
describe '#handle_event' do
|
|
62
|
+
it "sets the event's client" do
|
|
63
|
+
event = Adhearsion::Event::Offer.new
|
|
64
|
+
subject.handle_event event
|
|
65
|
+
expect(event.client).to be subject
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
context 'if the event can be associated with a source component' do
|
|
69
|
+
before do
|
|
70
|
+
allow(mock_event).to receive_messages :source => mock_component
|
|
71
|
+
expect(mock_component).to receive(:add_event).with mock_event
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it 'should not call event handlers' do
|
|
75
|
+
handler = double 'handler'
|
|
76
|
+
expect(handler).to receive(:call).never
|
|
77
|
+
subject.register_event_handler do |event|
|
|
78
|
+
handler.call event
|
|
79
|
+
end
|
|
80
|
+
subject.handle_event mock_event
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
context 'if the event cannot be associated with a source component' do
|
|
85
|
+
before do
|
|
86
|
+
allow(mock_event).to receive_messages :source => nil
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
it 'should call registered event handlers' do
|
|
90
|
+
handler = double 'handler'
|
|
91
|
+
expect(handler).to receive(:call).once.with mock_event
|
|
92
|
+
subject.register_event_handler do |event|
|
|
93
|
+
handler.call event
|
|
94
|
+
end
|
|
95
|
+
subject.handle_event mock_event
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it 'should be able to register and retrieve components' do
|
|
101
|
+
subject.register_component mock_component
|
|
102
|
+
expect(subject.find_component_by_uri(component_uri)).to be mock_component
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
describe '#execute_command' do
|
|
106
|
+
let(:component) { Adhearsion::Rayo::Component::Output.new }
|
|
107
|
+
let(:event) { Adhearsion::Event::Complete.new }
|
|
108
|
+
|
|
109
|
+
before do
|
|
110
|
+
expect(connection).to receive(:write).once.with component, :call_id => call_id
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
let :execute_command do
|
|
114
|
+
subject.execute_command component, :call_id => call_id
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
it 'should write the command to the connection' do
|
|
118
|
+
execute_command
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
it "should set the command's client" do
|
|
122
|
+
execute_command
|
|
123
|
+
expect(component.client).to be subject
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
it "should handle a component's events" do
|
|
127
|
+
expect(subject).to receive(:trigger_handler).with(:event, event).once
|
|
128
|
+
execute_command
|
|
129
|
+
component.request!
|
|
130
|
+
component.execute!
|
|
131
|
+
component.add_event event
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Adhearsion::Rayo::Command::Accept do
|
|
6
|
+
it 'registers itself' do
|
|
7
|
+
expect(Adhearsion::Rayo::RayoNode.class_from_registration(:accept, 'urn:xmpp:rayo:1')).to eq(described_class)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
describe "from a stanza" do
|
|
11
|
+
let(:stanza) do
|
|
12
|
+
<<-STANZA
|
|
13
|
+
<accept xmlns="urn:xmpp:rayo:1">
|
|
14
|
+
<header name="X-skill" value="agent" />
|
|
15
|
+
<header name="X-customer-id" value="8877" />
|
|
16
|
+
</accept>
|
|
17
|
+
STANZA
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
subject { Adhearsion::Rayo::RayoNode.from_xml parse_stanza(stanza).root, '9f00061', '1' }
|
|
21
|
+
|
|
22
|
+
it { is_expected.to be_instance_of described_class }
|
|
23
|
+
|
|
24
|
+
describe '#headers' do
|
|
25
|
+
subject { super().headers }
|
|
26
|
+
it { is_expected.to eq({ 'X-skill' => 'agent', 'X-customer-id' => '8877' }) }
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
context "with no headers provided" do
|
|
30
|
+
let(:stanza) { '<accept xmlns="urn:xmpp:rayo:1"/>' }
|
|
31
|
+
|
|
32
|
+
describe '#headers' do
|
|
33
|
+
subject { super().headers }
|
|
34
|
+
it { is_expected.to eq({}) }
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
describe "when setting options in initializer" do
|
|
40
|
+
subject { described_class.new headers: { 'X-skill' => 'agent', 'X-customer-id' => '8877' } }
|
|
41
|
+
|
|
42
|
+
describe '#headers' do
|
|
43
|
+
subject { super().headers }
|
|
44
|
+
it { is_expected.to eq({ 'X-skill' => 'agent', 'X-customer-id' => '8877' }) }
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
describe "exporting to Rayo" do
|
|
48
|
+
it "should export to XML that can be understood by its parser" do
|
|
49
|
+
new_instance = Adhearsion::Rayo::RayoNode.from_xml subject.to_rayo
|
|
50
|
+
expect(new_instance).to be_instance_of described_class
|
|
51
|
+
expect(new_instance.headers).to eq({ 'X-skill' => 'agent', 'X-customer-id' => '8877' })
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it "should render to a parent node if supplied" do
|
|
55
|
+
doc = Nokogiri::XML::Document.new
|
|
56
|
+
parent = Nokogiri::XML::Node.new 'foo', doc
|
|
57
|
+
doc.root = parent
|
|
58
|
+
rayo_doc = subject.to_rayo(parent)
|
|
59
|
+
expect(rayo_doc).to eq(parent)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|