Class: Tika::Download

Inherits:
Object
  • Object
show all
Defined in:
lib/tika/download.rb

Constant Summary collapse

DEFAULT_TIKA_VERSION =
"1.9"

Class Method Summary collapse

Class Method Details

.callObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/tika/download.rb', line 6

def self.call
  version = ENV["TIKA_VERSION"] || DEFAULT_TIKA_VERSION
  destination_path = ENV["TIKA_PATH"] || App::DEFAULT_TIKA_PATH
  unless Dir.exist? File.dirname(destination_path)
    raise Error, "Destination path directory does not exist: #{File.dirname(destination_path)}"
  end
  if File.exist? destination_path
    raise Error, "File exists at destination path #{destination_path}."
  end
  download_basename = "tika-app-#{version}.jar"
  download_url = "http://archive.apache.org/dist/tika/#{download_basename}"

  Dir.mktmpdir do |tmpdir|
    puts "Downloading Tika app from #{download_url} ... "
    FileUtils.cd(tmpdir) do
      system "curl -O #{download_url}"
      FileUtils.mv(download_basename, destination_path)
      puts "Moved Tika app to #{destination_path}."
    end
  end
end