Class: Oddb2xml::SwissIndexDownloader

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of SwissIndexDownloader.



174
175
176
177
178
179
# File 'lib/oddb2xml/downloader.rb', line 174

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



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/oddb2xml/downloader.rb', line 190

def download
  begin
    if @options[:debug]
      return File.read(File.expand_path("../../../spec/data/swissindex_#{@type}_#{@lang}.xml", __FILE__))
    end
    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)
    if response.success?
      if xml = response.to_xml
        response = nil # win
        if @options[:skip_download]
          file2save = File.expand_path("../../../data/download/swissindex_#{@type}_#{@lang}.xml", __FILE__)
          FileUtils.makedirs(File.dirname(file2save)) unless File.directory?(File.dirname(file2save))
          File.open(file2save, 'w+') { |file| file.puts xml }
        end
        return 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
end

#initObject



180
181
182
183
184
185
186
187
188
189
# File 'lib/oddb2xml/downloader.rb', line 180

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