Class: XcodeInstall::Curl

Inherits:
Object
  • Object
show all
Defined in:
lib/xcode/install.rb

Constant Summary collapse

COOKIES_PATH =
Pathname.new('/tmp/curl-cookies.txt')

Instance Method Summary collapse

Instance Method Details

#fetch(url, directory = nil, cookies = nil, output = nil, progress = true) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/xcode/install.rb', line 12

def fetch(url, directory = nil, cookies = nil, output = nil, progress = true)
  options = cookies.nil? ? '' : "-b '#{cookies}' -c #{COOKIES_PATH}"
  # options += ' -vvv'

  uri = URI.parse(url)
  output ||= File.basename(uri.path)
  output = (Pathname.new(directory) + Pathname.new(output)) if directory

  progress = progress ? '-#' : '-s'
  command = "curl #{options} -L -C - #{progress} -o #{output} #{url}"
  IO.popen(command).each do |fd|
    puts(fd)
  end
  result = $CHILD_STATUS.to_i == 0

  FileUtils.rm_f(COOKIES_PATH)
  result
end