module WebHelpers

Public Instance Methods

get(url, limit=10) click to toggle source
# File lib/web_helpers.rb, line 5
def get(url, limit=10)
  raise ArgumentError, "get() redirects too deep" if limit < 1

  raise EditUrlError, "shouldn't be trying to edit... #{url}" if url =~ /[?&]action=edit\b/

  response = Net::HTTP.get_response(URI(url))
  case response
  when Net::HTTPSuccess     then response.body
  when Net::HTTPRedirection then get(response["location"], limit - 1)
  else                           response.error!
  end
end