freeswitcher 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/fsr/cmd/uuid_send_dtmf.rb +29 -0
- data/lib/fsr/utils/dtmf.rb +27 -0
- data/lib/fsr/version.rb +1 -1
- data/spec/fsr/cmd/uuid_send_dtmf.rb +22 -0
- data/spec/fsr/loading.rb +1 -1
- data/spec/fsr/utils/dtmf.rb +18 -0
- metadata +9 -3
@@ -0,0 +1,29 @@
|
|
1
|
+
require "fsr/cmd"
|
2
|
+
require "fsr/utils/dtmf"
|
3
|
+
module FSR
|
4
|
+
module Cmd
|
5
|
+
class UuidSendDtmf < Command
|
6
|
+
def initialize(fs_socket = nil, args = {})
|
7
|
+
@fs_socket = fs_socket # FSR::CommandSocket obj
|
8
|
+
@uuid, dtmf = args.values_at(:uuid, :dtmf)
|
9
|
+
raise(ArgumentError, "No uuid given") unless @uuid
|
10
|
+
raise(ArgumentError, "No dtmf data given") unless dtmf
|
11
|
+
@dtmf = FSR::Utils::DTMF.from_string(dtmf)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Send the command to the event socket, using bgapi by default.
|
15
|
+
def run(api_method = :api)
|
16
|
+
orig_command = "%s %s" % [api_method, raw]
|
17
|
+
Log.debug "saying #{orig_command}"
|
18
|
+
@fs_socket.say(orig_command)
|
19
|
+
end
|
20
|
+
|
21
|
+
# This method builds the API command to send to the freeswitch event socket
|
22
|
+
def raw
|
23
|
+
"uuid_send_dtmf #{@uuid} #{@dtmf}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
register(:uuid_send_dtmf, UuidSendDtmf)
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module FSR
|
2
|
+
module Utils
|
3
|
+
module DTMF
|
4
|
+
MAP = Hash[
|
5
|
+
[%w{a b c},
|
6
|
+
%w{d e f},
|
7
|
+
%w{g h i},
|
8
|
+
%w{j k l},
|
9
|
+
%w{m n o},
|
10
|
+
%w{p q r s},
|
11
|
+
%w{t u v},
|
12
|
+
%w{w x y z}
|
13
|
+
].zip((2 .. 9).to_a)
|
14
|
+
]
|
15
|
+
|
16
|
+
def self.from_string(dtmf)
|
17
|
+
dtmf.each_char.map { |char|
|
18
|
+
if digit = MAP[MAP.keys.detect { |k| k.include? char }]
|
19
|
+
digit
|
20
|
+
else
|
21
|
+
char
|
22
|
+
end
|
23
|
+
}.join
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/fsr/version.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
require './spec/helper'
|
2
|
+
require "fsr/cmd"
|
3
|
+
FSR::Cmd.load_command("uuid_send_dtmf")
|
4
|
+
|
5
|
+
describe "Testing FSR::Cmd::UuidSendDtmf" do
|
6
|
+
## UUID Send DTMF Tones ##
|
7
|
+
#uuid_send_dtmf <uuid> <uuid_data>
|
8
|
+
it "FSR::Cmd::UuidSendData should Send DTMF with digits" do
|
9
|
+
cmd = FSR::Cmd::UuidSendDtmf.new nil, uuid: 1234, dtmf: "5555"
|
10
|
+
cmd.raw.should == 'uuid_send_dtmf 1234 5555'
|
11
|
+
end
|
12
|
+
|
13
|
+
it "FSR::Cmd::UuidSendData should Send DTMF with letters" do
|
14
|
+
cmd = FSR::Cmd::UuidSendDtmf.new nil, uuid: 1234, dtmf: "aceventura"
|
15
|
+
cmd.raw.should == 'uuid_send_dtmf 1234 2238368872'
|
16
|
+
end
|
17
|
+
|
18
|
+
it "FSR::Cmd::UuidSendData should raise an argument error without uuid or dtmf" do
|
19
|
+
lambda { FSR::Cmd::UuidSendDtmf.new nil, uuid: 1234 }.should.raise ArgumentError
|
20
|
+
lambda { FSR::Cmd::UuidSendDtmf.new nil, dtmf: 1234 }.should.raise ArgumentError
|
21
|
+
end
|
22
|
+
end
|
data/spec/fsr/loading.rb
CHANGED
@@ -16,7 +16,7 @@ describe "Testing FSR module loading methods" do
|
|
16
16
|
|
17
17
|
# When you add commands you must modify the expected cmds_loaded behavior
|
18
18
|
it "Loads all commands" do
|
19
|
-
all_commands = [:uuid_dump, :originate, :sofia, :fsctl, :sofia_contact, :status, :calls, :call_center, :channels, :enum, :sched_hangup, :sched_transfer, :uuid_transfer] # If you add a command add it to this set
|
19
|
+
all_commands = [:uuid_dump, :originate, :sofia, :fsctl, :sofia_contact, :status, :calls, :call_center, :channels, :enum, :sched_hangup, :sched_transfer, :uuid_transfer, :uuid_send_dtmf] # If you add a command add it to this set
|
20
20
|
cmds_loaded = FSR.load_all_commands
|
21
21
|
cmds_loaded.kind_of?(Array).should == true
|
22
22
|
all_commands.each do |cmd|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "spec/helper"
|
2
|
+
describe "FSR::Utils::DTMF module" do
|
3
|
+
it "Converts letters to numbers" do
|
4
|
+
require "fsr/utils/dtmf"
|
5
|
+
FSR::Utils::DTMF.from_string("afr").should.equal '237'
|
6
|
+
end
|
7
|
+
|
8
|
+
it "Doesn't Affect numbers" do
|
9
|
+
require "fsr/utils/dtmf"
|
10
|
+
FSR::Utils::DTMF.from_string("1234567890").should.equal '1234567890'
|
11
|
+
end
|
12
|
+
|
13
|
+
it "Allows mixed number/letter" do
|
14
|
+
require "fsr/utils/dtmf"
|
15
|
+
FSR::Utils::DTMF.from_string("1a2d3g4k5n6s7u8z90").should.equal '122334455667788990'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 6
|
8
|
-
-
|
9
|
-
version: 0.6.
|
8
|
+
- 1
|
9
|
+
version: 0.6.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jayson Vaughn
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2011-02-
|
20
|
+
date: 2011-02-24 00:00:00 -06:00
|
21
21
|
default_executable:
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
@@ -93,6 +93,7 @@ files:
|
|
93
93
|
- lib/fsr/cmd/sofia_contact.rb
|
94
94
|
- lib/fsr/cmd/status.rb
|
95
95
|
- lib/fsr/cmd/uuid_dump.rb
|
96
|
+
- lib/fsr/cmd/uuid_send_dtmf.rb
|
96
97
|
- lib/fsr/cmd/uuid_transfer.rb
|
97
98
|
- lib/fsr/command_socket.rb
|
98
99
|
- lib/fsr/database.rb
|
@@ -117,6 +118,7 @@ files:
|
|
117
118
|
- lib/fsr/model/queue.rb
|
118
119
|
- lib/fsr/model/tier.rb
|
119
120
|
- lib/fsr/ostruct.rb
|
121
|
+
- lib/fsr/utils/dtmf.rb
|
120
122
|
- lib/fsr/version.rb
|
121
123
|
- lib/rack/middleware.rb
|
122
124
|
- tasks/authors.rake
|
@@ -161,6 +163,7 @@ files:
|
|
161
163
|
- spec/fsr/cmd/sofia.rb
|
162
164
|
- spec/fsr/cmd/sofia/profile.rb
|
163
165
|
- spec/fsr/cmd/uuid_dump.rb
|
166
|
+
- spec/fsr/cmd/uuid_send_dtmf.rb
|
164
167
|
- spec/fsr/cmd/uuid_transfer.rb
|
165
168
|
- spec/fsr/file_methods.rb
|
166
169
|
- spec/fsr/listener.rb
|
@@ -168,6 +171,7 @@ files:
|
|
168
171
|
- spec/fsr/listener/inbound.rb
|
169
172
|
- spec/fsr/listener/outbound.rb
|
170
173
|
- spec/fsr/loading.rb
|
174
|
+
- spec/fsr/utils/dtmf.rb
|
171
175
|
has_rdoc: true
|
172
176
|
homepage: http://code.rubyists.com/projects/fs
|
173
177
|
licenses: []
|
@@ -409,6 +413,7 @@ test_files:
|
|
409
413
|
- spec/fsr/cmd/sofia.rb
|
410
414
|
- spec/fsr/cmd/sofia/profile.rb
|
411
415
|
- spec/fsr/cmd/uuid_dump.rb
|
416
|
+
- spec/fsr/cmd/uuid_send_dtmf.rb
|
412
417
|
- spec/fsr/cmd/uuid_transfer.rb
|
413
418
|
- spec/fsr/file_methods.rb
|
414
419
|
- spec/fsr/listener.rb
|
@@ -416,3 +421,4 @@ test_files:
|
|
416
421
|
- spec/fsr/listener/inbound.rb
|
417
422
|
- spec/fsr/listener/outbound.rb
|
418
423
|
- spec/fsr/loading.rb
|
424
|
+
- spec/fsr/utils/dtmf.rb
|