Sha256: 0362b0f5b8cb7a65335ad746060ed967b4f9831a6728d5385a94cd74b6c8ae0c

Contents?: true

Size: 1.05 KB

Versions: 4

Compression:

Stored size: 1.05 KB

Contents

require "fsr/app"
module FSR
  module Cmd
    class Calls < Command

      include Enumerable
      def each(&block)
        @calls ||= run
        if @calls
          @calls.each { |call| yield call }
        end
      end

      def initialize(fs_socket = nil)
        @fs_socket = fs_socket # FSR::CommandSocket obj
      end

      # Send the command to the event socket, using bgapi by default.
      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"
          require "csv"
          @calls = CSV.parse(call_info)
          return @calls[1 .. -1].map { |c| FSR::Model::Call.new(@calls[0],*c) }
        end
        []
      end

      # This method builds the API command to send to the freeswitch event socket
      def raw
        orig_command = "show calls"
      end
    end

    register(:calls, Calls)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
freeswitcher-0.6.16 lib/fsr/cmd/calls.rb
freeswitcher-0.6.15 lib/fsr/cmd/calls.rb
freeswitcher-0.6.14 lib/fsr/cmd/calls.rb
freeswitcher-0.6.13 lib/fsr/cmd/calls.rb