Class: MFYNAB::YnabTransactionImporter
- Inherits:
-
Object
- Object
- MFYNAB::YnabTransactionImporter
- Defined in:
- lib/mfynab/ynab_transaction_importer.rb
Instance Method Summary collapse
-
#initialize(api_key, budget_name, account_mappings, logger:) ⇒ YnabTransactionImporter
constructor
A new instance of YnabTransactionImporter.
-
#run(mf_transactions) ⇒ Object
rubocop:disable Metrics/AbcSize.
Constructor Details
#initialize(api_key, budget_name, account_mappings, logger:) ⇒ YnabTransactionImporter
Returns a new instance of YnabTransactionImporter.
7 8 9 10 11 12 |
# File 'lib/mfynab/ynab_transaction_importer.rb', line 7 def initialize(api_key, budget_name, account_mappings, logger:) @api_key = api_key @budget_name = budget_name @account_mappings = account_mappings @logger = logger end |
Instance Method Details
#run(mf_transactions) ⇒ Object
rubocop:disable Metrics/AbcSize
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/mfynab/ynab_transaction_importer.rb', line 14 def run(mf_transactions) # rubocop:disable Metrics/AbcSize mf_transactions.map do |mf_account, mf_account_transactions| account = ynab_account_for_mf_account(mf_account) next unless account transactions = mf_account_transactions.map do |row| convert_mf_transaction(row, account) end begin logger.info("Importing #{transactions.size} transactions for #{account.name}") result = ynab_transactions_api.create_transaction(budget.id, transactions: transactions) logger.info( "Imported #{result.data.transactions.size} transactions " \ "for #{account.name} " \ "(#{result.data.duplicate_import_ids.size} duplicates)", ) rescue StandardError => e logger.error("Error importing transactions for #{budget.name}. #{e} : #{e.detail}") end end end |