Class: BankScrap::Ing

Inherits:
Bank
  • Object
show all
Defined in:
lib/bank_scrap/banks/ing.rb

Constant Summary collapse

BASE_ENDPOINT =
'https://ing.ingdirect.es/'
LOGIN_ENDPOINT =
BASE_ENDPOINT + 'genoma_login/rest/session'
POST_AUTH_ENDPOINT =
BASE_ENDPOINT + 'genoma_api/login/auth/response'
CLIENT_ENDPOINT =
BASE_ENDPOINT + 'genoma_api/rest/client'
PRODUCTS_ENDPOINT =
BASE_ENDPOINT + 'genoma_api/rest/products'
SAMPLE_WIDTH =
30
SAMPLE_HEIGHT =
30
SAMPLE_ROOT_PATH =
'/ing/numbers'

Constants inherited from Bank

Bank::WEB_USER_AGENT

Instance Attribute Summary

Attributes inherited from Bank

#accounts, #headers, #investments

Instance Method Summary collapse

Methods inherited from Bank

#account_with_iban

Constructor Details

#initialize(user, password, log: false, debug: false, extra_args:) ⇒ Ing

Returns a new instance of Ing.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/bank_scrap/banks/ing.rb', line 18

def initialize(user, password, log: false, debug: false, extra_args:)
  @dni      = user
  @password = password.to_s
  @birthday = extra_args.with_indifferent_access['birthday']
  @log      = log
  @debug    = debug

  initialize_connection
  

  @investments = fetch_investments

  super
end

Instance Method Details

#balancesObject



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/bank_scrap/banks/ing.rb', line 33

def balances
  log 'get_balances'
  balances = {}
  total_balance = 0
  @accounts.each do ||
    balances[.description] = .balance
    total_balance += .balance
  end

  balances['TOTAL'] = total_balance
  balances
end

#fetch_accountsObject



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/bank_scrap/banks/ing.rb', line 46

def fetch_accounts
  log 'fetch_accounts'
  add_headers(
    'Accept'       => '*/*',
    'Content-Type' => 'application/json; charset=utf-8'
  )

  JSON.parse(get(PRODUCTS_ENDPOINT)).map do ||
    () if ['iban']
  end.compact
end

#fetch_investmentsObject



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/bank_scrap/banks/ing.rb', line 58

def fetch_investments
  log 'fetch_investments'
  add_headers(
    'Accept'       => '*/*',
    'Content-Type' => 'application/json; charset=utf-8'
  )

  JSON.parse(get(PRODUCTS_ENDPOINT)).map do |investment|
    build_investment(investment) if investment['investment']
  end.compact
end

#fetch_transactions_for(account, start_date: Date.today - 1.month, end_date: Date.today) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/bank_scrap/banks/ing.rb', line 70

def fetch_transactions_for(, start_date: Date.today - 1.month, end_date: Date.today)
  log "fetch_transactions for #{.id}"

  # The API allows any limit to be passed, but we better keep
  # being good API citizens and make a loop with a short limit
  params = {
    fromDate: start_date.strftime('%d/%m/%Y'),
    toDate: end_date.strftime('%d/%m/%Y'),
    limit: 25,
    offset: 0
  }

  transactions = []
  loop do
    request = get("#{PRODUCTS_ENDPOINT}/#{.id}/movements", params: params)
    json = JSON.parse(request)
    transactions += (json['elements'] || []).map do |transaction|
      build_transaction(transaction, )
    end
    params[:offset] += 25
    break if (params[:offset] > json['total']) || json['elements'].blank?
  end
  transactions
end