Class: MFYNAB::YnabTransactionImporter

Inherits:
Object
  • Object
show all
Defined in:
lib/mfynab/ynab_transaction_importer.rb

Constant Summary collapse

MEMO_MAX_LENGTH =
500
PAYEE_MAX_LENGTH =
200
IMPORT_ID_MAX_LENGTH =
36

Instance Method Summary collapse

Constructor Details

#initialize(api_key, budget_name, account_mappings, logger:) ⇒ YnabTransactionImporter

Returns a new instance of YnabTransactionImporter.



12
13
14
15
16
17
# File 'lib/mfynab/ynab_transaction_importer.rb', line 12

def initialize(api_key, budget_name, , logger:)
  @api_key = api_key
  @budget_name = budget_name
  @account_mappings = 
  @logger = logger
end

Instance Method Details

#run(mf_transactions) ⇒ Object

rubocop:disable Metrics/AbcSize



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/mfynab/ynab_transaction_importer.rb', line 19

def run(mf_transactions) # rubocop:disable Metrics/AbcSize
  mf_transactions.map do |, |
     = ()
    next unless 

    transactions = .map do |row|
      convert_mf_transaction(row, )
    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