forked from bougyman/freeswitcher
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e88a5ad
commit d3f6910
Showing
3 changed files
with
16 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,19 @@ class Chat < Command | |
attr_reader :fs_socket | ||
|
||
def initialize(fs_socket = nil, args = {}) | ||
|
||
raise(ArgumentError, "args (Passed: <<<#{args}>>>) must be a hash") unless args.kind_of?(Hash) | ||
|
||
@fs_socket = fs_socket # FSR::CommandSocket obj | ||
@protocol = args[:protocol] ? args[:protocol] : 'sip' | ||
@from = '1001' | ||
@to = '[email protected]' | ||
@message = 'Oh, hello!' | ||
raise(ArgumentError, "Cannot send chat with invalid protocol") unless @protocol.to_s.size > 0 | ||
@from = args[:from] # i.e. [email protected] | ||
raise(ArgumentError, "Cannot send chat without :from set") unless @from.to_s.size > 0 | ||
@to = args[:to] # i.e. [email protected] | ||
raise(ArgumentError, "Cannot send chat without :to set") unless @to.to_s.size > 0 | ||
@message = args[:message] | ||
raise(ArgumentError, "Cannot send chat without :message set") unless @message.to_s.size > 0 | ||
@message.gsub!('|', '\|') | ||
end | ||
|
||
# Send the command to the event socket, using api by default. | ||
|
@@ -26,6 +34,6 @@ def raw | |
end | ||
end | ||
|
||
register(:chat, Chat) | ||
register(:chat, Chat) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,13 +46,13 @@ | |
end | ||
|
||
it "Honours a more complex message" do | ||
chat = FSR::Cmd::Chat.new(nil, :message => 'Hello, friendly sir. fƒø£0"f', :to => '[email protected]', :from => '1001') | ||
chat.raw.should == %Q(chat sip|1001|[email protected]|Hello, friendly sir. fƒø£0"f) | ||
chat = FSR::Cmd::Chat.new(nil, :message => 'Hello, friendly sir. "*/;{(\|/;,@#,/', :to => '[email protected]', :from => '1001') | ||
chat.raw.should == 'chat sip|1001|[email protected]|Hello, friendly sir. "*/;{(\\\|/;,@#,/' | ||
end | ||
|
||
it "Escapes pipes from messages" do | ||
chat = FSR::Cmd::Chat.new(nil, :message => 'He||o there |ove|y', :to => '[email protected]', :from => '1001') | ||
chat.raw.should == "chat sip|1001|[email protected]|He\|\|o there \|ove\|y" | ||
chat.raw.should == %Q(chat sip|1001|[email protected]|He\\|\\|o there \\|ove\\|y) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters