mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-02 20:15:22 +02:00
Only fetch needed Plaid products, improve Plaid tests and mocks
This commit is contained in:
parent
03a146222d
commit
6935ffa3d1
5 changed files with 188 additions and 246 deletions
|
@ -62,18 +62,32 @@ class PlaidItem::AccountsSnapshot
|
|||
)
|
||||
end
|
||||
|
||||
def can_fetch_transactions?
|
||||
plaid_item.supports_product?("transactions") && accounts.any?
|
||||
end
|
||||
|
||||
def transactions_data
|
||||
return nil unless plaid_item.supports_product?("transactions")
|
||||
return nil unless can_fetch_transactions?
|
||||
@transactions_data ||= plaid_provider.get_transactions(plaid_item.access_token)
|
||||
end
|
||||
|
||||
def can_fetch_investments?
|
||||
plaid_item.supports_product?("investments") &&
|
||||
accounts.any? { |a| a.type == "investment" }
|
||||
end
|
||||
|
||||
def investments_data
|
||||
return nil unless plaid_item.supports_product?("investments")
|
||||
return nil unless can_fetch_investments?
|
||||
@investments_data ||= plaid_provider.get_item_investments(plaid_item.access_token)
|
||||
end
|
||||
|
||||
def can_fetch_liabilities?
|
||||
plaid_item.supports_product?("liabilities") &&
|
||||
accounts.any? { |a| [ "credit", "loan" ].include?(a.type) }
|
||||
end
|
||||
|
||||
def liabilities_data
|
||||
return nil unless plaid_item.supports_product?("liabilities")
|
||||
return nil unless can_fetch_liabilities?
|
||||
@liabilities_data ||= plaid_provider.get_item_liabilities(plaid_item.access_token)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue