Class: BankScrap::Ing
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
Instance Attribute Summary
Attributes inherited from Bank
Instance Method Summary collapse
- #balances ⇒ Object
- #fetch_accounts ⇒ Object
- #fetch_transactions_for(account, start_date: Date.today - 1.month, end_date: Date.today) ⇒ Object
-
#initialize(user, password, log: false, debug: false, extra_args:) ⇒ Ing
constructor
A new instance of Ing.
Methods inherited from Bank
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 |
# 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 bundled_login super end |
Instance Method Details
#balances ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/bank_scrap/banks/ing.rb', line 31 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
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/bank_scrap/banks/ing.rb', line 44 def fetch_accounts log 'fetch_accounts' set_headers( 'Accept' => '*/*', 'Content-Type' => 'application/json; charset=utf-8' ) @raw_accounts_data = JSON.parse(get(PRODUCTS_ENDPOINT)) @raw_accounts_data.map do |account| build_account(account) if account['iban'] end.compact end |
#fetch_transactions_for(account, start_date: Date.today - 1.month, end_date: Date.today) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/bank_scrap/banks/ing.rb', line 58 def fetch_transactions_for(account, start_date: Date.today - 1.month, end_date: Date.today) log "fetch_transactions for #{account.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}/#{account.id}/movements", 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 |