Class: FSR::Cmd::Sofia::Profile
- Defined in:
- lib/fsr/cmd/sofia/profile.rb
Constant Summary collapse
- VALID_ACTIONS =
[:start, :stop, :restart, :rescan]
Constants inherited from Command
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#command_string ⇒ Object
Returns the value of attribute command_string.
-
#fs_socket ⇒ Object
Returns the value of attribute fs_socket.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
-
.rescan(profile, socket = FSR::CommandSocket.new) ⇒ Object
Rescan a sip_profile.
-
.restart(profile, socket = FSR::CommandSocket.new) ⇒ Object
Restart a sip_profile.
- .start(profile, socket = FSR::CommandSocket.new) ⇒ Object
-
.stop(profile, socket = FSR::CommandSocket.new) ⇒ Object
Stop a sip_profile.
Instance Method Summary collapse
-
#initialize(fs_socket = nil, options = nil) ⇒ Profile
constructor
A new instance of Profile.
-
#raw ⇒ Object
This method builds the API command to send to the freeswitch event socket.
-
#run(api_method = :api) ⇒ Object
Send the command to the event socket, using api by default.
Constructor Details
#initialize(fs_socket = nil, options = nil) ⇒ Profile
Returns a new instance of Profile.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/fsr/cmd/sofia/profile.rb', line 10 def initialize(fs_socket = nil, = nil) @fs_socket = fs_socket # FSR::CommandSocket object if .kind_of?(String) @command_string = else raise "options must be a String or Hash" unless .kind_of?(Hash) @options = @action = @options[:action] if @action raise "Invalid action, must specify one of #{VALID_ACTIONS.inspect}" unless VALID_ACTIONS.include?(@action) @name = @options[:name] raise "Invalid profile name" unless @name.to_s.match(/\w/) else @command_string = @options[:command_string] # If user wants to send a raw "sofia profile" end end @command_string ||= "" end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
7 8 9 |
# File 'lib/fsr/cmd/sofia/profile.rb', line 7 def action @action end |
#command_string ⇒ Object
Returns the value of attribute command_string.
7 8 9 |
# File 'lib/fsr/cmd/sofia/profile.rb', line 7 def command_string @command_string end |
#fs_socket ⇒ Object
Returns the value of attribute fs_socket.
7 8 9 |
# File 'lib/fsr/cmd/sofia/profile.rb', line 7 def fs_socket @fs_socket end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/fsr/cmd/sofia/profile.rb', line 7 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/fsr/cmd/sofia/profile.rb', line 6 def @options end |
Class Method Details
.rescan(profile, socket = FSR::CommandSocket.new) ⇒ Object
Rescan a sip_profile
55 56 57 |
# File 'lib/fsr/cmd/sofia/profile.rb', line 55 def self.rescan(profile, socket = FSR::CommandSocket.new) new(socket, :name => profile, :action => :rescan) end |
.restart(profile, socket = FSR::CommandSocket.new) ⇒ Object
Restart a sip_profile
45 46 47 |
# File 'lib/fsr/cmd/sofia/profile.rb', line 45 def self.restart(profile, socket = FSR::CommandSocket.new) new(socket, :name => profile, :action => :restart) end |
.start(profile, socket = FSR::CommandSocket.new) ⇒ Object
40 41 42 |
# File 'lib/fsr/cmd/sofia/profile.rb', line 40 def self.start(profile, socket = FSR::CommandSocket.new) new(socket, :name => profile, :action => :start) end |
.stop(profile, socket = FSR::CommandSocket.new) ⇒ Object
Stop a sip_profile
50 51 52 |
# File 'lib/fsr/cmd/sofia/profile.rb', line 50 def self.stop(profile, socket = FSR::CommandSocket.new) new(socket, :name => profile, :action => :stop) end |
Instance Method Details
#raw ⇒ Object
This method builds the API command to send to the freeswitch event socket
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/fsr/cmd/sofia/profile.rb', line 60 def raw raise "Invalid action, must specify (start|stop|restart|rescan) as an action or pass a command_string" unless @command_string or @action if @action if @action_options "sofia profile %s %s %s" % [@name, @action, @action_options] else "sofia profile %s %s" % [@name, @action] end else "sofia profile %s" % @command_string end.to_s.strip end |
#run(api_method = :api) ⇒ Object
Send the command to the event socket, using api by default.
34 35 36 37 38 |
# File 'lib/fsr/cmd/sofia/profile.rb', line 34 def run(api_method = :api) orig_command = "%s %s" % [api_method, raw] Log.debug "saying #{orig_command}" @fs_socket.say(orig_command) end |