Changeset 6625
- Timestamp:
- 04/29/07 04:46:14 (2 years ago)
- Files:
-
- trunk/activeresource/CHANGELOG (modified) (1 diff)
- trunk/activeresource/lib/active_resource/base.rb (modified) (6 diffs)
- trunk/activeresource/lib/active_resource/custom_methods.rb (modified) (3 diffs)
- trunk/activeresource/test/base_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activeresource/CHANGELOG
r6624 r6625 4 4 5 5 class Project 6 custom_headers['X-Token'] = 'foo'6 headers['X-Token'] = 'foo' 7 7 end 8 8 trunk/activeresource/lib/active_resource/base.rb
r6624 r6625 30 30 end 31 31 32 def custom_headers33 @ custom_headers ||= {}32 def headers 33 @headers ||= {} 34 34 end 35 35 … … 155 155 from ||= collection_path(prefix_options, query_options) 156 156 157 instantiate_collection(connection.get(from, custom_headers) || [])157 instantiate_collection(connection.get(from, headers) || []) 158 158 end 159 159 … … 172 172 from = scope.to_s.include?("/") ? scope : element_path(scope, prefix_options, query_options) 173 173 174 returning new(connection.get(from, custom_headers)) do |resource|174 returning new(connection.get(from, headers)) do |resource| 175 175 resource.prefix_options = prefix_options 176 176 end … … 259 259 # Delete the resource. 260 260 def destroy 261 connection.delete(element_path, self.class. custom_headers)261 connection.delete(element_path, self.class.headers) 262 262 end 263 263 … … 305 305 # Update the resource on the remote service. 306 306 def update 307 returning connection.put(element_path(prefix_options), to_xml, self.class. custom_headers) do |response|307 returning connection.put(element_path(prefix_options), to_xml, self.class.headers) do |response| 308 308 load_attributes_from_response(response) 309 309 end … … 312 312 # Create (i.e., save to the remote service) the new resource. 313 313 def create 314 returning connection.post(collection_path, to_xml, self.class. custom_headers) do |response|314 returning connection.post(collection_path, to_xml, self.class.headers) do |response| 315 315 self.id = id_from_response(response) 316 316 load_attributes_from_response(response) trunk/activeresource/lib/active_resource/custom_methods.rb
r6624 r6625 37 37 38 38 def get(method_name, options = {}) 39 connection.get(custom_method_collection_url(method_name, options), custom_headers)39 connection.get(custom_method_collection_url(method_name, options), headers) 40 40 end 41 41 42 42 def post(method_name, options = {}, body = nil) 43 connection.post(custom_method_collection_url(method_name, options), body, custom_headers)43 connection.post(custom_method_collection_url(method_name, options), body, headers) 44 44 end 45 45 46 46 def put(method_name, options = {}, body = nil) 47 connection.put(custom_method_collection_url(method_name, options), body, custom_headers)47 connection.put(custom_method_collection_url(method_name, options), body, headers) 48 48 end 49 49 … … 51 51 def delete(custom_method_name, options = {}) 52 52 if (custom_method_name.is_a?(Symbol)) 53 connection.delete(custom_method_collection_url(custom_method_name, options), custom_headers)53 connection.delete(custom_method_collection_url(custom_method_name, options), headers) 54 54 else 55 55 orig_delete(custom_method_name, options) … … 72 72 module InstanceMethods 73 73 def get(method_name, options = {}) 74 connection.get(custom_method_element_url(method_name, options), self.class. custom_headers)74 connection.get(custom_method_element_url(method_name, options), self.class.headers) 75 75 end 76 76 77 77 def post(method_name, options = {}, body = nil) 78 78 if new? 79 connection.post(custom_method_new_element_url(method_name, options), (body.nil? ? to_xml : body), self.class. custom_headers)79 connection.post(custom_method_new_element_url(method_name, options), (body.nil? ? to_xml : body), self.class.headers) 80 80 else 81 connection.post(custom_method_element_url(method_name, options), body, self.class. custom_headers)81 connection.post(custom_method_element_url(method_name, options), body, self.class.headers) 82 82 end 83 83 end 84 84 85 85 def put(method_name, options = {}, body = nil) 86 connection.put(custom_method_element_url(method_name, options), body, self.class. custom_headers)86 connection.put(custom_method_element_url(method_name, options), body, self.class.headers) 87 87 end 88 88 89 89 def delete(method_name, options = {}) 90 connection.delete(custom_method_element_url(method_name, options), self.class. custom_headers)90 connection.delete(custom_method_element_url(method_name, options), self.class.headers) 91 91 end 92 92 trunk/activeresource/test/base_test.rb
r6624 r6625 201 201 202 202 def test_custom_header 203 Person. custom_headers['key'] = 'value'203 Person.headers['key'] = 'value' 204 204 assert_raises(ActiveResource::ResourceNotFound) { Person.find(3) } 205 205 ensure 206 Person. custom_headers.delete('key')206 Person.headers.delete('key') 207 207 end 208 208