From f9b369487046020bcdb92a3985270c9fb9943382 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 31 Aug 2006 09:31:11 +0000 Subject: 200...400 are valid response codes. PUT and POST request bodies default to ''. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4887 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activeresource/lib/active_resource/connection.rb | 32 +++++++++++++----------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'activeresource/lib/active_resource') diff --git a/activeresource/lib/active_resource/connection.rb b/activeresource/lib/active_resource/connection.rb index 7318e7256f..cc98645fdc 100644 --- a/activeresource/lib/active_resource/connection.rb +++ b/activeresource/lib/active_resource/connection.rb @@ -11,24 +11,24 @@ module ActiveResource @response = response @message = message end - + def to_s "Failed with #{response.code}" end end - + class ClientError < ConnectionError end class ServerError < ConnectionError end - + class ResourceNotFound < ClientError end class Connection - attr_accessor :uri - + attr_accessor :site + class << self def requests @@requests ||= [] @@ -38,29 +38,31 @@ module ActiveResource def initialize(site) @site = site end - + def get(path) Hash.create_from_xml(request(:get, path).body) end - + def delete(path) request(:delete, path) end - - def put(path, body) + + def put(path, body = '') request(:put, path, body) end - def post(path, body) + def post(path, body = '') request(:post, path, body) end - + private def request(method, *arguments) - response = http.send(method, *arguments) + handle_response(http.send(method, *arguments)) + end + def handle_response(response) case response.code.to_i - when 200...300 + when 200...400 response when 404 raise(ResourceNotFound.new(response)) @@ -79,8 +81,8 @@ module ActiveResource @http.use_ssl = @site.is_a?(URI::HTTPS) @http.verify_mode = OpenSSL::SSL::VERIFY_NONE if @http.use_ssl end - + @http end end -end \ No newline at end of file +end -- cgit v1.2.3