punchblock 2.0.2 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b8dddb3e5a8b1158136add6d851f6f40fbe94438
4
- data.tar.gz: ff999c1ed2536e739167e74ab6d9ac96c188f0e9
3
+ metadata.gz: 8497250485b747e066b5df34ae25d12b6773e884
4
+ data.tar.gz: 833a6638459f513c128d0765cc9ed39668216218
5
5
  SHA512:
6
- metadata.gz: 8817401f7029230cc46119a8fabe2a525b72c0af9375eb09127dfbbf8855617ac1a553b2fca2699accec6311df9d9bb378a6dff5322a9df0b26e6a994d2f66fb
7
- data.tar.gz: 43668278a0c3943259fbbc75f4b0704e6cc617d41fb2f405b3b0fac1d6aa8093ea78bbf24a8c868b55b3ccced90da00648af8d3b5a18163cecb074dd1b845510
6
+ metadata.gz: 91fc99d918b5b81045adff0aac91b924abe2874c1777ffd40c452f8a71dd5c88392b1b46d9987dbfa5ba7238f86f3860072c811b962ebda478b810006679783c
7
+ data.tar.gz: baff387cd63774ab1aefecc86055d816de003b9e4bf216488ecaced37a296f18315bf3e9c4d8682f02475d7ea77e45d4b5fc62701ed29f4e029e94f7b38b1b10
@@ -1,5 +1,9 @@
1
1
  # [develop](https://github.com/adhearsion/punchblock)
2
2
 
3
+ # [v2.1.0](https://github.com/adhearsion/punchblock/compare/v2.0.2...v2.1.0) - [2013-11-12](https://rubygems.org/gems/punchblock/versions/2.1.0)
4
+ * Feature: Support RubySpeech builtin grammars on Asterisk and FreeSWITCH
5
+ * Update: Update to stable release of Virtus
6
+
3
7
  # [v2.0.2](https://github.com/adhearsion/punchblock/compare/v2.0.1...v2.0.2) - [2013-10-17](https://rubygems.org/gems/punchblock/versions/2.0.2)
4
8
  * Bugfix: Reject commands against components which have finished on Asterisk, and garbage collect them
5
9
  * Bugfix: Register/lookup components by their full URI rather than component ID since the component ID may only be unique per call
@@ -5,7 +5,7 @@ require 'virtus'
5
5
 
6
6
  module Punchblock
7
7
  class RayoNode
8
- include Virtus
8
+ include Virtus.model
9
9
 
10
10
  @@registrations = {}
11
11
 
@@ -79,10 +79,6 @@ module Punchblock
79
79
  o.is_a?(self.class) && self.to_hash == o.to_hash
80
80
  end
81
81
 
82
- def to_hash
83
- get_attributes(&:public_reader?)
84
- end
85
-
86
82
  ##
87
83
  # @return [RayoNode] the original command issued that lead to this event
88
84
  #
@@ -3,6 +3,26 @@
3
3
  module Punchblock
4
4
  module Translator
5
5
  class DTMFRecognizer
6
+ class BuiltinMatcherCache
7
+ include Singleton
8
+ include MonitorMixin
9
+
10
+ def get(uri)
11
+ cache[uri] ||= fetch(uri)
12
+ end
13
+
14
+ private
15
+
16
+ def fetch(uri)
17
+ grammar = RubySpeech::GRXML.from_uri(uri)
18
+ RubySpeech::GRXML::Matcher.new(grammar)
19
+ end
20
+
21
+ def cache
22
+ @cache ||= {}
23
+ end
24
+ end
25
+
6
26
  def initialize(responder, grammar, initial_timeout = nil, inter_digit_timeout = nil, terminator = nil)
7
27
  @responder = responder
8
28
  self.initial_timeout = initial_timeout || -1
@@ -10,7 +30,11 @@ module Punchblock
10
30
  @terminator = terminator
11
31
  @finished = false
12
32
 
13
- @matcher = RubySpeech::GRXML::Matcher.new RubySpeech::GRXML.import(grammar.to_s)
33
+ @matcher = if grammar.url
34
+ BuiltinMatcherCache.instance.get(grammar.url)
35
+ else
36
+ RubySpeech::GRXML::Matcher.new RubySpeech::GRXML.import(grammar.value.to_s)
37
+ end
14
38
  @buffer = ""
15
39
  end
16
40
 
@@ -8,7 +8,7 @@ module Punchblock
8
8
  setup_dtmf_recognizer
9
9
  send_ref
10
10
  start_timers
11
- rescue OptionError => e
11
+ rescue OptionError, ArgumentError => e
12
12
  with_error 'option error', e.message
13
13
  end
14
14
 
@@ -52,7 +52,7 @@ module Punchblock
52
52
 
53
53
  def setup_dtmf_recognizer
54
54
  @recognizer = DTMFRecognizer.new self,
55
- input_node.grammars.first.value,
55
+ input_node.grammars.first,
56
56
  (input_node.initial_timeout || -1),
57
57
  (input_node.inter_digit_timeout || -1),
58
58
  input_node.terminator
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Punchblock
4
- VERSION = "2.0.2"
4
+ VERSION = "2.1.0"
5
5
  end
@@ -31,8 +31,8 @@ Gem::Specification.new do |s|
31
31
  s.add_runtime_dependency %q<celluloid>, ["~> 0.14"]
32
32
  s.add_runtime_dependency %q<ruby_ami>, ["~> 2.0"]
33
33
  s.add_runtime_dependency %q<ruby_fs>, ["~> 1.1"]
