class Jetel::Downloaders::Ruby
Public Instance Methods
download(url, opts = BaseDownloader::OPTS_DOWNLOAD)
click to toggle source
Calls superclass method
Jetel::Downloaders::BaseDownloader#download
# File lib/jetel/downloaders/ruby/ruby.rb, line 12 def download(url, opts = BaseDownloader::OPTS_DOWNLOAD) super raw = { :headers => { :user_agent => "jetel/#{Jetel::VERSION}" }, :method => :get, :url => url, # TODO: Load from config, param or so :verify_ssl => false } FileUtils.mkdir_p(opts[:dir]) filename = opts[:filename] || url.split('/').last out_full_path = File.join(opts[:dir], filename) File.open(out_full_path, 'w') do |file| RestClient::Request.execute(raw) do |chunk, _x, response| if response.code.to_s != '200' fail ArgumentError, "Error downloading #{url}. Got response: #{response.code} #{response} #{response.body}" end file.write chunk end end end