class ADPDownloader::Runner

Public Class Methods

new(arguments) click to toggle source
# File lib/adp-downloader/runner.rb, line 6
def initialize(arguments)
  @arguments = arguments
end

Public Instance Methods

run() click to toggle source
# File lib/adp-downloader/runner.rb, line 10
def run
  parse_options
  begin
    downloader = Downloader.new(HttpClient.new)
    downloader.get_statements('pay', downloader.pay_statements)
    # FIXME: downloading tax statements requires extra steps :(
    # downloader.get_statements('tax', downloader.tax_statements)
  rescue Exception => e
    path = log_exception_to_file(e)
    puts "An error ocurred: #{e}"
    puts "Details were logged to #{path}"
    exit 1
  end
end

Private Instance Methods

log_exception_to_file(e) click to toggle source
# File lib/adp-downloader/runner.rb, line 26
def log_exception_to_file(e)
  file = Tempfile.new("adp-downloader-")
  file.puts(e)
  file.puts(e.backtrace)
  FileUtils.mv file.path, File.join("", "tmp")
  File.join("", "tmp", File.basename(file.path))
end
parse_options() click to toggle source
# File lib/adp-downloader/runner.rb, line 34
def parse_options
  options = OptionParser.new
  options.banner = "Usage: adp-downloader [options]"
  options.on("-e", "--employer EMP", "Employer name") { |e| Config.employer = e }
  options.on("-v", "--quiet", "Only display errors") { Config.quiet = true }
  options.on("--version", "Display the current version") { puts(VERSION); exit }
  options.on("-h", "--help",  "Show this message")   { puts(options); exit }
  options.parse!(@arguments)
end