Sha256: 926130c5890a55eb8623a8d9e9aabfed1ee3229dac66a8ac9a1d0b9561b5fa6e

Contents?: true

Size: 768 Bytes

Versions: 1

Compression:

Stored size: 768 Bytes

Contents

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

module Ortega
  module HTTP
    def download(url, options = {}, &block)
      options = options.with_indifferent_access
      url = HTTP.url_helper(url)
      options[:name] = url.path if options[:name].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)
        end
      end
    end
    
    class << self
      def url_helper(url)
        url.insert(0, 'http://') unless url.match(/http/) 
        return URI url
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ortega-0.0.6 lib/ortega/http.rb