34
- s.add_runtime_dependency %q<ruby_speech>, ["~> 2.0"]
35
- s.add_runtime_dependency %q<virtus>, ["~> 0.5"]
34
+ s.add_runtime_dependency %q<ruby_speech>, ["~> 2.3"]
35
+ s.add_runtime_dependency %q<virtus>, ["~> 1.0"]
36
36
  s.add_runtime_dependency %q<ruby_jid>, ["~> 1.0"]
37
37
 
38
38
  s.add_development_dependency %q<bundler>, ["~> 1.0"]
@@ -127,6 +127,60 @@ module Punchblock
127
127
  end
128
128
  end
129
129
 
130
+ context 'with a builtin grammar' do
131
+ let(:original_command_opts) { { grammar: { url: 'builtin:dtmf/boolean' } } }
132
+
133
+ before do
134
+ subject.execute
135
+ expected_event
136
+ send_ami_events_for_dtmf 1
137
+ end
138
+
139
+ let :expected_nlsml do
140
+ RubySpeech::NLSML.draw do
141
+ interpretation confidence: 1 do
142
+ instance "true"
143
+ input "1", mode: :dtmf
144
+ end
145
+ end
146
+ end
147
+
148
+ let :expected_event do
149
+ Punchblock::Component::Input::Complete::Match.new nlsml: expected_nlsml
150
+ end
151
+
152
+ it "should use RubySpeech builtin grammar" do
153
+ reason.should be == expected_event
154
+ end
155
+ end
156
+
157
+ context 'with a parameterized builtin grammar' do
158
+ let(:original_command_opts) { { grammar: { url: 'builtin:dtmf/boolean?n=3;y=4' } } }
159
+
160
+ before do
161
+ subject.execute
162
+ expected_event
163
+ send_ami_events_for_dtmf 4
164
+ end
165
+
166
+ let :expected_nlsml do
167
+ RubySpeech::NLSML.draw do
168
+ interpretation confidence: 1 do
169
+ instance "true"
170
+ input "4", mode: :dtmf
171
+ end
172
+ end
173
+ end
174
+
175
+ let :expected_event do
176
+ Punchblock::Component::Input::Complete::Match.new nlsml: expected_nlsml
177
+ end
178
+
179
+ it "should use RubySpeech builtin grammar" do
180
+ reason.should be == expected_event
181
+ end
182
+ end
183
+
130
184
  context 'with multiple grammars' do
131
185
  let(:original_command_opts) { { :grammars => [{:value => grammar}, {:value => grammar}] } }
132
186
  it "should return an error and not execute any actions" do
@@ -123,6 +123,70 @@ module Punchblock
123
123
  end
124
124
  end
125
125
 
126
+ context 'with a builtin grammar' do
127
+ let(:original_command_opts) { { grammar: { url: 'builtin:dtmf/boolean' } } }
128
+
129
+ before do
130
+ subject.execute
131
+ expected_event
132
+ send_dtmf 1
133
+ end
134
+
135
+ let :expected_nlsml do
136
+ RubySpeech::NLSML.draw do
137
+ interpretation confidence: 1 do
138
+ instance "true"
139
+ input "1", mode: :dtmf
140
+ end
141
+ end
142
+ end
143
+
144
+ let :expected_event do
145
+ Punchblock::Component::Input::Complete::Match.new nlsml: expected_nlsml
146
+ end
147
+
148
+ it "should use RubySpeech builtin grammar" do
149
+ reason.should be == expected_event
150
+ end
151
+ end
152
+
153
+ context 'with a parameterized builtin grammar' do
154
+ let(:original_command_opts) { { grammar: { url: 'builtin:dtmf/boolean?n=3;y=4' } } }
155
+
156
+ before do
157
+ subject.execute
158
+ expected_event
159
+ send_dtmf 4
160
+ end
161
+
162
+ let :expected_nlsml do
163
+ RubySpeech::NLSML.draw do
164
+ interpretation confidence: 1 do
165
+ instance "true"
166
+ input "4", mode: :dtmf
167
+ end
168
+ end
169
+ end
170
+
171
+ let :expected_event do
172
+ Punchblock::Component::Input::Complete::Match.new nlsml: expected_nlsml
173
+ end
174
+
175
+ it "should use RubySpeech builtin grammar" do
176
+ reason.should be == expected_event
177
+ end
178
+ end
179
+
180
+ context 'with a bad builtin grammar name' do
181
+ let(:original_command_opts) { { grammar: { url: 'builtin:dtmf/foobar' } } }
182
+
183
+ it "should return an error and not execute any actions" do
184
+ subject.execute
185
+ error = ProtocolError.new.setup 'option error', 'foobar is an invalid builtin grammar'
186
+ original_command.response(0.1).should be == error
187
+ end
188
+ end
189
+
126
190
  context 'with multiple grammars' do
127
191
  let(:original_command_opts) { { :grammars => [{:value => grammar}, {:value => grammar}] } }
128
192
  it "should return an error and not execute any actions" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: punchblock
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Goecke
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-10-17 00:00:00.000000000 Z
13
+ date: 2013-11-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: nokogiri
@@ -156,28 +156,28 @@ dependencies:
156
156
  requirements:
157
157
  - - ~>
158
158
  - !ruby/object:Gem::Version
159
- version: '2.0'
159
+ version: '2.3'
160
160
  type: :runtime
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - ~>
165
165
  - !ruby/object:Gem::Version
166
- version: '2.0'
166
+ version: '2.3'
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: virtus
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
171
  - - ~>
172
172
  - !ruby/object:Gem::Version
173
- version: '0.5'
173
+ version: '1.0'
174
174
  type: :runtime
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - ~>
179
179
  - !ruby/object:Gem::Version
180
- version: '0.5'
180
+ version: '1.0'
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: ruby_jid
183
183
  requirement: !ruby/object:Gem::Requirement