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



264
265
266
267
268
269
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
298
299
# File 'lib/oddb2xml/downloader.rb', line 264

def download
  file = "swissmedic_info.zip"
  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
    return read_xml_form_zip(/^AipsDownload_/iu, file)
  rescue Timeout::Error, Errno::ETIMEDOUT
    retrievable? ? retry : raise
  rescue NoMethodError
    # pass
  ensure
    # win
    deleted = false
    if File.exists?(file)
      until deleted
        begin
          File.unlink(file)
          deleted = true
        rescue Errno::EACCES # Permission Denied on Windows
        end
      end
    end
  end
end

#initObject



259
260
261
262
263
# File 'lib/oddb2xml/downloader.rb', line 259

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