Class: Oddb2xml::SwissmedicInfoDownloader

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

Instance Attribute Summary

Attributes inherited from Downloader

#agent, #file2save, #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



374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
# File 'lib/oddb2xml/downloader.rb', line 374

def download
  file = File.join(DOWNLOADS, "swissmedic_info.zip")
  report_download(@url, file)
  FileUtils.rm_f(file, verbose: true) unless Oddb2xml.skip_download?
  unless File.exist?(file)
    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
  end
  read_xml_from_zip(/^AipsDownload_/iu, file)
end

#initObject



368
369
370
371
372
# File 'lib/oddb2xml/downloader.rb', line 368

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