matrioska 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/.travis.yml +13 -0
- data/CHANGELOG.md +4 -0
- data/README.md +28 -4
- data/Rakefile +8 -1
- data/lib/matrioska/app_runner.rb +26 -4
- data/lib/matrioska/dial_with_apps.rb +33 -0
- data/lib/matrioska/version.rb +1 -1
- data/spec/matrioska/app_runner_spec.rb +18 -0
- data/spec/matrioska/dial_with_apps_spec.rb +51 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc5710bb33c4c4ec260526fb66e7053f669fbb5c
|
4
|
+
data.tar.gz: d50e98d2d805e576d48c1db9afd43fbbfb93c117
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce872c227620f228c643d520a2e6b342561fe5b5b8bc9f2b2079102f0dcd947a13d278470c7076f72062cfa8eba3eb07184262b78a71929adc54083a8213169f
|
7
|
+
data.tar.gz: 4e5231d6481d3a1d804745463dc1ee8ef5c7dec190b296eb2fa91c1aa51066f52bd6a0286460df038431da77a37ca964b2dac01dd88939e367c909379294c21d
|
data/.travis.yml
ADDED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
[](http://travis-ci.org/adhearsion/matrioska)
|
2
|
+
|
1
3
|
# Matrioska
|
2
4
|
|
3
5
|
Matrioska is an Adhearsion plugin for running in-call apps at the press of a DTMF.
|
@@ -8,7 +10,7 @@ By mapping controllers or blocks to the desired applications, a listener object
|
|
8
10
|
|
9
11
|
```ruby
|
10
12
|
# inside your controller
|
11
|
-
runner = Matrioska::AppRunner.new
|
13
|
+
runner = Matrioska::AppRunner.new call
|
12
14
|
runner.map_app 3 do
|
13
15
|
logger.info "hi there!"
|
14
16
|
end
|
@@ -17,9 +19,23 @@ runner.map_app 5, AppController
|
|
17
19
|
runner.start
|
18
20
|
```
|
19
21
|
|
20
|
-
###
|
22
|
+
### Using local and remote apps with at the same time with a parallel dial
|
23
|
+
```ruby
|
24
|
+
# inside your controller
|
25
|
+
dial_with_apps ['user/userb'] do |dial|
|
26
|
+
local do |runner|
|
27
|
+
runner.map_app '1' do
|
28
|
+
say 'Gosh you sound stunning today leg a'
|
29
|
+
end
|
30
|
+
end
|
21
31
|
|
22
|
-
|
32
|
+
remote do |runner|
|
33
|
+
runner.map_app '2' do
|
34
|
+
say 'Gosh you sound stunning today leg b'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
```
|
23
39
|
|
24
40
|
### Links
|
25
41
|
|
@@ -32,10 +48,18 @@ Original author: [Luca Pradovera](https://github.com/polysics)
|
|
32
48
|
* Fork the project.
|
33
49
|
* Make your feature addition or bug fix.
|
34
50
|
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
35
|
-
* Commit, do not mess with
|
51
|
+
* Commit, do not mess with Rakefile, version, or history.
|
36
52
|
* If you want to have your own version, that is fine but bump version in a commit by itself so I can ignore when I pull
|
37
53
|
* Send me a pull request. Bonus points for topic branches.
|
38
54
|
|
55
|
+
### Credits
|
56
|
+
|
57
|
+
Original author: [Luca Pradovera](https://github.com/polysics)
|
58
|
+
|
59
|
+
Developed by [Mojo Lingo](http://mojolingo.com) in partnership with [RingPlus](http://ringplus.net).
|
60
|
+
|
61
|
+
Thanks to [RingPlus](http://ringplus.net) for ongoing sponsorship of Matrioska.
|
62
|
+
|
39
63
|
### Copyright
|
40
64
|
|
41
65
|
Copyright (c) 2013 Adhearsion Foundation Inc. MIT license (see LICENSE for details).
|
data/Rakefile
CHANGED
data/lib/matrioska/app_runner.rb
CHANGED
@@ -9,17 +9,35 @@ module Matrioska
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def start
|
12
|
+
@state = :started
|
12
13
|
logger.debug "MATRIOSKA START CALLED"
|
13
14
|
unless @running
|
14
|
-
component = Punchblock::Component::Input.new mode: :dtmf, grammar: { value: grammar_accept }
|
15
|
+
@component = Punchblock::Component::Input.new mode: :dtmf, grammar: { value: grammar_accept }
|
15
16
|
logger.debug "MATRIOSKA STARTING LISTENER"
|
16
|
-
component.register_event_handler Punchblock::Event::Complete do |event|
|
17
|
+
@component.register_event_handler Punchblock::Event::Complete do |event|
|
17
18
|
handle_input_complete event
|
18
19
|
end
|
19
|
-
@call.write_and_await_response component if @call.active?
|
20
|
+
@call.write_and_await_response @component if @call.active?
|
20
21
|
end
|
21
22
|
end
|
22
23
|
|
24
|
+
def stop!
|
25
|
+
@state = :stopped
|
26
|
+
@component.stop! if @component && @component.executing?
|
27
|
+
end
|
28
|
+
|
29
|
+
def status
|
30
|
+
@state
|
31
|
+
end
|
32
|
+
|
33
|
+
def started?
|
34
|
+
@state == :started
|
35
|
+
end
|
36
|
+
|
37
|
+
def stopped?
|
38
|
+
@state == :stopped
|
39
|
+
end
|
40
|
+
|
23
41
|
def map_app(digit, controller = nil, &block)
|
24
42
|
digit = digit.to_s
|
25
43
|
range = "1234567890*#"
|
@@ -40,6 +58,10 @@ module Matrioska
|
|
40
58
|
end
|
41
59
|
|
42
60
|
def handle_input_complete(event)
|
61
|
+
if @state == :stopped
|
62
|
+
logger.warn "Stopped runner #{self} received event."
|
63
|
+
return
|
64
|
+
end
|
43
65
|
logger.debug "MATRIOSKA HANDLING INPUT"
|
44
66
|
result = event.reason.respond_to?(:utterance) ? event.reason.utterance : nil
|
45
67
|
digit = parse_dtmf result
|
@@ -60,7 +82,7 @@ module Matrioska
|
|
60
82
|
@running = false
|
61
83
|
logger.debug "MATRIOSKA CALLBACK RESTARTING LISTENER"
|
62
84
|
if call.active?
|
63
|
-
start
|
85
|
+
start unless stopped?
|
64
86
|
else
|
65
87
|
logger.debug "MATRIOSKA CALLBACK NOT DOING ANYTHING BECAUSE CALL IS DEAD"
|
66
88
|
end
|
@@ -33,5 +33,38 @@ module Matrioska
|
|
33
33
|
dial.cleanup_calls
|
34
34
|
dial.status
|
35
35
|
end
|
36
|
+
|
37
|
+
def dial_with_apps(to, options = {}, &block)
|
38
|
+
dial = Adhearsion::CallController::Dial::ParallelConfirmationDial.new to, options, call
|
39
|
+
yield dial
|
40
|
+
|
41
|
+
local_runner = Matrioska::AppRunner.new call
|
42
|
+
@local_runner_block.call local_runner
|
43
|
+
local_runner.start
|
44
|
+
|
45
|
+
dial.prep_calls do |new_call|
|
46
|
+
new_call.on_joined call do
|
47
|
+
remote_runner = Matrioska::AppRunner.new new_call
|
48
|
+
@remote_runner_block.call remote_runner
|
49
|
+
remote_runner.start
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
dial.track_originating_call
|
54
|
+
dial.place_calls
|
55
|
+
dial.await_completion
|
56
|
+
dial.cleanup_calls
|
57
|
+
dial.status
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def local(&block)
|
63
|
+
@local_runner_block = block
|
64
|
+
end
|
65
|
+
|
66
|
+
def remote(&block)
|
67
|
+
@remote_runner_block = block
|
68
|
+
end
|
36
69
|
end
|
37
70
|
end
|
data/lib/matrioska/version.rb
CHANGED
@@ -37,6 +37,24 @@ module Matrioska
|
|
37
37
|
it "should start the appropriate component" do
|
38
38
|
call.should_receive(:write_and_await_response).with(input_component)
|
39
39
|
subject.start
|
40
|
+
subject.status.should == :started
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#stop!" do
|
45
|
+
let(:mock_component) { double Punchblock::Component::Input, register_event_handler: true }
|
46
|
+
|
47
|
+
before do
|
48
|
+
Punchblock::Component::Input.stub(:new).and_return mock_component
|
49
|
+
call.stub(:write_and_await_response)
|
50
|
+
subject.start
|
51
|
+
end
|
52
|
+
|
53
|
+
it "stops the runner" do
|
54
|
+
mock_component.should_receive(:executing?).and_return true
|
55
|
+
mock_component.should_receive :stop!
|
56
|
+
subject.stop!
|
57
|
+
subject.status.should == :stopped
|
40
58
|
end
|
41
59
|
end
|
42
60
|
|
@@ -95,4 +95,55 @@ describe Matrioska::DialWithApps do
|
|
95
95
|
dial_thread.join.should be_true
|
96
96
|
end
|
97
97
|
end
|
98
|
+
|
99
|
+
describe "#dial_with_apps" do
|
100
|
+
let(:mock_local_runner) { Matrioska::AppRunner.new call }
|
101
|
+
let(:mock_remote_runner) { Matrioska::AppRunner.new second_other_mock_call }
|
102
|
+
|
103
|
+
before do
|
104
|
+
Matrioska::AppRunner.stub(:new).with(call).and_return mock_local_runner
|
105
|
+
Matrioska::AppRunner.stub(:new).with(second_other_mock_call).and_return mock_remote_runner
|
106
|
+
|
107
|
+
Adhearsion::OutboundCall.should_receive(:new).and_return other_mock_call, second_other_mock_call
|
108
|
+
end
|
109
|
+
|
110
|
+
it "starts an app listener on both ends of the call" do
|
111
|
+
call.should_receive(:answer).once
|
112
|
+
|
113
|
+
mock_local_runner.should_receive(:foo).once
|
114
|
+
mock_local_runner.should_receive(:start).once
|
115
|
+
|
116
|
+
mock_remote_runner.should_receive(:bar).once
|
117
|
+
mock_remote_runner.should_receive(:start).once
|
118
|
+
|
119
|
+
other_mock_call.should_receive(:dial).with(to, from: 'foo').once
|
120
|
+
other_mock_call.should_receive(:hangup).once.and_return do
|
121
|
+
other_mock_call << mock_end
|
122
|
+
end
|
123
|
+
|
124
|
+
second_other_mock_call.should_receive(:dial).with(second_to, from: 'foo').once
|
125
|
+
second_other_mock_call.should_receive(:join).once.and_return do
|
126
|
+
second_other_mock_call << Punchblock::Event::Joined.new(call_uri: call_id)
|
127
|
+
end
|
128
|
+
|
129
|
+
dial_thread = Thread.new do
|
130
|
+
controller.instance_exec(to,second_to) do |to, second_to|
|
131
|
+
dial_with_apps([to, second_to], from: 'foo') do |dial|
|
132
|
+
local do |runner|
|
133
|
+
runner.foo
|
134
|
+
end
|
135
|
+
|
136
|
+
remote do |runner|
|
137
|
+
runner.bar
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
sleep 0.1
|
144
|
+
second_other_mock_call << mock_answered
|
145
|
+
second_other_mock_call << mock_end
|
146
|
+
dial_thread.join.should be_true
|
147
|
+
end
|
148
|
+
end
|
98
149
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: matrioska
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Pradovera
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: adhearsion
|
@@ -90,6 +90,7 @@ extra_rdoc_files: []
|
|
90
90
|
files:
|
91
91
|
- .gitignore
|
92
92
|
- .rspec
|
93
|
+
- .travis.yml
|
93
94
|
- CHANGELOG.md
|
94
95
|
- Gemfile
|
95
96
|
- Guardfile
|