Class: OAuthActiveResource::UniqueResourceArray

Inherits:
UniqueArray
  • Object
show all
Defined in:
lib/oauth_active_resource/unique_resource_array.rb

Overview

see has_many in Resource

Instance Method Summary collapse

Methods inherited from UniqueArray

#<<, #[]=, #insert

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,options = {})   
  super()   
  
  @connection = connection
  @collection_path = collection_path
  @resource = resource
  @options = options
  reload
end

Instance Method Details

#reloadObject



81
82
83
84
# File 'lib/oauth_active_resource/unique_resource_array.rb', line 81

def reload
  self.replace(@resource.find(:all, :from => @collection_path, :params => @options))
  return self
end

#saveObject

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



76
77
78
79
# File 'lib/oauth_active_resource/unique_resource_array.rb', line 76

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_jsonObject



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_xmlObject



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