Class: Gtin2atc::SwissmedicDownloader
- Inherits:
-
Downloader
- Object
- Downloader
- Gtin2atc::SwissmedicDownloader
- Defined in:
- lib/gtin2atc/downloader.rb
Instance Attribute Summary
Attributes inherited from Downloader
Instance Method Summary collapse
- #download ⇒ Object
- #init ⇒ Object
-
#initialize(type = :orphan) ⇒ SwissmedicDownloader
constructor
A new instance of SwissmedicDownloader.
- #origin ⇒ Object
Constructor Details
#initialize(type = :orphan) ⇒ SwissmedicDownloader
Returns a new instance of SwissmedicDownloader.
148 149 150 151 152 153 |
# 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 |
Instance Method Details
#download ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# 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.(file2save) end Util.debug_msg "Must download #{file2save} #{File.(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.(file2save) rescue Timeout::Error, Errno::ETIMEDOUT retrievable? ? retry : raise ensure Gtin2atc.download_finished(file2save, false) end return File.(file2save) end |
#init ⇒ Object
157 158 159 160 161 162 163 164 165 166 |
# 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 ⇒ Object
154 155 156 |
# File 'lib/gtin2atc/downloader.rb', line 154 def origin @url end |