Class: Jetel::Downloaders::Ruby
- Inherits:
-
BaseDownloader
- Object
- BaseDownloader
- Jetel::Downloaders::Ruby
- Defined in:
- lib/jetel/downloaders/ruby/ruby.rb
Constant Summary
Constants inherited from BaseDownloader
BaseDownloader::DATA_DIRECTORY, BaseDownloader::OPTS_DOWNLOAD
Instance Method Summary collapse
Instance Method Details
#download(url, opts = BaseDownloader::OPTS_DOWNLOAD) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# 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 |