Class: BankScrap::Bankinter

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

Constant Summary collapse

BASE_ENDPOINT =
"https://www.bankinter.com"
LOGIN_ENDPOINT =
"/www/es-es/cgi/ebk+login"
TRANSACTIONS_ENDPOINT =
"/www/es-es/cgi/ebk+opr+buscadormov"

Constants inherited from Bank

BankScrap::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, #fetch_investments

Constructor Details

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

Returns a new instance of Bankinter.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/bank_scrap/banks/bankinter.rb', line 10

def initialize(user, password, log: false, debug: false, extra_args: nil)
  @user = user
  @password = password
  @log = log
  @debug = debug

  initialize_connection
  initialize_cookie(BASE_ENDPOINT)
  parse_html(get(BASE_ENDPOINT + '/www/es-es/cgi/ebk+gc+lgin'))
  
  super
end

Instance Method Details

#fetch_accountsObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/bank_scrap/banks/bankinter.rb', line 23

def fetch_accounts
  log 'fetch_accounts'
  accounts = []
  if @dashboard_doc
    if links = @dashboard_doc.css('div.caj_content_plegable.bk_ocultable_novisible div.tab_extracto_01')[0]
      links.css('table tbody tr').each do |x|
        name = x.css('td.enlace div form button').text.encode("UTF-8")
        balance_currency = x.css('td.numero').text.scan(/[\d,\.]+|\D+/)
        balance = balance_currency[0]
        currency = balance_currency[1].gsub(/[[:space:]]/,"")
        cc = x.css('td.enlace div form input')[0]['value']
        data = {'id' => cc, 'description' => name, 'availableBalance' => balance, 'currency' => currency, 'iban' => cc}

        accounts.push((data))
      end
    end
  end

  accounts
end

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



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/bank_scrap/banks/bankinter.rb', line 44

def fetch_transactions_for(, start_date: Date.today - 1.month, end_date: Date.today)
  transactions = []

  fields = {
    'ext-solapa' => 'operar',
    'ext-subsolapa' => 'mis_cuentas',
    'ordenDesc' => '',
    'ordenFechaC' => 'A',
    'ordenFechaV' => '',
    'ordenGasto' => '',
    'ordenIng' => '',
    'buscador' => 'S',
    'tipoConsulta' => 'N',
    'seleccionado_tipo' => '',
    'cuenta_seleccionada' => .iban,
    'tipoMov' => 'A',
    'dia' => start_date.strftime("%d"),
    'mes' => start_date.strftime("%m"),
    'anio' => start_date.strftime("%Y"),
    'diaH' => end_date.strftime("%d"),
    'mesH' => end_date.strftime("%m"),
    'anioH' => end_date.strftime("%Y"),
  }

  response = post(BASE_ENDPOINT + TRANSACTIONS_ENDPOINT, fields: fields)

  html_doc = Nokogiri::HTML(response)

  html_transactions = html_doc.css('table#tablaDin_tabla tbody tr')

  html_transactions.each do |x|
    date = x.css('td.fecha')[0].text
    description = x.css('td')[2].text
    amount = x.css('td.numero').text.gsub(/\s+|\.|,/, "")

    data = {'description' => description, 'amount' => amount, 'operationDate' => date, 'currency' => .currency}
    transactions.push(build_transaction(data, ));
  end

  transactions
end