Class: Oddb2xml::SwissmedicInfoDownloader

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

Instance Attribute Summary

Attributes inherited from Downloader

#agent, #type, #url

Instance Method Summary collapse

Methods inherited from Downloader

#initialize, #report_download

Constructor Details

This class inherits a constructor from Oddb2xml::Downloader

Instance Method Details

#downloadObject



324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
# File 'lib/oddb2xml/downloader.rb', line 324

def download
  file = File.join(Downloads, "swissmedic_info.zip")
  report_download(@url, file)
  FileUtils.rm_f(file, :verbose => false) unless Oddb2xml.skip_download?
  begin
    response = nil
    if home = @agent.get(@url)
      form = home.form_with(:id => 'Form1')
      bttn = form.button_with(:name => 'ctl00$MainContent$btnOK')
      if page = form.submit(bttn)
        form = page.form_with(:id => 'Form1')
        bttn = form.button_with(:name => 'ctl00$MainContent$BtnYes')
        response = form.submit(bttn)
      end
    end
    if response
      response.save_as(file)
      response = nil # win
    end
  rescue Timeout::Error, Errno::ETIMEDOUT
    retrievable? ? retry : raise
  rescue NoMethodError
    # pass
  ensure
    Oddb2xml.download_finished(file)
  end unless File.exists?(file)
  read_xml_from_zip(/^AipsDownload_/iu, file)
end

#initObject



319
320
321
322
323
# File 'lib/oddb2xml/downloader.rb', line 319

def init
  super
  @agent.ignore_bad_chunking = true
  @url ||= "http://download.swissmedicinfo.ch/Accept.aspx?ReturnUrl=%2f"
end