class Playtypus::CLI

Public Instance Methods

play(*args) click to toggle source
# File lib/playtypus/cli.rb, line 13
def play(*args)
  require_relative '../../ascii.rb'
  $logger.debug "playtypus is playing with options #{options.inspect}"
  
  sender = Playtypus::HttpSender.new(options[:host])
  preserve_times = options[:preserve_times]
  calls = []

  if File.directory? options[:call_log]
    $logger.info "--call-log is a directory.  calls will be sent in order, without --preserve-times"
    preserve_times = false
    logs = Dir.glob("#{options[:call_log]}/**/*.json")
    logs.sort.each do |log|
      calls.concat(Playtypus::CallContainer.from_log(File.read(log)).calls)
    end
  else
    log_file = File.read(options[:call_log])
    calls = Playtypus::CallContainer.from_log(log_file).calls
  end
  unless options[:response_log].to_s.empty?
    FileUtils.mkdir_p options[:response_log]
  end
  gateway = Playtypus::Gateway.new(calls, sender, preserve_times, options[:response_log])
  gateway.playback()
end