Class: Gtin2atc::Downloader

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Downloader.



38
39
40
41
42
43
44
45
# File 'lib/gtin2atc/downloader.rb', line 38

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

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



37
38
39
# File 'lib/gtin2atc/downloader.rb', line 37

def type
  @type
end

Instance Method Details

#initObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/gtin2atc/downloader.rb', line 46

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
  Util.debug_msg "Downloader @agent ist #{@agent}"
end