punchblock 0.4.3 → 0.5.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.md +3 -0
- data/bin/punchblock-console +11 -10
- data/lib/punchblock.rb +2 -1
- data/lib/punchblock/client.rb +64 -0
- data/lib/punchblock/client/component_registry.rb +22 -0
- data/lib/punchblock/command/dial.rb +1 -4
- data/lib/punchblock/component.rb +6 -8
- data/lib/punchblock/connection.rb +4 -206
- data/lib/punchblock/connection/connected.rb +15 -0
- data/lib/punchblock/connection/xmpp.rb +161 -0
- data/lib/punchblock/dsl.rb +4 -4
- data/lib/punchblock/rayo_node.rb +2 -2
- data/lib/punchblock/version.rb +1 -1
- data/punchblock.gemspec +1 -1
- data/spec/punchblock/client/component_registry_spec.rb +15 -0
- data/spec/punchblock/client_spec.rb +125 -0
- data/spec/punchblock/command/dial_spec.rb +1 -8
- data/spec/punchblock/component/input_spec.rb +3 -2
- data/spec/punchblock/component/output_spec.rb +10 -9
- data/spec/punchblock/component/record_spec.rb +5 -4
- data/spec/punchblock/component/tropo/ask_spec.rb +3 -2
- data/spec/punchblock/component/tropo/conference_spec.rb +6 -5
- data/spec/punchblock/component/tropo/say_spec.rb +5 -4
- data/spec/punchblock/component/tropo/transfer_spec.rb +3 -2
- data/spec/punchblock/component_spec.rb +3 -9
- data/spec/punchblock/connection/xmpp_spec.rb +201 -0
- metadata +45 -38
- data/lib/punchblock/generic_connection.rb +0 -18
- data/spec/punchblock/connection_spec.rb +0 -216
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
module Punchblock
|
|
2
|
-
class GenericConnection
|
|
3
|
-
attr_accessor :event_queue
|
|
4
|
-
|
|
5
|
-
##
|
|
6
|
-
# @param [Hash] options
|
|
7
|
-
# @option options [Logger] :transport_logger The logger to which transport events will be logged
|
|
8
|
-
#
|
|
9
|
-
def initialize(options = {})
|
|
10
|
-
@event_queue = Queue.new
|
|
11
|
-
@logger = options.delete(:transport_logger) if options[:transport_logger]
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def connected
|
|
15
|
-
'CONNECTED'
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
module Punchblock
|
|
4
|
-
describe Connection do
|
|
5
|
-
let(:connection) { Connection.new :username => '1@call.rayo.net', :password => 1 }
|
|
6
|
-
|
|
7
|
-
subject { connection }
|
|
8
|
-
|
|
9
|
-
it 'should require a username and password to be passed in the options' do
|
|
10
|
-
expect { Connection.new :password => 1 }.to raise_error ArgumentError
|
|
11
|
-
expect { Connection.new :username => 1 }.to raise_error ArgumentError
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it 'should properly set the Blather logger' do
|
|
15
|
-
Connection.new :wire_logger => :foo, :username => 1, :password => 1
|
|
16
|
-
Blather.logger.should be :foo
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
its(:event_queue) { should be_a Queue }
|
|
20
|
-
|
|
21
|
-
it "looking up original command by command ID" do
|
|
22
|
-
offer = Event::Offer.new
|
|
23
|
-
offer.call_id = '9f00061'
|
|
24
|
-
offer.to = 'sip:whatever@127.0.0.1'
|
|
25
|
-
say = <<-MSG
|
|
26
|
-
<say xmlns='urn:xmpp:tropo:say:1' voice='allison'>
|
|
27
|
-
<audio url='http://acme.com/greeting.mp3'>
|
|
28
|
-
Thanks for calling ACME company
|
|
29
|
-
</audio>
|
|
30
|
-
<audio url='http://acme.com/package-shipped.mp3'>
|
|
31
|
-
Your package was shipped on
|
|
32
|
-
</audio>
|
|
33
|
-
<say-as interpret-as='date'>12/01/2011</say-as>
|
|
34
|
-
</say>
|
|
35
|
-
MSG
|
|
36
|
-
Component::Tropo::Say
|
|
37
|
-
say = RayoNode.import parse_stanza(say).root
|
|
38
|
-
connection.event_queue = []
|
|
39
|
-
connection.expects(:write_to_stream).once.returns true
|
|
40
|
-
iq = Blather::Stanza::Iq.new :set, '9f00061@call.rayo.net'
|
|
41
|
-
connection.expects(:create_iq).returns iq
|
|
42
|
-
|
|
43
|
-
write_thread = Thread.new do
|
|
44
|
-
connection.write offer.call_id, say
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
result = import_stanza <<-MSG
|
|
48
|
-
<iq type='result' from='16577@app.rayo.net/1' to='9f00061@call.rayo.net/1' id='#{iq.id}'>
|
|
49
|
-
<ref id='fgh4590' xmlns='urn:xmpp:rayo:1' />
|
|
50
|
-
</iq>
|
|
51
|
-
MSG
|
|
52
|
-
|
|
53
|
-
sleep 0.5 # Block so there's enough time for the write thread to get to the point where it's waiting on an IQ
|
|
54
|
-
|
|
55
|
-
connection.__send__ :handle_iq_result, result
|
|
56
|
-
|
|
57
|
-
write_thread.join
|
|
58
|
-
|
|
59
|
-
say.state_name.should == :executing
|
|
60
|
-
|
|
61
|
-
connection.original_component_from_id('fgh4590').should == say
|
|
62
|
-
|
|
63
|
-
example_complete = import_stanza <<-MSG
|
|
64
|
-
<presence to='16577@app.rayo.net/1' from='9f00061@call.rayo.net/fgh4590'>
|
|
65
|
-
<complete xmlns='urn:xmpp:rayo:ext:1'>
|
|
66
|
-
<success xmlns='urn:xmpp:tropo:say:complete:1' />
|
|
67
|
-
</complete>
|
|
68
|
-
</presence>
|
|
69
|
-
MSG
|
|
70
|
-
|
|
71
|
-
connection.__send__ :handle_presence, example_complete
|
|
72
|
-
say.complete_event.resource.source.should == say
|
|
73
|
-
|
|
74
|
-
say.component_id.should == 'fgh4590'
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
describe '#handle_presence' do
|
|
78
|
-
let :offer_xml do
|
|
79
|
-
<<-MSG
|
|
80
|
-
<presence to='16577@app.rayo.net/1' from='9f00061@call.rayo.net'>
|
|
81
|
-
<offer xmlns="urn:xmpp:rayo:1" to="sip:whatever@127.0.0.1" from="sip:ylcaomxb@192.168.1.9">
|
|
82
|
-
<header name="Max-Forwards" value="70"/>
|
|
83
|
-
<header name="Content-Length" value="367"/>
|
|
84
|
-
</offer>
|
|
85
|
-
</presence>
|
|
86
|
-
MSG
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
let(:example_offer) { import_stanza offer_xml }
|
|
90
|
-
|
|
91
|
-
it { example_offer.should be_a Blather::Stanza::Presence }
|
|
92
|
-
|
|
93
|
-
let :complete_xml do
|
|
94
|
-
<<-MSG
|
|
95
|
-
<presence to='16577@app.rayo.net/1' from='9f00061@call.rayo.net/fgh4590'>
|
|
96
|
-
<complete xmlns='urn:xmpp:rayo:ext:1'>
|
|
97
|
-
<success xmlns='urn:xmpp:tropo:say:complete:1' />
|
|
98
|
-
</complete>
|
|
99
|
-
</presence>
|
|
100
|
-
MSG
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
let(:example_complete) { import_stanza complete_xml }
|
|
104
|
-
|
|
105
|
-
it { example_complete.should be_a Blather::Stanza::Presence }
|
|
106
|
-
|
|
107
|
-
describe "event placed on the event queue" do
|
|
108
|
-
before do
|
|
109
|
-
connection.event_queue = []
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
describe "from an offer" do
|
|
113
|
-
before do
|
|
114
|
-
connection.__send__ :handle_presence, example_offer
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
subject { connection.event_queue.first }
|
|
118
|
-
|
|
119
|
-
it { should be_instance_of Event::Offer }
|
|
120
|
-
its(:call_id) { should == '9f00061' }
|
|
121
|
-
|
|
122
|
-
it "should populate the call map with the domain for the call ID" do
|
|
123
|
-
callmap = connection.instance_variable_get(:'@callmap')
|
|
124
|
-
callmap['9f00061'].should == 'call.rayo.net'
|
|
125
|
-
end
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
describe "from a complete" do
|
|
129
|
-
before do
|
|
130
|
-
connection.__send__ :handle_presence, example_complete
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
subject { connection.event_queue.first }
|
|
134
|
-
|
|
135
|
-
it { should be_instance_of Event::Complete }
|
|
136
|
-
its(:call_id) { should == '9f00061' }
|
|
137
|
-
its(:connection) { should == connection }
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
describe "from something that's not a real event" do
|
|
141
|
-
let :irrelevant_xml do
|
|
142
|
-
<<-MSG
|
|
143
|
-
<presence to='16577@app.rayo.net/1' from='9f00061@call.rayo.net/fgh4590'>
|
|
144
|
-
<foo/>
|
|
145
|
-
</presence>
|
|
146
|
-
MSG
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
let(:example_irrelevant_event) { import_stanza irrelevant_xml }
|
|
150
|
-
|
|
151
|
-
before do
|
|
152
|
-
lambda { connection.__send__ :handle_presence, example_irrelevant_event }.should throw_symbol(:pass)
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
subject { connection.event_queue }
|
|
156
|
-
|
|
157
|
-
it { should be_empty }
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
describe "from someone other than the rayo domain" do
|
|
161
|
-
let :irrelevant_xml do
|
|
162
|
-
<<-MSG
|
|
163
|
-
<presence to='16577@app.rayo.net/1' from='9f00061@jabber.org/fgh4590'>
|
|
164
|
-
<complete xmlns='urn:xmpp:rayo:ext:1'>
|
|
165
|
-
<success xmlns='urn:xmpp:tropo:say:complete:1' />
|
|
166
|
-
</complete>
|
|
167
|
-
</presence>
|
|
168
|
-
MSG
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
let(:example_irrelevant_event) { import_stanza irrelevant_xml }
|
|
172
|
-
|
|
173
|
-
before do
|
|
174
|
-
lambda { connection.__send__ :handle_presence, example_irrelevant_event }.should throw_symbol(:pass)
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
subject { connection.event_queue }
|
|
178
|
-
|
|
179
|
-
it { should be_empty }
|
|
180
|
-
end
|
|
181
|
-
end
|
|
182
|
-
end
|
|
183
|
-
|
|
184
|
-
describe "#handle_error" do
|
|
185
|
-
let(:call_id) { "f6d437f4-1e18-457b-99f8-b5d853f50347" }
|
|
186
|
-
let(:component_id) { 'abc123' }
|
|
187
|
-
let :error_xml do
|
|
188
|
-
<<-MSG
|
|
189
|
-
<iq type="error" id="blather000e" from="f6d437f4-1e18-457b-99f8-b5d853f50347@10.0.1.11/abc123" to="usera@10.0.1.11/voxeo">
|
|
190
|
-
<output xmlns="urn:xmpp:rayo:output:1"/>
|
|
191
|
-
<error type="cancel">
|
|
192
|
-
<item-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
|
|
193
|
-
<text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" lang="en">Could not find call [id=f6d437f4-1e18-457b-99f8-b5d853f50347]</text>
|
|
194
|
-
</error>
|
|
195
|
-
</iq>
|
|
196
|
-
MSG
|
|
197
|
-
end
|
|
198
|
-
|
|
199
|
-
let(:example_error) { import_stanza error_xml }
|
|
200
|
-
let(:cmd) { Component::Output.new }
|
|
201
|
-
|
|
202
|
-
before(:all) do
|
|
203
|
-
cmd.request!
|
|
204
|
-
connection.instance_variable_get(:'@iq_id_to_command')['blather000e'] = cmd
|
|
205
|
-
connection.__send__ :handle_error, example_error
|
|
206
|
-
end
|
|
207
|
-
|
|
208
|
-
subject { cmd.response }
|
|
209
|
-
|
|
210
|
-
its(:call_id) { should == call_id }
|
|
211
|
-
its(:component_id) { should == component_id }
|
|
212
|
-
its(:name) { should == :item_not_found }
|
|
213
|
-
its(:text) { should == 'Could not find call [id=f6d437f4-1e18-457b-99f8-b5d853f50347]' }
|
|
214
|
-
end
|
|
215
|
-
end # describe Connection
|
|
216
|
-
end # Punchblock
|