module Urifetch

Public Class Methods

fetch(url,args={}) click to toggle source
# File lib/urifetch.rb, line 26
def self.fetch(url,args={})
  if valid_url?(url)
    uri = Addressable::URI.heuristic_parse(url.to_s)
    @@router.find(uri).execute!
  else
    raise ArgumentError, "Invalid URL"
  end
end
route(args={},&block) click to toggle source
# File lib/urifetch.rb, line 40
def self.route(args={},&block)
  @@router = Router.new(args) do
    instance_eval(&block)
  end
end
valid_url?(url) click to toggle source
# File lib/urifetch.rb, line 35
def self.valid_url?(url)
  # Validates URL according to Cloudsdale.org standards
  !(url =~ /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix).nil?
end