Sha256: fc8e48a30e3ac9de98eeff8a5759b9c6842ae6f281c82180d06bdbbec37cb59f

Contents?: true

Size: 788 Bytes

Versions: 2

Compression:

Stored size: 788 Bytes

Contents

require 'net/http'
require 'ortega/file'
require 'ortega/uri'
require 'active_support/core_ext/hash/indifferent_access'

module Ortega
  module HTTP
    include Ortega::URI

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ortega-0.0.8 lib/ortega/http.rb
ortega-0.0.7 lib/ortega/http.rb