Module: Ortega::HTTP

Includes:
URI
Included in:
Ortega
Defined in:
lib/ortega/http.rb

Instance Method Summary collapse

Methods included from URI

#url_helper

Instance Method Details

#download(url, options = {}, &block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ortega/http.rb', line 10

def download(url, options = {}, &block)
  options = options.with_indifferent_access
  url = url_helper(url)
  options[:name] = url.path if options[:name].nil?
  options[:extension] = ::File.extname(url.path) if options[:extension].nil?
  options[:bar] = true if options[:bar].nil?
  file = Ortega::File.get_path(options)

  http = Net::HTTP.new(url.host, url.port)
  http.use_ssl = true if url.scheme == 'https'

  http.start do |http|
    http.request Net::HTTP::Get.new url do |response|
      file.write(response, options)
    end
  end
end