Class: FSR::Cmd::Sofia::Status

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

Constant Summary

Constants inherited from Command

Command::DEFAULT_OPTIONS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fs_socket = nil, args = {}) ⇒ Status

Returns a new instance of Status.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/fsr/cmd/sofia/status.rb', line 8

def initialize(fs_socket = nil, args = {})
  @fs_socket = fs_socket # FSR::CommandSocket object
  @status  = args[:status] # Status type; profile or gateway
  @name = args[:name] # Name of profile or gateway
  @xml_status = !!args[:xml_status] # Return results in xml rather than text
  # If status is given, make sure it's profile or gateway
  unless @status.nil?
    raise "status must be profile or gateway" unless @status =~ /profile|gateway/i
  end
  if @status
    raise "must provide a profile or gateway name" unless @name
  end
end

Instance Attribute Details

#fs_socketObject (readonly)

Returns the value of attribute fs_socket.



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

def fs_socket
  @fs_socket
end

Instance Method Details

#rawObject

This method builds the API command to send to the freeswitch event socket



30
31
32
33
34
35
36
37
# File 'lib/fsr/cmd/sofia/status.rb', line 30

def raw
  status_type = @xml_status ? 'xmlstatus' : 'status'
  if @status and @name
    orig_command = "sofia #{status_type} #{@status} #{@name}"
  else
    orig_command = "sofia #{status_type}"
  end
end

#run(api_method = :api) ⇒ Object

Send the command to the event socket, using api by default.



23
24
25
26
27
# File 'lib/fsr/cmd/sofia/status.rb', line 23

def run(api_method = :api)
  orig_command = "%s %s" % [api_method, raw]
  Log.debug "saying #{orig_command}"
  @fs_socket.say(orig_command)
end