Module: RUtilAnts::URLCache

Defined in:
lib/rUtilAnts/URLCache.rb,
lib/rUtilAnts/URLHandlers/FTP.rb,
lib/rUtilAnts/URLHandlers/HTTP.rb,
lib/rUtilAnts/URLHandlers/DataImage.rb,
lib/rUtilAnts/URLHandlers/LocalFile.rb

Defined Under Namespace

Modules: URLHandlers Classes: URLCache

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.initializeURLCacheObject

Initialize a global cache



109
110
111
112
# File 'lib/rUtilAnts/URLCache.rb', line 109

def self.initializeURLCache
  $rUtilAnts_URLCache = URLCache.new
  Object.module_eval('include RUtilAnts::URLCache')
end

Instance Method Details

#getURLContent(iURL, iParameters = {}) ⇒ Object

Get a content from a URL. Here are the different formats the URL can have:

  • Local file name

  • http/https/ftp/ftps:// protocols

  • data:image URI

  • file:// protocol

It also handles redirections or zipped files

Parameters:

  • iURL (String): The URL

  • iParameters (map<Symbol,Object>): Additional parameters:

** :ForceLoad (Boolean): Do we force to refresh the cache ? [optional = false] ** :FollowRedirections (Boolean): Do we follow redirections ? [optional = true] ** :NbrRedirectionsAllowed (Integer): Number of redirections allowed [optional = 10] ** :LocalFileAccess (Boolean): Do we need a local file to read the content from ? If not, the content itself will be given the code block. [optional = false]

  • CodeBlock: The code returning the object corresponding to the content:

** iContent (String): File content, or file name if :LocalFileAccess was true ** Returns: ** Object: Object read from the content, or nil in case of error ** Exception: The error encountered, or nil in case of success Return:

  • Object: The corresponding URL content, or nil in case of failure

  • Exception: The error, or nil in case of success



137
138
139
140
141
# File 'lib/rUtilAnts/URLCache.rb', line 137

def getURLContent(iURL, iParameters = {})
  return $rUtilAnts_URLCache.getURLContent(iURL, iParameters) do |iContent|
    next yield(iContent)
  end
end