lib/oddb2xml/downloader.rb in oddb2xml-1.1.0 vs lib/oddb2xml/downloader.rb in oddb2xml-1.1.1
- old
+ new
@@ -56,33 +56,31 @@
@type = (type == :pharma ? 'Pharma' : 'NonPharma')
url = "https://index.ws.e-mediat.net/Swissindex/#{@type}/ws_#{@type}_V101.asmx?WSDL"
super(url)
end
def init
- Savon.configure do |config|
- config.log_level = :info
- config.log = false # $stdout
- config.raise_errors = true
- end
+ @config = {
+ :log_level => :info,
+ :log => false, # $stdout
+ :raise_errors => true,
+ :ssl_verify_mode => :none,
+ :wsdl => @url
+ }
end
def download_by(lang = 'DE')
- client = Savon::Client.new do |wsdl, http|
- http.auth.ssl.verify_mode = :none
- wsdl.document = @url
- end
+ client = Savon::Client.new(@config)
begin
type = @type
- response = client.request :download_all do
- soap.xml = <<XML
+ soap = <<XML
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<lang xmlns="http://swissindex.e-mediat.net/Swissindex#{type}_out_V101">#{lang}</lang>
</soap:Body>
</soap:Envelope>
XML
- end
+ response = client.call(:download_all, :xml => soap)
if response.success?
if xml = response.to_xml
return xml
else
# received broken data or internal error
@@ -119,9 +117,49 @@
response.save_as file
end
return File.open(file, 'rb')
rescue Timeout::Error
retrievable? ? retry : raise
+ ensure
+ if File.exists? file
+ File.unlink file
+ end
+ end
+ end
+ end
+ class SwissmedicInfoDownloader < Downloader
+ def init
+ @url ||= "http://download.swissmedicinfo.ch/Accept.aspx?ReturnUrl=%2f"
+ end
+ def download
+ file = "swissmedic_info.zip"
+ begin
+ response = nil
+ agent = Mechanize.new
+ agent.ignore_bad_chunking = true
+ 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
+ end
+ xml = ''
+ Zip::ZipFile.foreach(file) do |entry|
+ if entry.name =~ /^AipsDownload_/iu
+ entry.get_input_stream{ |io| xml = io.read }
+ end
+ end
+ return xml
+ rescue Timeout::Error
+ retrievable? ? retry : raise
+ rescue NoMethodError => e
+ # pass
ensure
if File.exists? file
File.unlink file
end
end