Class: Apt::Spy2::Downloader

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

Instance Method Summary collapse

Constructor Details

#initialize(url = nil) ⇒ Downloader

Returns a new instance of Downloader.



7
8
9
# File 'lib/apt/spy2/downloader.rb', line 7

def initialize(url = nil)
  @url = url if !url.nil?
end

Instance Method Details

#do_download(url = nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/apt/spy2/downloader.rb', line 11

def do_download(url = nil)
  @url = url if !url.nil?

  raise "Please supply a url." if url.nil?

  begin
    return open(@url).read
  rescue OpenURI::HTTPError => the_error
    case the_error.io.status[0]
    when "404"
      raise "The URL #{@url} does not exist."
    else
      raise "Status: #{the_error.io.status[0]}"
    end
  end
end