Permalink
Browse files

Let users access the last active resource response object

  • Loading branch information...
1 parent 43a72a2 commit ad7fa51841bc5278bf99281785f4bc0edf6ed3f6 @anibalcucco committed Aug 23, 2012
Showing with 25 additions and 0 deletions.
  1. +7 −0 README.rdoc
  2. +1 −0 lib/basecamp.rb
  3. +17 −0 lib/basecamp/active_resource.rb
View
7 README.rdoc
@@ -196,6 +196,13 @@ By default the wrapper will use :xml for the active record connection but you ca
Note: We recommend using xml. There are some API calls that don't behave well with json.
+= Access active resource response object
+
+You can acces the last response object:
+
+ Basecamp::Message.find(:all, params => { :project_id => 1037 })
+ Basecamp::Message.connection.response["status"] # => "200 OK"
+
== Contributors
* jamesarosen
View
1 lib/basecamp.rb
@@ -7,6 +7,7 @@
require 'basecamp/base'
require 'basecamp/connection'
+require 'basecamp/active_resource'
require 'basecamp/hash'
require 'basecamp/record'
require 'basecamp/resource'
View
17 lib/basecamp/active_resource.rb
@@ -0,0 +1,17 @@
+# ActiveResource connection patch to let users access the last response object and the headers.
+#
+# Example:
+# >> Basecamp::Message.find(:all, params => { :project_id => 1037 })
+# >> Basecamp::Message.connection.response["status"]
+# => "200 OK"
+class ActiveResource::Connection
+ alias_method :original_handle_response, :handle_response
+ def handle_response(response)
+ Thread.current[:active_resource_connection_headers] = response
+ original_handle_response(response)
+ end
+
+ def response
+ Thread.current[:active_resource_connection_headers]
+ end
+end

0 comments on commit ad7fa51

Please sign in to comment.