Class: OAuthActiveResource::UniqueResourceArray
- Inherits:
-
UniqueArray
- Object
- Array
- UniqueArray
- OAuthActiveResource::UniqueResourceArray
- Defined in:
- lib/oauth_active_resource/unique_resource_array.rb
Overview
see has_many in Resource
Instance Method Summary collapse
-
#initialize(connection, resource, collection_path, options = {}) ⇒ UniqueResourceArray
constructor
A new instance of UniqueResourceArray.
- #reload ⇒ Object
-
#save ⇒ Object
DEPRECATED…
- #to_json ⇒ Object
- #to_xml ⇒ Object
Methods inherited from UniqueArray
Constructor Details
#initialize(connection, resource, collection_path, options = {}) ⇒ UniqueResourceArray
Returns a new instance of UniqueResourceArray.
41 42 43 44 45 46 47 48 49 |
# File 'lib/oauth_active_resource/unique_resource_array.rb', line 41 def initialize(connection, resource, collection_path, = {}) super() @connection = connection @collection_path = collection_path @resource = resource @options = reload end |
Instance Method Details
#reload ⇒ Object
80 81 82 83 |
# File 'lib/oauth_active_resource/unique_resource_array.rb', line 80 def reload self.replace(@resource.find(:all, :from => @collection_path, :params => @options)) return self end |
#save ⇒ Object
DEPRECATED… def find(look_for)
if not (look_for.is_a? String or look_for.is_a? Integer)
look_for_id = look_for
else
look_for_id = look_for.id
end
self.each do |obj|
obj.id == look_for_id and return obj
end
return nil
end
75 76 77 78 |
# File 'lib/oauth_active_resource/unique_resource_array.rb', line 75 def save response = @connection.handle_response( @connection.put("#{@collection_path}",self.to_xml) ) self.replace( @resource.load_collection( @connection.format.decode(response.body) ) ) end |
#to_json ⇒ Object
51 52 53 |
# File 'lib/oauth_active_resource/unique_resource_array.rb', line 51 def to_json return "[ #{self.map { |obj| obj.to_json }.join(',')} ]" end |
#to_xml ⇒ Object
55 56 57 58 59 |
# File 'lib/oauth_active_resource/unique_resource_array.rb', line 55 def to_xml # or use __method__ here? pt = @resource.element_name.pluralize return "<#{pt}> #{self.map { |obj| obj.to_xml({:skip_instruct => true})}.join(' ')} </#{pt}>" end |