module Shibkit::MetaMeta::Mixin::CachedDownloads

A few simple utility functions for slurping data from XML

Public Class Methods

included(receiver) click to toggle source

Automatically add class methods to the including class

# File lib/shibkit/meta_meta/mixin/cached_downloads.rb, line 38
def self.included(receiver)

  receiver.extend(CDClassMethods)

end

Public Instance Methods

fetch_local(filename) click to toggle source

Copy a filesystem file into the working directory (slower but safer)

# File lib/shibkit/meta_meta/mixin/cached_downloads.rb, line 45
def fetch_local(filename)
  
  return unless filename
  
  file_path = ::File.expand_path(filename)
  raise "Can't access file #{file_path}!" unless ::File.exists?(file_path) and
    ::File.readable?(file_path)

  file = Tempfile.new(Time.new.to_i.to_s) 
  open(file_path, 'w') { |f| f << http_response.to_s }

  return file

end
fetch_remote(url) click to toggle source

Copy a remote file into the working directory, also caching it for next update

# File lib/shibkit/meta_meta/mixin/cached_downloads.rb, line 61
def fetch_remote(url)

  self.class.init_caches 
 
  http_response = RestClient.get(url)

  file = Tempfile.new(Time.new.to_i.to_s)
  open(file.path, 'w') { |f| f << http_response.to_s }

  return file

end