aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource/lib/active_resource
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2006-08-31 09:31:11 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2006-08-31 09:31:11 +0000
commitf9b369487046020bcdb92a3985270c9fb9943382 (patch)
tree0c51bb258ba729abc0cb4d15908b393c80372c82 /activeresource/lib/active_resource
parentc1af2db14be7a5978ee57e6b46f02e1ec8bc14f9 (diff)
downloadrails-f9b369487046020bcdb92a3985270c9fb9943382.tar.gz
rails-f9b369487046020bcdb92a3985270c9fb9943382.tar.bz2
rails-f9b369487046020bcdb92a3985270c9fb9943382.zip
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
Diffstat (limited to 'activeresource/lib/active_resource')
-rw-r--r--activeresource/lib/active_resource/connection.rb32
1 files changed, 17 insertions, 15 deletions
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