class Myfinance::Resources::FinancialAccount
Public Class Methods
# File lib/myfinance/resources/financial_account.rb, line 5 def initialize(http) @http = http set_method_for(pay_or_receive_method) set_method_for(undo_payment_or_receivement) end
Public Instance Methods
Creates a payable/receivable account
- API
-
Method:
POST /entities/:entity_id/payable_accounts
Method:POST /entities/:entity_id/receivable_accounts
Documentation: app.myfinance.com.br/docs/api/payable_accounts#post_create Documentation: app.myfinance.com.br/docs/api/receivable_accounts#post_create
# File lib/myfinance/resources/financial_account.rb, line 29 def create(entity_id, params = {}) request_and_build_object_response(:post, endpoint_for(nil, entity_id, :create), params) end
Destroys a payable/receivable account
- API
-
Method:
DELETE /entities/:entity_id/payable_accounts/:id
Method:DELETE /entities/:entity_id/receivable_accounts/:id
Documentation: app.myfinance.com.br/docs/api/payable_accounts#delete_destroy Documentation: app.myfinance.com.br/docs/api/receivable_accounts#delete_destroy
# File lib/myfinance/resources/financial_account.rb, line 57 def destroy(entity_id, id) http.delete(endpoint_for(id, entity_id, :destroy)) do |_response| true end end
# File lib/myfinance/resources/financial_account.rb, line 69 def destroy_many(entity_id, ids) http.delete(destroy_many_endpoint(ids, entity_id)) do |_response| true end end
# File lib/myfinance/resources/financial_account.rb, line 63 def destroy_recurrence(entity_id, id) http.delete(endpoint_for(id, entity_id, :destroy_recurrence)) do |_response| true end end
# File lib/myfinance/resources/financial_account.rb, line 15 def find(entity_id, id) request_and_build_object_response(:get, endpoint_for(id, entity_id, :show)) end
# File lib/myfinance/resources/financial_account.rb, line 11 def find_all(entity_id, page = nil) request_and_build_collection_response(:get, index_endpoint(entity_id, page)) end
Updates a payable/receivable account
- API
-
Method:
PUT /entities/:entity_id/payable_accounts/:id
Method:PUT /entities/:entity_id/receivable_accounts/:id
Documentation: app.myfinance.com.br/docs/api/payable_accounts#put_update Documentation: app.myfinance.com.br/docs/api/receivable_accounts#put_update
# File lib/myfinance/resources/financial_account.rb, line 43 def update(entity_id, id, params = {}) request_and_build_object_response(:put, endpoint_for(id, entity_id, :update), params) end
Private Instance Methods
# File lib/myfinance/resources/financial_account.rb, line 100 def default_endpoints { index: "/entities/:entity_id/#{resource_key}s", show: "/entities/:entity_id/#{resource_key}s/:id", create: "/entities/:entity_id/#{resource_key}s", update: "/entities/:entity_id/#{resource_key}s/:id", destroy: "/entities/:entity_id/#{resource_key}s/:id", destroy_recurrence: "/entities/:entity_id/#{resource_key}s/:id/recurrence" } end
# File lib/myfinance/resources/financial_account.rb, line 121 def destroy_many_endpoint(ids, entity_id) "/entities/#{entity_id}/#{resource_key}s?selected_ids=#{ids.join(',')}" end
# File lib/myfinance/resources/financial_account.rb, line 96 def endpoint_for(id, entity_id, key) parameterize_endpoint(id, entity_id, key) end
# File lib/myfinance/resources/financial_account.rb, line 89 def index_endpoint(entity_id, page) index_path = parameterize_endpoint(nil, entity_id, :index) return index_path unless page index_path + "?page=#{page}" end
# File lib/myfinance/resources/financial_account.rb, line 111 def parameterize_endpoint(id, entity_id, key) endpoints[key.to_sym].gsub(':entity_id', entity_id.to_s).gsub(':id', id.to_s) end
# File lib/myfinance/resources/financial_account.rb, line 83 def request_and_build_collection_response(method, endpoint) http.send(method, endpoint, body: {}) do |response| respond_with_collection(response) end end
# File lib/myfinance/resources/financial_account.rb, line 77 def request_and_build_object_response(method, endpoint, params = {}) http.send(method, endpoint, body: { resource_key => params }) do |response| respond_with_object(response, resource_key) end end
# File lib/myfinance/resources/financial_account.rb, line 115 def set_method_for(action) self.class.send(:define_method, action) do |id, entity_id, params={}| request_and_build_object_response(:put, endpoint_for(id, entity_id, action), params) end end