Class: Subfinder::Parser::Download

Inherits:
Object
  • Object
show all
Defined in:
lib/subfinder/parser/download.rb

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Download

Returns a new instance of Download.



5
6
7
# File 'lib/subfinder/parser/download.rb', line 5

def initialize(url)
  @url = url
end

Instance Method Details

#response_is_healthy?(res) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
29
30
31
32
# File 'lib/subfinder/parser/download.rb', line 22

def response_is_healthy?(res)
  if res.code != 200
    Logger.info "Error when downloading '#{@url}'\n Error message: resposnse code is #{res.code}\n".red
    false
  elsif res.body.include? 'An error occurred while processing your request.'
    Logger.info "Error when downloading '#{@url}'\n Error message:  'An error occurred while processing your request.'\n".red
    false
  else
    true
  end
end

#saveObject



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/subfinder/parser/download.rb', line 9

def save
  res = RestClient.get @url
  return false unless response_is_healthy? res

  file_name = res.headers[:content_disposition].split('=')[1]
  File.write("#{Config.working_dir}/#{file_name}", res.body)
  Logger.info "Downloaded to #{Config.working_dir}/#{file_name}"
  true
rescue StandardError => e
  Logger.info "Error when downloading '#{@url}'\n Error message: #{e}\n".red
  false
end