Class: FSR::Cmd::Sofia::Profile

Inherits:
Command
  • Object
show all
Defined in:
lib/fsr/cmd/sofia/profile.rb

Constant Summary collapse

VALID_ACTIONS =
[:start, :stop, :restart, :rescan]

Constants inherited from Command

Command::DEFAULT_OPTIONS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, options = nil)
  @fs_socket = fs_socket # FSR::CommandSocket object
  if options.kind_of?(String)
    @command_string = options
  else
    raise "options must be a String or Hash" unless options.kind_of?(Hash)
    @options = 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

#actionObject

Returns the value of attribute action.



7
8
9
# File 'lib/fsr/cmd/sofia/profile.rb', line 7

def action
  @action
end

#command_stringObject

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_socketObject

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

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/fsr/cmd/sofia/profile.rb', line 7

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/fsr/cmd/sofia/profile.rb', line 6

def options
  @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

#rawObject

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