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.



40
41
42
43
44
45
46
47
# File 'lib/oddb2xml/downloader.rb', line 40

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

Instance Attribute Details

#agentObject (readonly)

Returns the value of attribute agent.



39
40
41
# File 'lib/oddb2xml/downloader.rb', line 39

def agent
  @agent
end

#typeObject (readonly)

Returns the value of attribute type.



39
40
41
# File 'lib/oddb2xml/downloader.rb', line 39

def type
  @type
end

#urlObject (readonly)

Returns the value of attribute url.



39
40
41
# File 'lib/oddb2xml/downloader.rb', line 39

def url
  @url
end

Instance Method Details

#initObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/oddb2xml/downloader.rb', line 54

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 and
     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



48
49
50
51
52
53
# File 'lib/oddb2xml/downloader.rb', line 48

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