Class: BankScrap::Ing
- Inherits:
-
Bank
- Object
- Bank
- BankScrap::Ing
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 = .with_indifferent_access['birthday']
@log = log
@debug = debug
initialize_connection
bundled_login
@investments = fetch_investments
super
end
|
Instance Method Details
#balances ⇒ Object
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 |account|
balances[account.description] = account.balance
total_balance += account.balance
end
balances['TOTAL'] = total_balance
balances
end
|
#fetch_accounts ⇒ Object
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'
(
'Accept' => '*/*',
'Content-Type' => 'application/json; charset=utf-8'
)
JSON.parse(get(PRODUCTS_ENDPOINT)).map do |account|
build_account(account) if account['iban']
end.compact
end
|
#fetch_investments ⇒ Object
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'
(
'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(account, start_date: Date.today - 1.month, end_date: Date.today)
log "fetch_transactions for #{account.id}"
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}/#{account.id}/movements", params: params)
json = JSON.parse(request)
transactions += (json['elements'] || []).map do |transaction|
build_transaction(transaction, account)
end
params[:offset] += 25
break if (params[:offset] > json['total']) || json['elements'].blank?
end
transactions
end
|