class Gtin2atc::SwissindexDownloader

Public Class Methods

new(options={}, type=:pharma, lang='DE') click to toggle source
Calls superclass method Gtin2atc::Downloader::new
# File lib/gtin2atc/downloader.rb, line 194
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

Public Instance Methods

download() click to toggle source
# File lib/gtin2atc/downloader.rb, line 213
    def download
      begin
        file2save, dated = Gtin2atc::Util.get_latest_and_dated_name("swissindex_#{@type}_#{@lang}", '.xml')
        if File.exists?(file2save) and diff_hours = ((Time.now-File.ctime(file2save)).to_i/3600) and diff_hours < 24
          Util.debug_msg "Skip download of #{file2save} as only #{diff_hours} hours old"
          return IO.read(file2save)
        end
        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)
        if response.success?
          if xml = response.to_xml
            response = nil # win
            FileUtils.makedirs(WorkDir)
            File.open(file2save, 'w+') { |file| file.write xml }
            Util.debug_msg "Swissindex download successful"
          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
      Util.debug_msg "Download of #{file2save} finished"
      xml
    end
init() click to toggle source
# File lib/gtin2atc/downloader.rb, line 203
def init
  config = {
    :log_level       => :info,
    :log             => false, # $stdout
    :raise_errors    => true,
    :ssl_version     => :SSLv3,
    :wsdl            => @url
  }
  @client = Savon::Client.new(config)
end
origin() click to toggle source
# File lib/gtin2atc/downloader.rb, line 200
def origin
  @url
end