Class: ZohoInvoiceResource::Base
- Inherits:
-
ActiveResource::Base
- Object
- ActiveResource::Base
- ZohoInvoiceResource::Base
- Includes:
- ActiveRecord::AttributeAssignment, UnderscoreKeys
- Defined in:
- lib/zoho_invoice_resource/base.rb
Class Method Summary collapse
-
.cached_resource(options = {}) ⇒ Object
For CachedResource.
- .collection_path(prefix_options = {}, query_options = {}) ⇒ Object
- .connection(refresh = false) ⇒ Object
- .element_path(id, prefix_options = {}, query_options = {}) ⇒ Object
- .find_all_recursively(options = {}) ⇒ Object
- .format ⇒ Object
Instance Method Summary collapse
- #create_resource_for(resource_name) ⇒ Object
- #encode(options = {}) ⇒ Object
- #update ⇒ Object
- #update_element_path(options = nil) ⇒ Object
Methods included from UnderscoreKeys
Class Method Details
.cached_resource(options = {}) ⇒ Object
For CachedResource
40 41 42 43 44 45 46 47 48 |
# File 'lib/zoho_invoice_resource/base.rb', line 40 def cached_resource(={}) if defined?(::CachedResource::Model) && self.include?(::CachedResource::Model) super.tap do include CachedResourcePatch end else super end end |
.collection_path(prefix_options = {}, query_options = {}) ⇒ Object
19 20 21 22 |
# File 'lib/zoho_invoice_resource/base.rb', line 19 def collection_path( = {}, = {}) .merge!(auth_params) super(, ) end |
.connection(refresh = false) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/zoho_invoice_resource/base.rb', line 75 def self.connection(refresh = false) @connection = Connection.new(site, format) if refresh || @connection.nil? @connection.tap do |c| c.proxy = proxy if proxy c.user = user if user c.password = password if password c.auth_type = auth_type if auth_type c.timeout = timeout if timeout c. = if end end |
.element_path(id, prefix_options = {}, query_options = {}) ⇒ Object
14 15 16 17 |
# File 'lib/zoho_invoice_resource/base.rb', line 14 def element_path(id, = {}, = {}) .merge!(auth_params) super(id, , ) end |
.find_all_recursively(options = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/zoho_invoice_resource/base.rb', line 24 def find_all_recursively( = {}) collection = find(:all, .merge(params: {'Per_Page' => 500})) while collection.page && (collection.page < collection.total_pages) next_collection = find(:all, params: {'Page' => collection.page + 1, 'Per_Page' => 500}) collection.merge!(next_collection) end collection rescue ActiveResource::ResourceNotFound nil end |
Instance Method Details
#create_resource_for(resource_name) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/zoho_invoice_resource/base.rb', line 68 def create_resource_for(resource_name) super.tap do |resource| resource.send(:include, UnderscoreKeys) resource.send(:include, ActiveRecord::AttributeAssignment) end end |
#encode(options = {}) ⇒ Object
63 64 65 66 |
# File 'lib/zoho_invoice_resource/base.rb', line 63 def encode(={}) xml = self.class.format.encode(self, {:root => self.class.element_name}.merge()) URI.encode_www_form(self.class.auth_params.merge('XMLString' => xml)) end |
#update ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/zoho_invoice_resource/base.rb', line 51 def update run_callbacks :update do connection.post(self.class.custom_method_collection_url(:update, ), encode, self.class.headers).tap do |response| load_attributes_from_response(response) end end end |
#update_element_path(options = nil) ⇒ Object
59 60 61 |
# File 'lib/zoho_invoice_resource/base.rb', line 59 def update_element_path( = nil) self.class.element_path(to_param, || ) end |