aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource/lib
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2006-12-05 19:12:51 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2006-12-05 19:12:51 +0000
commit7370e54cc4d6b298a29383bf943b277bcfb730aa (patch)
tree5585190cfb324c1dbfcdebf69e431cc901e45960 /activeresource/lib
parent0ee0c1b2aae3cb90869c79235470e6b69296feeb (diff)
downloadrails-7370e54cc4d6b298a29383bf943b277bcfb730aa.tar.gz
rails-7370e54cc4d6b298a29383bf943b277bcfb730aa.tar.bz2
rails-7370e54cc4d6b298a29383bf943b277bcfb730aa.zip
*_path instance methods. Check for missing/invalid site uri. http_mock response takes message arg, extracts numeric code. Tests log to test/debug.log
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5680 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activeresource/lib')
-rw-r--r--activeresource/lib/active_resource/base.rb14
-rw-r--r--activeresource/lib/active_resource/connection.rb7
2 files changed, 15 insertions, 6 deletions
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb
index 5d72d98be6..07933d499b 100644
--- a/activeresource/lib/active_resource/base.rb
+++ b/activeresource/lib/active_resource/base.rb
@@ -106,7 +106,7 @@ module ActiveResource
end
def destroy
- connection.delete(self.class.element_path(id, prefix_options))
+ connection.delete(element_path)
end
def to_xml(options={})
@@ -155,12 +155,12 @@ module ActiveResource
end
def update
- connection.put(self.class.element_path(id, prefix_options), to_xml)
+ connection.put(element_path, to_xml)
true
end
def create
- resp = connection.post(self.class.collection_path(prefix_options), to_xml)
+ resp = connection.post(collection_path, to_xml)
self.id = id_from_response(resp)
true
end
@@ -170,6 +170,14 @@ module ActiveResource
response['Location'][/\/([^\/]*?)(\.\w+)?$/, 1]
end
+ def element_path(options = nil)
+ self.class.element_path(id, options || prefix_options)
+ end
+
+ def collection_path(options = nil)
+ self.class.collection_path(options || prefix_options)
+ end
+
private
def find_or_create_resource_for_collection(name)
find_or_create_resource_for(name.to_s.singularize)
diff --git a/activeresource/lib/active_resource/connection.rb b/activeresource/lib/active_resource/connection.rb
index 1a1b376d3a..e4f733cf70 100644
--- a/activeresource/lib/active_resource/connection.rb
+++ b/activeresource/lib/active_resource/connection.rb
@@ -40,9 +40,10 @@ module ActiveResource
end
def initialize(site)
- self.site = site.is_a?(URI) ? site : URI.parse(site)
+ raise ArgumentError, 'Missing site URI' unless site
+ self.site = site
end
-
+
def site=(site)
@site = site.is_a?(URI) ? site : URI.parse(site)
end
@@ -65,7 +66,7 @@ module ActiveResource
private
def request(method, path, *arguments)
- logger.info "requesting #{method.to_s.upcase} #{site.scheme}://#{site.host}:#{site.port}#{path}" if logger
+ logger.info "#{method.to_s.upcase} #{site.scheme}://#{site.host}:#{site.port}#{path}" if logger
result = nil
time = Benchmark.realtime { result = http.send(method, path, *arguments) }
logger.info "--> #{result.code} #{result.message} (#{result.body.length}b %.2fs)" % time if logger