Module: S3MediaServerApi::Downloader

Defined in:
lib/s3_media_server_api/downloader.rb

Class Method Summary collapse

Class Method Details

.download_by_url(url) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/s3_media_server_api/downloader.rb', line 8

def download_by_url(url)
  file_path = generate_random_file_name
  easy = Curl::Easy.new(url)
  easy.ssl_verify_peer = false
  File.open(file_path, 'wb') do |f|
    easy.on_body {|data| f << data; data.size }
    easy.perform
  end
  file_path
end

.remove_if_exists(path) ⇒ Object



19
20
21
22
# File 'lib/s3_media_server_api/downloader.rb', line 19

def remove_if_exists(path)
  return if path.nil?
  FileUtils.rm(path) if File.exist?(path)
end