Class: Oddb2xml::SwissIndexDownloader

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

Instance Attribute Summary

Attributes inherited from Downloader

#type

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, type = :pharma, lang = 'DE') ⇒ SwissIndexDownloader

Returns a new instance of SwissIndexDownloader.



207
208
209
210
211
212
# File 'lib/oddb2xml/downloader.rb', line 207

def initialize(options={}, type=:pharma, lang='DE')
  @type = (type == :pharma ? 'Pharma' : 'NonPharma')
  @lang = lang
  url = "https://index.ws.e-mediat.net/Swissindex/#{@type}/ws_#{@type}_V101.asmx?WSDL"
  super(options, url)
end

Instance Method Details

#downloadObject



223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# File 'lib/oddb2xml/downloader.rb', line 223

def download
  begin
    filename =  "swissindex_#{@type}_#{@lang}.xml"
    file2save = File.join(Downloads, "swissindex_#{@type}_#{@lang}.xml")
    return IO.read(file2save) if Oddb2xml.skip_download? and File.exists?(file2save)
    FileUtils.rm_f(file2save, :verbose => false)
    soap = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<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/\">\n<soap:Body>\n  <lang xmlns=\"http://swissindex.e-mediat.net/Swissindex\#{@type}_out_V101\">\#{@lang}</lang>\n</soap:Body>\n</soap:Envelope>\n"
    response = @client.call(:download_all, :xml => soap)
    if response.success?
      if xml = response.to_xml
        response = nil # win
        FileUtils.makedirs(Downloads)
        File.open(file2save, 'w+') { |file| file.write xml }
      else
        # received broken data or internal error
        raise StandardError
      end
    else
      raise Timeout::Error
    end
  rescue HTTPI::SSLError
    exit # catch me in Cli class
  rescue Timeout::Error, Errno::ETIMEDOUT
    retrievable? ? retry : raise
  end
  xml
end

#initObject



213
214
215
216
217
218
219
220
221
222
# File 'lib/oddb2xml/downloader.rb', line 213

def init
  config = {
    :log_level       => :info,
    :log             => false, # $stdout
    :raise_errors    => true,
    :ssl_version     => :SSLv3,
    :wsdl            => @url
  }
  @client = Savon::Client.new(config)
end