Permalink
Browse files

change #custom_headers to just #headers [Rick]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6625 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
technoweenie committed Apr 29, 2007
1 parent bd50d82 commit 8e8fd99d7f88f35f67d46d43eea693a67e61d7ec
View
@@ -3,7 +3,7 @@
* Add support for setting custom headers per ActiveResource model [Rick]
class Project
- custom_headers['X-Token'] = 'foo'
+ headers['X-Token'] = 'foo'
end
# makes the GET request with the custom X-Token header
@@ -29,8 +29,8 @@ def connection(refresh = false)
@connection
end
- def custom_headers
- @custom_headers ||= {}
+ def headers
+ @headers ||= {}
end
# Do not include any modules in the default element name. This makes it easier to seclude ARes objects
@@ -154,7 +154,7 @@ def find_every(options)
prefix_options, query_options = split_options(options)
from ||= collection_path(prefix_options, query_options)
- instantiate_collection(connection.get(from, custom_headers) || [])
+ instantiate_collection(connection.get(from, headers) || [])
end
def instantiate_collection(collection, prefix_options = {})
@@ -171,7 +171,7 @@ def find_single(scope, options)
prefix_options, query_options = split_options(options)
from = scope.to_s.include?("/") ? scope : element_path(scope, prefix_options, query_options)
- returning new(connection.get(from, custom_headers)) do |resource|
+ returning new(connection.get(from, headers)) do |resource|
resource.prefix_options = prefix_options
end
end
@@ -258,7 +258,7 @@ def save
# Delete the resource.
def destroy
- connection.delete(element_path, self.class.custom_headers)
+ connection.delete(element_path, self.class.headers)
end
# Evaluates to <tt>true</tt> if this resource is found.
@@ -304,14 +304,14 @@ def connection(refresh = false)
# Update the resource on the remote service.
def update
- returning connection.put(element_path(prefix_options), to_xml, self.class.custom_headers) do |response|
+ returning connection.put(element_path(prefix_options), to_xml, self.class.headers) do |response|
load_attributes_from_response(response)
end
end
# Create (i.e., save to the remote service) the new resource.
def create
- returning connection.post(collection_path, to_xml, self.class.custom_headers) do |response|
+ returning connection.post(collection_path, to_xml, self.class.headers) do |response|
self.id = id_from_response(response)
load_attributes_from_response(response)
end
@@ -36,21 +36,21 @@ class << self
alias :orig_delete :delete
def get(method_name, options = {})
- connection.get(custom_method_collection_url(method_name, options), custom_headers)
+ connection.get(custom_method_collection_url(method_name, options), headers)
end
def post(method_name, options = {}, body = nil)
- connection.post(custom_method_collection_url(method_name, options), body, custom_headers)
+ connection.post(custom_method_collection_url(method_name, options), body, headers)
end
def put(method_name, options = {}, body = nil)
- connection.put(custom_method_collection_url(method_name, options), body, custom_headers)
+ connection.put(custom_method_collection_url(method_name, options), body, headers)
end
# Need to jump through some hoops to retain the original class 'delete' method
def delete(custom_method_name, options = {})
if (custom_method_name.is_a?(Symbol))
- connection.delete(custom_method_collection_url(custom_method_name, options), custom_headers)
+ connection.delete(custom_method_collection_url(custom_method_name, options), headers)
else
orig_delete(custom_method_name, options)
end
@@ -71,23 +71,23 @@ def custom_method_collection_url(method_name, options = {})
module InstanceMethods
def get(method_name, options = {})
- connection.get(custom_method_element_url(method_name, options), self.class.custom_headers)
+ connection.get(custom_method_element_url(method_name, options), self.class.headers)
end
def post(method_name, options = {}, body = nil)
if new?
- connection.post(custom_method_new_element_url(method_name, options), (body.nil? ? to_xml : body), self.class.custom_headers)
+ connection.post(custom_method_new_element_url(method_name, options), (body.nil? ? to_xml : body), self.class.headers)
else
- connection.post(custom_method_element_url(method_name, options), body, self.class.custom_headers)
+ connection.post(custom_method_element_url(method_name, options), body, self.class.headers)
end
end
def put(method_name, options = {}, body = nil)
- connection.put(custom_method_element_url(method_name, options), body, self.class.custom_headers)
+ connection.put(custom_method_element_url(method_name, options), body, self.class.headers)
end
def delete(method_name, options = {})
- connection.delete(custom_method_element_url(method_name, options), self.class.custom_headers)
+ connection.delete(custom_method_element_url(method_name, options), self.class.headers)
end
@@ -200,10 +200,10 @@ def test_find_first
end
def test_custom_header
- Person.custom_headers['key'] = 'value'
+ Person.headers['key'] = 'value'
assert_raises(ActiveResource::ResourceNotFound) { Person.find(3) }
ensure
- Person.custom_headers.delete('key')
+ Person.headers.delete('key')
end
def test_find_by_id_not_found

0 comments on commit 8e8fd99

Please sign in to comment.