class Gtin2atc::SwissmedicDownloader
Public Class Methods
new(type=:orphan)
click to toggle source
Calls superclass method
Gtin2atc::Downloader::new
# File lib/gtin2atc/downloader.rb, line 148 def initialize(type=:orphan) @type = :package @xpath = "//div[@id='sprungmarke10_7']//a[@title='Excel-Version Zugelassene Verpackungen*']" @url = "http://www.swissmedic.ch/arzneimittel/00156/00221/00222/00230/index.html?lang=de" super({}, @url) end
Public Instance Methods
download()
click to toggle source
# File lib/gtin2atc/downloader.rb, line 167 def download file2save, dated = Gtin2atc::Util.get_latest_and_dated_name("swissmedic_package", '.xlsx') 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 File.expand_path(file2save) end Util.debug_msg "Must download #{file2save} #{File.expand_path(file2save)}" begin @agent = Mechanize.new page = @agent.get(@url) if link_node = page.search(@xpath).first link = Mechanize::Page::Link.new(link_node, @agent, page) response = link.click response.save_as(file2save) response = nil # win end return File.expand_path(file2save) rescue Timeout::Error, Errno::ETIMEDOUT retrievable? ? retry : raise ensure Gtin2atc.download_finished(file2save, false) end return File.expand_path(file2save) end
init()
click to toggle source
# File lib/gtin2atc/downloader.rb, line 157 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 154 def origin @url end