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) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/xcode/install.rb', line 40

def fetch(url, directory = nil, cookies = nil, output = nil)
	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

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

	FileUtils.rm_f(COOKIES_PATH)
	result
end