module Public

Constants

DATAURI

location of where public files are placed on the web

Public Class Methods

getJSON(pubname) click to toggle source

contents of a given public file, read from local copy if possible, fetched from the web otherwise; parsed as JSON

# File lib/whimsy/public.rb, line 31
def self.getJSON(pubname)
  JSON.parse(getfile(pubname))
end
getfile(pubname) click to toggle source

contents of a given public file, read from local copy if possible, fetched from the web otherwise

# File lib/whimsy/public.rb, line 16
  def self.getfile(pubname)
    local_copy = File.expand_path('../../../www/public/'+pubname, __FILE__.untaint).untaint
    if File.exist? local_copy
#      Wunderbar.info "Using local copy of #{pubname}"
      File.read(local_copy)
    else
#      Wunderbar.info "Fetching remote copy of #{pubname}"
      response = Net::HTTP.get_response(URI(DATAURI+pubname))
      raise ArgumentError, "'#{pubname}' #{response.message}" unless response.is_a?(Net::HTTPSuccess)
      response.body
    end
  end