Class: BandCamp::Downloader

Inherits:
Object
  • Object
show all
Defined in:
lib/band_camp/downloader.rb

Class Method Summary collapse

Class Method Details

.download(options) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/band_camp/downloader.rb', line 6

def self.download(options)
  url = options[:url] || raise(ArgumentError, "No url provided")
  file_name = options[:file_name] || raise(ArgumentError, "No file_name provided")

  puts "Saving #{file_name}" if options[:debug]

  parsed_url = URI.parse(url)
  res = Net::HTTP.start(parsed_url.host, parsed_url.port) {|http|
    http.get("#{parsed_url.path}?#{parsed_url.query}")
  }

  File.open(file_name, "w") do |file|
    file.puts res.body
  end
end