Class: FSR::Cmd::Calls
- Inherits:
-
Command
- Object
- Command
- FSR::Cmd::Calls
- Includes:
- Enumerable
- Defined in:
- lib/fsr/cmd/calls.rb
Constant Summary
Constants inherited from Command
Instance Method Summary (collapse)
- - (Object) each(&block)
-
- (Calls) initialize(fs_socket = nil)
constructor
A new instance of Calls.
-
- (Object) raw
This method builds the API command to send to the freeswitch event socket.
-
- (Object) run(api_method = :api)
Send the command to the event socket, using bgapi by default.
Methods inherited from Command
Constructor Details
- (Calls) initialize(fs_socket = nil)
A new instance of Calls
14 15 16 |
# File 'lib/fsr/cmd/calls.rb', line 14 def initialize(fs_socket = nil) @fs_socket = fs_socket # FSR::CommandSocket obj end |
Instance Method Details
- (Object) each(&block)
7 8 9 10 11 12 |
# File 'lib/fsr/cmd/calls.rb', line 7 def each(&block) @calls ||= run if @calls @calls.each { |call| yield call } end end |
- (Object) raw
This method builds the API command to send to the freeswitch event socket
39 40 41 |
# File 'lib/fsr/cmd/calls.rb', line 39 def raw orig_command = "show calls" end |
- (Object) run(api_method = :api)
Send the command to the event socket, using bgapi by default.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/fsr/cmd/calls.rb', line 19 def run(api_method = :api) orig_command = "%s %s" % [api_method, raw] Log.debug "saying #{orig_command}" resp = @fs_socket.say(orig_command) unless resp["body"] == "0 total." call_info, count = resp["body"].split("\n\n") require "fsr/model/call" begin require "fastercsv" calls = FCSV.parse(call_info) rescue LoadError require "csv" calls = CSV.parse(call_info) end return calls[1 .. -1].map { |c| FSR::Model::Call.new(calls[0],*c) } end nil end |