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 29
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 15
def self.getfile(pubname)
  local_copy = File.expand_path('../../../www/public/' + pubname, __FILE__)
  if File.exist? local_copy
    File.read(local_copy)
  else
    response = Net::HTTP.get_response(URI(DATAURI + pubname))
    raise ArgumentError, "'#{pubname}' #{response.message}" unless response.is_a?(Net::HTTPSuccess)

    response.body
  end
end