Sha256: c4c92e179e0dd7fd6851d1871e3115abb24015813174ec835494f315fc6827cd

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

require "tempfile"
require "optparse"

module ADPDownloader
  class Runner
    def initialize(arguments)
      @arguments = arguments
    end

    def run
      parse_options
      begin
        downloader = Downloader.new(HttpClient.new)
        downloader.get_statements('tax', downloader.tax_statements)
        downloader.get_statements('pay', downloader.pay_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
    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

    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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
adp-downloader-0.3.2 lib/adp-downloader/runner.rb