lib/oddb2xml/downloader.rb in oddb2xml-2.1.7 vs lib/oddb2xml/downloader.rb in oddb2xml-2.1.8
- old
+ new
@@ -1,7 +1,9 @@
# encoding: utf-8
+require 'net/ntlm/version' # needed to avoid error: uninitialized constant Net::NTLM::VERSION
+require 'rubyntlm'
require 'mechanize'
require 'zip'
require 'savon'
module Oddb2xml
@@ -32,11 +34,11 @@
end
return data
end
end
class Downloader
- attr_reader :type
+ attr_reader :type, :agent
def initialize(options={}, url=nil)
@options = options
@url = url
@retry_times = 3
HTTPI.log = false # disable httpi warning
@@ -53,10 +55,11 @@
ENV['SSL_CERT_FILE'].nil?
cert_store = OpenSSL::X509::Store.new
cert_store.add_file(File.expand_path('../../../tools/cacert.pem', __FILE__))
@agent.cert_store = cert_store
end
+ @agent.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
protected
def retrievable?
if @retry_times > 0
sleep 5
@@ -131,18 +134,18 @@
end
end
class BMUpdateDownloader < Downloader
include DownloadMethod
def download
- @url ||= 'https://raw.github.com/zdavatz/oddb2xml_files/master/BM_Update.txt'
+ @url ||= 'https://raw.githubusercontent.com/zdavatz/oddb2xml_files/master/BM_Update.txt'
download_as('oddb2xml_files_bm_update.txt', 'r')
end
end
class LppvDownloader < Downloader
include DownloadMethod
def download
- @url ||= 'https://raw.github.com/zdavatz/oddb2xml_files/master/LPPV.txt'
+ @url ||= 'https://raw.githubusercontent.com/zdavatz/oddb2xml_files/master/LPPV.txt'
download_as('oddb2xml_files_lppv.txt', 'r')
end
end
class ZurroseDownloader < Downloader
include DownloadMethod
@@ -201,15 +204,14 @@
content = read_xml_from_zip(/Preparations.xml/, File.join(Downloads, File.basename(file)))
FileUtils.rm_f(file, :verbose => false) unless defined?(Rspec)
content
end
end
- class SwissIndexDownloader < Downloader
- def initialize(options={}, type=:pharma, lang='DE')
+ class RefdataDownloader < Downloader
+ def initialize(options={}, type=:pharma)
@type = (type == :pharma ? 'Pharma' : 'NonPharma')
- @lang = lang
- url = "https://index.ws.e-mediat.net/Swissindex/#{@type}/ws_#{@type}_V101.asmx?WSDL"
+ url = "http://refdatabase.refdata.ch/Service/Article.asmx?WSDL"
super(options, url)
end
def init
config = {
:log_level => :info,
@@ -220,23 +222,25 @@
}
@client = Savon::Client.new(config)
end
def download
begin
- filename = "swissindex_#{@type}_#{@lang}.xml"
- file2save = File.join(Downloads, "swissindex_#{@type}_#{@lang}.xml")
+ filename = "refdata_#{@type}.xml"
+ file2save = File.join(Downloads, "refdata_#{@type}.xml")
+ soap = %(<?xml version="1.0" encoding="UTF-8"?>
+<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://refdatabase.refdata.ch/Article_in" xmlns:ns2="http://refdatabase.refdata.ch/">
+ <SOAP-ENV:Body>
+ <ns2:DownloadArticleInput>
+ <ns1:ATYPE>#{@type.upcase}</ns1:ATYPE>
+ </ns2:DownloadArticleInput>
+ </SOAP-ENV:Body>
+ </SOAP-ENV:Envelope>
+</ns1:ATYPE></ns2:DownloadArticleInput></SOAP-ENV:Body>
+)
return IO.read(file2save) if Oddb2xml.skip_download? and File.exists?(file2save)
FileUtils.rm_f(file2save, :verbose => false)
- 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
- response = @client.call(:download_all, :xml => soap)
+ response = @client.call(:download, :xml => soap)
if response.success?
if xml = response.to_xml
response = nil # win
FileUtils.makedirs(Downloads)
File.open(file2save, 'w+') { |file| file.write xml }
@@ -280,10 +284,10 @@
return File.expand_path(file)
end
begin
FileUtils.rm(File.expand_path(file), :verbose => !defined?(RSpec)) if File.exists?(File.expand_path(file))
page = @agent.get(@url)
- if link_node = page.search(@xpath).first
+ if !page.class.is_a?(String) and link_node = page.search(@xpath).first
link = Mechanize::Page::Link.new(link_node, @agent, page)
response = link.click
response.save_as(file)
response = nil # win
end