class BanksApi::Ynab::Sync

Attributes

bank_account_id[R]
bank_name[R]
credentials[R]
date_from[R]
date_to[R]
ynab_account_id[R]
ynab_budget_id[R]

Public Class Methods

new(ynab_budget_id:, ynab_account_id:, bank_name:, credentials:, bank_account_id:, date_from:, date_to:) click to toggle source
# File lib/banks_api/ynab/sync.rb, line 10
def initialize(ynab_budget_id:, ynab_account_id:, bank_name:, credentials:, bank_account_id:, date_from:, date_to:)
  @ynab_budget_id = ynab_budget_id
  @ynab_account_id = ynab_account_id
  @bank_name = bank_name
  @credentials = credentials
  @bank_account_id = bank_account_id
  @date_from = date_from
  @date_to = date_to
end
run(*args) click to toggle source
# File lib/banks_api/ynab/sync.rb, line 6
def self.run(*args)
  new(*args).run
end

Public Instance Methods

run() click to toggle source
# File lib/banks_api/ynab/sync.rb, line 20
def run
  ynab_api.transactions.bulk_create_transactions(ynab_budget_id, bulk_transactions)
end

Private Instance Methods

bank_account() click to toggle source
# File lib/banks_api/ynab/sync.rb, line 36
def bank_account
  @_bank_account ||= user_account.account(bank_account_id)
end
banks_api_transactions() click to toggle source
# File lib/banks_api/ynab/sync.rb, line 32
def banks_api_transactions
  bank_account.transactions(from: date_from, to: date_to)
end
bulk_transactions() click to toggle source
# File lib/banks_api/ynab/sync.rb, line 28
def bulk_transactions
  BanksApi::Ynab::BulkTransactions.new(banks_api_transactions, account_id: ynab_account_id)
end
user_account() click to toggle source
# File lib/banks_api/ynab/sync.rb, line 40
def user_account
  @_user_account ||= BanksApi::UserAccount.new(bank_name, credentials)
end
ynab_api() click to toggle source
# File lib/banks_api/ynab/sync.rb, line 44
def ynab_api
  @_ynab_api ||= YNAB::API.new(ENV["YNAB_API_TOKEN"])
end