Class: ActiveResource::Base
- Inherits:
-
Object
- Object
- ActiveResource::Base
- Defined in:
- lib/patches/ar2/base.rb,
lib/patches/ar3/base.rb
Overview
Overridden methods to suit SalesKing. Some changes might be kicked when AR 3.0 is out
Direct Known Subclasses
Class Method Summary collapse
-
.instantiate_collection(collection, prefix_options = {}) ⇒ Object
Overridden to grab the data(= clients-collection) from json: { ‘collection’=> will_paginate infos, ‘links’ => prev/next links ‘clients’=> [data], << what we need }.
Instance Method Summary collapse
-
#encode(options = {}) ⇒ Object
override encode because json is also returned nested by SalesKing.
-
#load_attributes_from_response(response) ⇒ Object
override ARes method to parse only the client part.
Class Method Details
.instantiate_collection(collection, prefix_options = {}) ⇒ Object
Overridden to grab the data(= clients-collection) from json: { ‘collection’=> will_paginate infos,
'links' => prev/next links
'clients'=> [data], << what we need
}
37 38 39 40 |
# File 'lib/patches/ar2/base.rb', line 37 def self.instantiate_collection(collection, = {}) collection = collection[ self.element_name.pluralize ] if collection.is_a?(Hash) collection.collect! { |record| instantiate_record(record, ) } end |
Instance Method Details
#encode(options = {}) ⇒ Object
override encode because json is also returned nested by SalesKing
14 15 16 17 18 19 20 21 |
# File 'lib/patches/ar2/base.rb', line 14 def encode(={}) case self.class.format when ActiveResource::Formats[:xml] self.class.format.encode(attributes, {:root => self.class.element_name}.merge()) else # json also nested self.class.format.encode( {self.class.element_name => attributes}, ) end end |
#load_attributes_from_response(response) ⇒ Object
override ARes method to parse only the client part
24 25 26 27 28 29 30 |
# File 'lib/patches/ar2/base.rb', line 24 def load_attributes_from_response(response) if (response['Transfer-Encoding'] == 'chunked' || (!response['Content-Length'].blank? && response['Content-Length'] != "0")) && !response.body.nil? && response.body.strip.size > 0 load( self.class.format.decode(response.body)[self.class.element_name] ) end end |