freeswitcher 0.7.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -20,7 +20,7 @@ GEMSPEC = Gem::Specification.new do |spec|
20
20
  spec.summary = 'A library for interacting with the "FreeSWITCH":http://freeswitch.org telephony platform'
21
21
  spec.authors = ["Jayson Vaughn", "Michael Fellinger", "Kevin Berry", "TJ Vanderpoel"]
22
22
  spec.email = "FreeSWITCHeR@rubyists.com"
23
- spec.homepage = "http://code.rubyists.com/projects/fs"
23
+ spec.homepage = "http://github.com/rubyists/freeswitcher"
24
24
  spec.add_dependency "eventmachine"
25
25
 
26
26
  spec.files = GEM_FILES
@@ -0,0 +1,39 @@
1
+ require "fsr/app"
2
+ module FSR
3
+ module Cmd
4
+ class Chat < Command
5
+
6
+ attr_reader :fs_socket
7
+
8
+ def initialize(fs_socket = nil, args = {})
9
+
10
+ raise(ArgumentError, "args (Passed: <<<#{args}>>>) must be a hash") unless args.kind_of?(Hash)
11
+
12
+ @fs_socket = fs_socket # FSR::CommandSocket obj
13
+ @protocol = args[:protocol] ? args[:protocol] : 'sip'
14
+ raise(ArgumentError, "Cannot send chat with invalid protocol") unless @protocol.to_s.size > 0
15
+ @from = args[:from] # i.e. 1000@192.168.1.1
16
+ raise(ArgumentError, "Cannot send chat without :from set") unless @from.to_s.size > 0
17
+ @to = args[:to] # i.e. 1001@192.168.1.1
18
+ raise(ArgumentError, "Cannot send chat without :to set") unless @to.to_s.size > 0
19
+ @message = args[:message]
20
+ raise(ArgumentError, "Cannot send chat without :message set") unless @message.to_s.size > 0
21
+ @message.gsub!('|', '\|')
22
+ end
23
+
24
+ # Send the command to the event socket, using api by default.
25
+ def run(api_method = :api)
26
+ orig_command = "%s %s" % [api_method, raw]
27
+ Log.debug "saying #{orig_command}"
28
+ @fs_socket.say(orig_command)
29
+ end
30
+
31
+ # This method builds the API command to send to the freeswitch event socket
32
+ def raw
33
+ %Q(chat #{@protocol}|#{@from}|#{@to}|#{@message})
34
+ end
35
+ end
36
+
37
+ register(:chat, Chat)
38
+ end
39
+ end
@@ -9,6 +9,7 @@ module FSR
9
9
  @fs_socket = fs_socket # FSR::CommandSocket object
10
10
  @status = args[:status] # Status type; profile or gateway
11
11
  @name = args[:name] # Name of profile or gateway
12
+ @xml_status = !!args[:xml_status] # Return results in xml rather than text
12
13
  # If status is given, make sure it's profile or gateway
13
14
  unless @status.nil?
14
15
  raise "status must be profile or gateway" unless @status =~ /profile|gateway/i
@@ -27,10 +28,11 @@ module FSR
27
28
 
28
29
  # This method builds the API command to send to the freeswitch event socket
29
30
  def raw
31
+ status_type = @xml_status ? 'xmlstatus' : 'status'
30
32
  if @status and @name
31
- orig_command = "sofia status #{@status} #{@name}"
33
+ orig_command = "sofia #{status_type} #{@status} #{@name}"
32
34
  else
33
- orig_command = "sofia status"
35
+ orig_command = "sofia #{status_type}"
34
36
  end
35
37
  end
36
38
  end
@@ -0,0 +1,58 @@
1
+ require 'spec/helper'
2
+ require "fsr/cmd"
3
+ FSR::Cmd.load_command("chat")
4
+
5
+ describe "Testing FSR::Cmd::Chat" do
6
+ # Invalid originates
7
+ it "Must be passed an argument hash" do
8
+ lambda { FSR::Cmd::Chat.new(nil, :endpoint) }.should.raise(ArgumentError).
9
+ message.should.match(/args \(Passed: <<<.*?>>>\) must be a hash/)
10
+ end
11
+
12
+ it "Can not send a chat without a message" do
13
+ lambda { FSR::Cmd::Chat.new(nil, :to => '1000', :from => '1001') }.should.raise(ArgumentError).
14
+ message.should.match(/Cannot send chat without :message set/)
15
+ end
16
+
17
+ it "Can not send a chat without to set" do
18
+ lambda { FSR::Cmd::Chat.new(nil, :message => 'Hello', :from => '1001') }.should.raise(ArgumentError).
19
+ message.should.match(/Cannot send chat without :to set/)
20
+ end
21
+
22
+ it "Can not send a chat without from set" do
23
+ lambda { FSR::Cmd::Chat.new(nil, :message => 'Hello', :to => '1000') }.should.raise(ArgumentError).
24
+ message.should.match(/Cannot send chat without :from set/)
25
+ end
26
+
27
+ it "Can not send a chat with invalid protocol" do
28
+ lambda { FSR::Cmd::Chat.new(nil, :message => 'Hello', :to => '1000', :from => '1001', :protocol => '') }.should.raise(ArgumentError).
29
+ message.should.match(/Cannot send chat with invalid protocol/)
30
+ end
31
+
32
+ it "Creates a valid chat message with sensible default protocol" do
33
+ chat = FSR::Cmd::Chat.new(nil, :message => 'Hello', :to => '1000', :from => '1001')
34
+ chat.raw.should == "chat sip|1001|1000|Hello"
35
+ end
36
+
37
+ # Different options choices
38
+ it "Honours different protocols" do
39
+ chat = FSR::Cmd::Chat.new(nil, :message => 'Hello', :to => '1000', :from => '1001', :protocol => 'jingle')
40
+ chat.raw.should == "chat jingle|1001|1000|Hello"
41
+ end
42
+
43
+ it "Honours a more realistic to" do
44
+ chat = FSR::Cmd::Chat.new(nil, :message => 'Hello', :to => '1000@192.168.1.1', :from => '1001')
45
+ chat.raw.should == "chat sip|1001|1000@192.168.1.1|Hello"
46
+ end
47
+
48
+ it "Honours a more complex message" do
49
+ chat = FSR::Cmd::Chat.new(nil, :message => 'Hello, friendly sir. "*/;{(\|/;,@#,/', :to => '1000@192.168.1.1', :from => '1001')
50
+ chat.raw.should == 'chat sip|1001|1000@192.168.1.1|Hello, friendly sir. "*/;{(\\\|/;,@#,/'
51
+ end
52
+
53
+ it "Escapes pipes from messages" do
54
+ chat = FSR::Cmd::Chat.new(nil, :message => 'He||o there |ove|y', :to => '1000@192.168.1.1', :from => '1001')
55
+ chat.raw.should == %Q(chat sip|1001|1000@192.168.1.1|He\\|\\|o there \\|ove\\|y)
56
+ end
57
+
58
+ end
@@ -28,6 +28,28 @@ describe "Testing FSR::Cmd::Sofia" do
28
28
  status = sofia.status(:status => 'gateway', :name => 'server')
29
29
  status.raw.should == "sofia status gateway server"
30
30
  end
31
+ ## Sofia XML Status ##
32
+ it "FSR::Cmd::Sofia should allow xmlstatus" do
33
+ sofia = FSR::Cmd::Sofia.new
34
+ status = sofia.status(:xml_status => true)
35
+ status.raw.should == "sofia xmlstatus"
36
+ end
37
+ # Sofia XML Status profile internal
38
+ it "FSR::Cmd::Sofia should allow status profile internal" do
39
+ sofia = FSR::Cmd::Sofia.new
40
+ status = sofia.status(:status => 'profile',
41
+ :name => 'internal',
42
+ :xml_status => true)
43
+ status.raw.should == "sofia xmlstatus profile internal"
44
+ end
45
+ # Sofia XML Status gateway server
46
+ it "FSR::Cmd::Sofia should allow status gateway server" do
47
+ sofia = FSR::Cmd::Sofia.new
48
+ status = sofia.status(:status => 'gateway',
49
+ :name => 'server',
50
+ :xml_status => true)
51
+ status.raw.should == "sofia xmlstatus gateway server"
52
+ end
31
53
 
32
54
  ## Sofia profile ##
33
55
  it "FSR::Cmd::Sofia should allow profile" do
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 = [:kill, :uuid_dump, :originate, :sofia, :fsctl, :sofia_contact, :status, :calls, :call_center, :channels, :enum, :sched_hangup, :sched_transfer, :uuid_transfer, :uuid_send_dtmf, :conference, :valet_info] # If you add a command add it to this set
19
+ all_commands = [:kill, :uuid_dump, :originate, :chat, :sofia, :fsctl, :sofia_contact, :status, :calls, :call_center, :channels, :enum, :sched_hangup, :sched_transfer, :uuid_transfer, :uuid_send_dtmf, :conference, :valet_info] # 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|
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: freeswitcher
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.7.1
5
+ version: 0.8.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jayson Vaughn
@@ -13,7 +13,7 @@ autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
15
 
16
- date: 2012-01-13 00:00:00 -06:00
16
+ date: 2012-11-26 00:00:00 -06:00
17
17
  default_executable:
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
@@ -85,6 +85,7 @@ files:
85
85
  - lib/fsr/cmd/call_center.rb
86
86
  - lib/fsr/cmd/calls.rb
87
87
  - lib/fsr/cmd/channels.rb
88
+ - lib/fsr/cmd/chat.rb
88
89
  - lib/fsr/cmd/conference.rb
89
90
  - lib/fsr/cmd/enum.rb
90
91
  - lib/fsr/cmd/fsctl.rb
@@ -167,6 +168,7 @@ files:
167
168
  - spec/fsr/cmd/call_center.rb
168
169
  - spec/fsr/cmd/calls.rb
169
170
  - spec/fsr/cmd/channels.rb
171
+ - spec/fsr/cmd/chat.rb
170
172
  - spec/fsr/cmd/conference.rb
171
173
  - spec/fsr/cmd/enum.rb
172
174
  - spec/fsr/cmd/kill.rb
@@ -187,7 +189,7 @@ files:
187
189
  - spec/fsr/loading.rb
188
190
  - spec/fsr/utils/dtmf.rb
189
191
  has_rdoc: true
190
- homepage: http://code.rubyists.com/projects/fs
192
+ homepage: http://github.com/rubyists/freeswitcher
191
193
  licenses: []
192
194
 
193
195
  post_install_message: |
@@ -421,6 +423,7 @@ test_files:
421
423
  - spec/fsr/cmd/call_center.rb
422
424
  - spec/fsr/cmd/calls.rb
423
425
  - spec/fsr/cmd/channels.rb
426
+ - spec/fsr/cmd/chat.rb
424
427
  - spec/fsr/cmd/conference.rb
425
428
  - spec/fsr/cmd/enum.rb
426
429
  - spec/fsr/cmd/kill.rb