lib/highrise/base.rb in highrise-3.0.3 vs lib/highrise/base.rb in highrise-3.0.4
- old
+ new
@@ -1,10 +1,33 @@
require 'active_resource'
module Highrise
class Base < ActiveResource::Base
protected
+
+ class << self
+ # If headers are not defined in a given subclass, then obtain
+ # headers from the superclass.
+ # http://opensoul.org/blog/archives/2010/02/16/active-resource-in-practice/
+ def headers
+ if defined?(@headers)
+ @headers
+ elsif superclass != Object && superclass.headers
+ superclass.headers
+ else
+ @headers ||= {}
+ end
+ end
+
+ def oauth_token=(token)
+ headers['Authorization'] = "Bearer #{token}"
+ end
+ end
+
+ # Fix for ActiveResource 3.1+ errors
+ self.format = :xml
+
# Dynamic finder for attributes
def self.method_missing(method, *args)
if method.to_s =~ /^find_(all_)?by_([_a-zA-Z]\w*)$/
raise ArgumentError, "Dynamic finder method must take an argument." if args.empty?
options = args.extract_options!
@@ -14,6 +37,6 @@
super
end
end
end
-end
\ No newline at end of file
+end