Class: Oddb2xml::Downloader

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, url = nil) ⇒ Downloader

Returns a new instance of Downloader.



45
46
47
48
49
50
51
# File 'lib/oddb2xml/downloader.rb', line 45

def initialize(options = {}, url = nil)
  @options = options
  @url = url
  @retry_times = 3
  Oddb2xml.log "Downloader from #{@url} for #{self.class}"
  init
end

Instance Attribute Details

#agent ⇒ Object (readonly)

Returns the value of attribute agent.



44
45
46
# File 'lib/oddb2xml/downloader.rb', line 44

def agent
  @agent
end

#file2save ⇒ Object (readonly)

Returns the value of attribute file2save.



44
45
46
# File 'lib/oddb2xml/downloader.rb', line 44

def file2save
  @file2save
end

#type ⇒ Object (readonly)

Returns the value of attribute type.



44
45
46
# File 'lib/oddb2xml/downloader.rb', line 44

def type
  @type
end

#url ⇒ Object (readonly)

Returns the value of attribute url.



44
45
46
# File 'lib/oddb2xml/downloader.rb', line 44

def url
  @url
end

Instance Method Details

#init ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/oddb2xml/downloader.rb', line 60

def init
  @agent = Mechanize.new
  @agent.user_agent = "Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20100101 Firefox/16.0"
  @agent.redirect_ok = true
  @agent.redirection_limit = 5
  @agent.follow_meta_refresh = true
  if RUBY_PLATFORM =~ (/mswin|mingw|bccwin|cygwin/i) &&
      ENV["SSL_CERT_FILE"].nil?
    cert_store = OpenSSL::X509::Store.new
    cert_store.add_file(File.expand_path("../../../tools/cacert.pem", __FILE__))
    @agent.cert_store = cert_store
  end
  @agent.verify_mode = OpenSSL::SSL::VERIFY_NONE
end

#report_download(url, file) ⇒ Object



53
54
55
56
57
58
# File 'lib/oddb2xml/downloader.rb', line 53

def report_download(url, file)
  Oddb2xml.log sprintf("%-20s: download_as %-24s from %s",
    self.class.to_s.split("::").last,
    File.basename(file),
    url)
end