librevox 0.2.1 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +12 -11
- data/TODO +5 -5
- data/lib/librevox.rb +16 -5
- data/lib/librevox/applications.rb +58 -51
- data/lib/librevox/command_socket.rb +5 -4
- data/lib/librevox/commands.rb +37 -13
- data/lib/librevox/listener/base.rb +28 -24
- data/lib/librevox/listener/inbound.rb +1 -1
- data/lib/librevox/listener/outbound.rb +13 -21
- data/lib/librevox/response.rb +4 -4
- data/librevox.gemspec +8 -5
- data/spec/helper.rb +82 -2
- data/spec/librevox/listener.rb +49 -64
- data/spec/librevox/listener/spec_inbound.rb +2 -2
- data/spec/librevox/listener/spec_outbound.rb +142 -97
- data/spec/librevox/spec_applications.rb +15 -10
- data/spec/librevox/spec_commands.rb +41 -6
- data/spec/librevox/spec_response.rb +1 -1
- metadata +63 -8
- data/spec/librevox/spec_command_socket.rb +0 -111
@@ -1,11 +1,11 @@
|
|
1
|
-
require 'spec/helper'
|
2
|
-
require 'spec/librevox/listener'
|
1
|
+
require './spec/helper'
|
2
|
+
require './spec/librevox/listener'
|
3
3
|
|
4
4
|
require 'librevox/listener/outbound'
|
5
5
|
|
6
6
|
module Librevox::Applications
|
7
|
-
def sample_app
|
8
|
-
|
7
|
+
def sample_app name, *args
|
8
|
+
application name, args.join(" ")
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
@@ -15,22 +15,28 @@ class OutboundTestListener < Librevox::Listener::Outbound
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
19
|
-
|
20
|
-
|
18
|
+
def event_and_linger_replies
|
19
|
+
command_reply "Reply-Text" => "+OK Events Enabled"
|
20
|
+
command_reply "Reply-Text" => "+OK will linger"
|
21
21
|
end
|
22
22
|
|
23
23
|
describe "Outbound listener" do
|
24
|
+
extend Librevox::Test::Matchers
|
25
|
+
|
24
26
|
before do
|
25
27
|
@listener = OutboundTestListener.new(nil)
|
26
|
-
|
27
|
-
|
28
|
+
command_reply(
|
29
|
+
"Caller-Caller-Id-Number" => "8675309",
|
30
|
+
"Unique-ID" => "1234",
|
31
|
+
"variable_some_var" => "some value"
|
32
|
+
)
|
33
|
+
event_and_linger_replies
|
28
34
|
end
|
29
35
|
|
30
36
|
should "connect to freeswitch and subscribe to events" do
|
31
|
-
@listener.
|
32
|
-
@listener.
|
33
|
-
@listener.
|
37
|
+
@listener.should send_command "connect"
|
38
|
+
@listener.should send_command "myevents"
|
39
|
+
@listener.should send_command "linger"
|
34
40
|
end
|
35
41
|
|
36
42
|
should "establish a session" do
|
@@ -38,111 +44,139 @@ describe "Outbound listener" do
|
|
38
44
|
end
|
39
45
|
|
40
46
|
should "call session callback after establishing new session" do
|
41
|
-
@listener.
|
47
|
+
@listener.outgoing_data.pop.should == "session was initiated"
|
42
48
|
end
|
43
49
|
|
44
|
-
should "make
|
50
|
+
should "make headers available through session" do
|
45
51
|
@listener.session[:caller_caller_id_number].should.equal "8675309"
|
46
52
|
end
|
47
53
|
|
54
|
+
should "make channel variables available through #variable" do
|
55
|
+
@listener.variable(:some_var).should == "some value"
|
56
|
+
end
|
57
|
+
|
48
58
|
behaves_like "events"
|
49
59
|
behaves_like "api commands"
|
50
|
-
|
51
|
-
should "register app" do
|
52
|
-
@listener.respond_to?(:sample_app).should.be.true?
|
53
|
-
end
|
54
60
|
end
|
55
61
|
|
56
62
|
class OutboundListenerWithNestedApps < Librevox::Listener::Outbound
|
57
63
|
def session_initiated
|
58
|
-
sample_app "foo"
|
59
|
-
|
60
|
-
end
|
64
|
+
sample_app "foo"
|
65
|
+
sample_app "bar"
|
61
66
|
end
|
62
67
|
end
|
63
68
|
|
64
69
|
describe "Outbound listener with apps" do
|
70
|
+
extend Librevox::Test::Matchers
|
71
|
+
|
65
72
|
before do
|
66
73
|
@listener = OutboundListenerWithNestedApps.new(nil)
|
67
74
|
|
68
|
-
|
69
|
-
|
70
|
-
|
75
|
+
command_reply "Establish-Session" => "OK",
|
76
|
+
"Unique-ID" => "1234"
|
77
|
+
event_and_linger_replies
|
71
78
|
3.times {@listener.outgoing_data.shift}
|
72
79
|
end
|
73
80
|
|
74
81
|
should "only send one app at a time" do
|
75
|
-
@listener.
|
76
|
-
@listener.
|
82
|
+
@listener.should send_application "foo"
|
83
|
+
@listener.should send_nothing
|
84
|
+
|
85
|
+
command_reply "Reply-Text" => "+OK"
|
86
|
+
@listener.should update_session
|
87
|
+
channel_data
|
77
88
|
|
78
|
-
@listener.
|
79
|
-
@listener.
|
80
|
-
@listener.read_data.should == nil
|
89
|
+
@listener.should send_application "bar"
|
90
|
+
@listener.should send_nothing
|
81
91
|
end
|
82
92
|
|
83
93
|
should "not be driven forward by events" do
|
84
|
-
@listener.
|
85
|
-
|
86
|
-
|
94
|
+
@listener.should send_application "foo"
|
95
|
+
|
96
|
+
command_reply :body => {
|
97
|
+
"Event-Name" => "CHANNEL_EXECUTE",
|
98
|
+
"Session-Var" => "Some"
|
99
|
+
}
|
100
|
+
|
101
|
+
@listener.should send_nothing
|
87
102
|
end
|
88
103
|
|
89
104
|
should "not be driven forward by api responses" do
|
90
|
-
@listener.
|
91
|
-
|
92
|
-
|
105
|
+
@listener.should send_application "foo"
|
106
|
+
|
107
|
+
api_response :body => "Foo"
|
108
|
+
|
109
|
+
@listener.should send_nothing
|
93
110
|
end
|
94
111
|
|
95
112
|
should "not be driven forward by disconnect notifications" do
|
96
|
-
@listener.
|
97
|
-
|
98
|
-
|
113
|
+
@listener.should send_application "foo"
|
114
|
+
|
115
|
+
response "Content-Type" => "text/disconnect-notice",
|
116
|
+
:body => "Lingering"
|
117
|
+
|
118
|
+
@listener.should send_nothing
|
99
119
|
end
|
100
120
|
end
|
101
121
|
|
102
122
|
module Librevox::Applications
|
103
|
-
def reader_app
|
104
|
-
|
123
|
+
def reader_app
|
124
|
+
application 'reader_app', "", {:variable => 'app_var'}
|
105
125
|
end
|
106
126
|
end
|
107
127
|
|
108
128
|
class OutboundListenerWithReader < Librevox::Listener::Outbound
|
109
129
|
def session_initiated
|
110
|
-
|
111
|
-
|
112
|
-
end
|
130
|
+
data = reader_app
|
131
|
+
application "send", data
|
113
132
|
end
|
114
133
|
end
|
115
134
|
|
116
135
|
describe "Outbound listener with app reading data" do
|
136
|
+
extend Librevox::Test::Matchers
|
137
|
+
|
117
138
|
before do
|
118
139
|
@listener = OutboundListenerWithReader.new(nil)
|
119
140
|
|
120
|
-
|
121
|
-
|
122
|
-
|
141
|
+
command_reply "Session-Var" => "First",
|
142
|
+
"Unique-ID" => "1234"
|
143
|
+
event_and_linger_replies
|
123
144
|
3.times {@listener.outgoing_data.shift}
|
145
|
+
|
146
|
+
@listener.should send_application "reader_app"
|
124
147
|
end
|
125
148
|
|
126
149
|
should "not send anything while missing response" do
|
127
|
-
@listener.
|
128
|
-
@listener.read_data.should == nil
|
150
|
+
@listener.should send_nothing
|
129
151
|
end
|
130
152
|
|
131
153
|
should "send uuid_dump to get channel var, after getting response" do
|
132
|
-
|
133
|
-
@listener.
|
154
|
+
command_reply "Reply-Text" => "+OK"
|
155
|
+
@listener.should update_session 1234
|
134
156
|
end
|
135
157
|
|
136
158
|
should "update session with new data" do
|
137
|
-
|
138
|
-
|
159
|
+
command_reply :body => "+OK"
|
160
|
+
|
161
|
+
@listener.should update_session 1234
|
162
|
+
api_response :body => {
|
163
|
+
"Event-Name" => "CHANNEL_DATA",
|
164
|
+
"Session-Var" => "Second"
|
165
|
+
}
|
166
|
+
|
139
167
|
@listener.session[:session_var].should == "Second"
|
140
168
|
end
|
141
169
|
|
142
|
-
should "
|
143
|
-
|
144
|
-
|
145
|
-
@listener.
|
170
|
+
should "return value of channel variable" do
|
171
|
+
command_reply :body => "+OK"
|
172
|
+
|
173
|
+
@listener.should update_session 1234
|
174
|
+
api_response :body => {
|
175
|
+
"Event-Name" => "CHANNEL_DATA",
|
176
|
+
"variable_app_var" => "Second"
|
177
|
+
}
|
178
|
+
|
179
|
+
@listener.should send_application "send", "Second"
|
146
180
|
end
|
147
181
|
end
|
148
182
|
|
@@ -150,99 +184,110 @@ class OutboundListenerWithNonNestedApps < Librevox::Listener::Outbound
|
|
150
184
|
attr_reader :queue
|
151
185
|
def session_initiated
|
152
186
|
sample_app "foo"
|
153
|
-
|
154
|
-
|
155
|
-
end
|
187
|
+
data = reader_app
|
188
|
+
application "send", "the end: #{data}"
|
156
189
|
end
|
157
190
|
end
|
158
191
|
|
159
192
|
describe "Outbound listener with non-nested apps" do
|
193
|
+
extend Librevox::Test::Matchers
|
194
|
+
|
160
195
|
before do
|
161
196
|
@listener = OutboundListenerWithNonNestedApps.new(nil)
|
162
197
|
|
163
|
-
|
164
|
-
|
165
|
-
|
198
|
+
command_reply "Session-Var" => "First",
|
199
|
+
"Unique-ID" => "1234"
|
200
|
+
event_and_linger_replies
|
166
201
|
3.times {@listener.outgoing_data.shift}
|
167
202
|
end
|
168
203
|
|
169
|
-
should "wait for response before calling next
|
170
|
-
|
171
|
-
|
172
|
-
@listener.
|
204
|
+
should "wait for response before calling next app" do
|
205
|
+
@listener.should send_application "foo"
|
206
|
+
command_reply :body => "+OK"
|
207
|
+
@listener.should update_session
|
208
|
+
channel_data "Unique-ID" => "1234"
|
173
209
|
|
174
|
-
|
175
|
-
|
176
|
-
@listener.receive_data("Content-Type: command/reply\nContent-Length: 3\n\n+OK\n\n")
|
210
|
+
@listener.should send_application "reader_app"
|
211
|
+
command_reply :body => "+OK"
|
177
212
|
|
178
|
-
|
179
|
-
|
180
|
-
|
213
|
+
@listener.should update_session
|
214
|
+
api_response :body => {
|
215
|
+
"Event-Name" => "CHANNEL_DATA",
|
216
|
+
"variable_app_var" => "Second"
|
217
|
+
}
|
181
218
|
|
182
|
-
@listener.
|
219
|
+
@listener.should send_application "send", "the end: Second"
|
183
220
|
end
|
184
221
|
end
|
185
222
|
|
186
223
|
module Librevox::Commands
|
187
|
-
def sample_cmd
|
188
|
-
|
224
|
+
def sample_cmd cmd, *args
|
225
|
+
command cmd, *args
|
189
226
|
end
|
190
227
|
end
|
191
228
|
|
192
229
|
class OutboundListenerWithAppsAndApi < Librevox::Listener::Outbound
|
193
230
|
def session_initiated
|
194
|
-
sample_app "foo"
|
195
|
-
|
196
|
-
|
197
|
-
end
|
198
|
-
end
|
231
|
+
sample_app "foo"
|
232
|
+
api.sample_cmd "bar"
|
233
|
+
sample_app "baz"
|
199
234
|
end
|
200
235
|
end
|
201
236
|
|
202
237
|
describe "Outbound listener with both apps and api calls" do
|
238
|
+
extend Librevox::Test::Matchers
|
239
|
+
|
203
240
|
before do
|
204
241
|
@listener = OutboundListenerWithAppsAndApi.new(nil)
|
205
242
|
|
206
|
-
|
207
|
-
|
208
|
-
|
243
|
+
command_reply "Session-Var" => "First",
|
244
|
+
"Unique-ID" => "1234"
|
245
|
+
event_and_linger_replies
|
209
246
|
3.times {@listener.outgoing_data.shift}
|
210
247
|
end
|
211
248
|
|
212
|
-
should "wait for response before calling next
|
213
|
-
@listener.
|
214
|
-
|
249
|
+
should "wait for response before calling next app/cmd" do
|
250
|
+
@listener.should send_application "foo"
|
251
|
+
command_reply :body => "+OK"
|
252
|
+
@listener.should update_session
|
253
|
+
channel_data
|
215
254
|
|
216
|
-
@listener.
|
217
|
-
|
255
|
+
@listener.should send_command "api bar"
|
256
|
+
api_response :body => "+OK"
|
218
257
|
|
219
|
-
@listener.
|
258
|
+
@listener.should send_application "baz"
|
220
259
|
end
|
221
260
|
end
|
222
261
|
|
223
262
|
class OutboundListenerWithUpdateSessionCallback < Librevox::Listener::Outbound
|
224
263
|
def session_initiated
|
225
|
-
update_session
|
226
|
-
|
227
|
-
end
|
264
|
+
update_session
|
265
|
+
application "send", "yay, #{session[:session_var]}"
|
228
266
|
end
|
229
267
|
end
|
230
268
|
|
231
269
|
describe "Outbound listener with update session callback" do
|
270
|
+
extend Librevox::Test::Matchers
|
271
|
+
|
232
272
|
before do
|
233
273
|
@listener = OutboundListenerWithUpdateSessionCallback.new(nil)
|
234
|
-
|
235
|
-
|
274
|
+
command_reply "Session-Var" => "First",
|
275
|
+
"Unique-ID" => "1234"
|
276
|
+
event_and_linger_replies
|
236
277
|
3.times {@listener.outgoing_data.shift}
|
237
278
|
|
238
|
-
@listener.
|
279
|
+
@listener.should update_session
|
280
|
+
api_response :body => {
|
281
|
+
"Event-Name" => "CHANNEL_DATA",
|
282
|
+
"Session-Var" => "Second"
|
283
|
+
}
|
239
284
|
end
|
240
285
|
|
241
286
|
should "execute callback" do
|
242
|
-
@listener.
|
287
|
+
@listener.outgoing_data.shift.should =~ /yay,/
|
243
288
|
end
|
244
289
|
|
245
290
|
should "update session before calling callback" do
|
246
|
-
@listener.
|
291
|
+
@listener.should send_application "send", "yay, Second"
|
247
292
|
end
|
248
293
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'spec/helper'
|
1
|
+
require './spec/helper'
|
2
2
|
require 'librevox/applications'
|
3
3
|
|
4
4
|
module AppTest
|
@@ -6,12 +6,11 @@ module AppTest
|
|
6
6
|
|
7
7
|
extend self
|
8
8
|
|
9
|
-
def
|
9
|
+
def application name, args="", params={}
|
10
10
|
{
|
11
11
|
:name => name,
|
12
12
|
:args => args,
|
13
|
-
:params => params
|
14
|
-
:block => block
|
13
|
+
:params => params
|
15
14
|
}
|
16
15
|
end
|
17
16
|
end
|
@@ -129,7 +128,7 @@ describe Librevox::Applications do
|
|
129
128
|
app = AppTest.play_and_get_digits "please-enter", "wrong-try-again"
|
130
129
|
app[:name].should == "play_and_get_digits"
|
131
130
|
app[:args].should == "1 2 3 5000 # please-enter wrong-try-again read_digits_var \\d+"
|
132
|
-
app[:params][:
|
131
|
+
app[:params][:variable].should == "read_digits_var"
|
133
132
|
end
|
134
133
|
|
135
134
|
should "take params" do
|
@@ -139,11 +138,11 @@ describe Librevox::Applications do
|
|
139
138
|
:tries => 4,
|
140
139
|
:terminators => "0",
|
141
140
|
:timeout => 10000,
|
142
|
-
:
|
141
|
+
:variable => "other_var",
|
143
142
|
:regexp => "[125]"
|
144
143
|
|
145
144
|
app[:args].should == "2 3 4 10000 0 please-enter invalid-choice other_var [125]"
|
146
|
-
app[:params][:
|
145
|
+
app[:params][:variable].should == "other_var"
|
147
146
|
end
|
148
147
|
end
|
149
148
|
|
@@ -165,7 +164,7 @@ describe Librevox::Applications do
|
|
165
164
|
app = AppTest.read "please-enter.wav"
|
166
165
|
app[:name].should == "read"
|
167
166
|
app[:args].should == "1 2 please-enter.wav read_digits_var 5000 #"
|
168
|
-
app[:params][:
|
167
|
+
app[:params][:variable].should == "read_digits_var"
|
169
168
|
end
|
170
169
|
|
171
170
|
should "take params" do
|
@@ -174,10 +173,10 @@ describe Librevox::Applications do
|
|
174
173
|
:max => 3,
|
175
174
|
:terminators => "0",
|
176
175
|
:timeout => 10000,
|
177
|
-
:
|
176
|
+
:variable => "other_var"
|
178
177
|
|
179
178
|
app[:args].should == "2 3 please-enter.wav other_var 10000 0"
|
180
|
-
app[:params][:
|
179
|
+
app[:params][:variable].should == "other_var"
|
181
180
|
end
|
182
181
|
end
|
183
182
|
|
@@ -203,6 +202,12 @@ describe Librevox::Applications do
|
|
203
202
|
end
|
204
203
|
end
|
205
204
|
|
205
|
+
should "respond with code" do
|
206
|
+
app = AppTest.respond 403
|
207
|
+
app[:name].should == "respond"
|
208
|
+
app[:args].should == "403"
|
209
|
+
end
|
210
|
+
|
206
211
|
should "set" do
|
207
212
|
app = AppTest.set("foo", "bar")
|
208
213
|
app[:name].should == "set"
|