Class: AviraUpdateMirrors::Download
- Inherits:
-
Object
- Object
- AviraUpdateMirrors::Download
- Includes:
- HTTParty
- Defined in:
- lib/avira_update_mirrors/download.rb
Instance Attribute Summary collapse
-
#download_file_path ⇒ Object
readonly
Returns the value of attribute download_file_path.
-
#downloads_dir ⇒ Object
readonly
Returns the value of attribute downloads_dir.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #downloaded? ⇒ Boolean
-
#initialize(base_url, options = {}) ⇒ Download
constructor
A new instance of Download.
- #perform(expand_url) ⇒ Object
Constructor Details
#initialize(base_url, options = {}) ⇒ Download
Returns a new instance of Download.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/avira_update_mirrors/download.rb', line 9 def initialize(base_url, = {}) @base_url = base_url @base_dir = [:base_dir] || Dir.pwd @downloads_dir = File.join(@base_dir, 'tmp', Time.now.strftime("%Y%m%d%H%M%S%L")) FileUtils.mkdir_p @downloads_dir @error = nil @download_file_path = nil self.class.base_uri @base_url end |
Instance Attribute Details
#download_file_path ⇒ Object (readonly)
Returns the value of attribute download_file_path.
7 8 9 |
# File 'lib/avira_update_mirrors/download.rb', line 7 def download_file_path @download_file_path end |
#downloads_dir ⇒ Object (readonly)
Returns the value of attribute downloads_dir.
7 8 9 |
# File 'lib/avira_update_mirrors/download.rb', line 7 def downloads_dir @downloads_dir end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
7 8 9 |
# File 'lib/avira_update_mirrors/download.rb', line 7 def error @error end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
7 8 9 |
# File 'lib/avira_update_mirrors/download.rb', line 7 def response @response end |
Instance Method Details
#downloaded? ⇒ Boolean
43 44 45 |
# File 'lib/avira_update_mirrors/download.rb', line 43 def downloaded? !@error end |
#perform(expand_url) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/avira_update_mirrors/download.rb', line 20 def perform() @expand_url = .gsub("\\", "/") @error = nil @download_file_path = File.join(@downloads_dir, @expand_url) FileUtils.mkdir_p File.dirname(@download_file_path) begin @response = self.class.get(@expand_url) rescue Timeout::Error @error = 'timeout' else case @response.code when 200 File.open(@download_file_path, "wb+") do |file| file.write @response.body end when 404 @error = '404' when 500...600 @error = '500' end end end |