require 'net/http'class String # Returns the contents of the string, assuming it is a url. Could be dangerous. def get(body = nil) url = get_url http = get_http(url) resp = http.get(url.path, body) resp.body end # Attempts to parse <code>self</code> as a URL and then performs an HTTP POST on it, with # the optional parameter as the body of the post. Returns the result of the post. def post(body = nil) url = get_url http = get_http(url) resp = http.post(url.path, body) resp.code_type == Net::HTTPOK end private def get_url URI.parse self end def get_http(url) Net::HTTP.new(url.host, url.port) endend