Class: Oddb2xml::SwissmedicInfoDownloader

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

Instance Method Summary collapse

Methods inherited from Downloader

#initialize

Constructor Details

This class inherits a constructor from Oddb2xml::Downloader

Instance Method Details

#downloadObject



270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# File 'lib/oddb2xml/downloader.rb', line 270

def download
  file = "swissmedic_info.zip"
  begin
    unless Oddb2xml.skip_download(file)
      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
    end
    read_xml_form_zip(/^AipsDownload_/iu, file)
  rescue Timeout::Error, Errno::ETIMEDOUT
    retrievable? ? retry : raise
  rescue NoMethodError
    # pass
  ensure
    Oddb2xml.download_finished(file)
  end
end

#initObject



265
266
267
268
269
# File 'lib/oddb2xml/downloader.rb', line 265

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