Module: BankApi::Clients::BancoSecurity::Deposits
- Included in:
- CompanyClient
- Defined in:
- lib/bank_api/clients/banco_security/concerns/deposits.rb
Constant Summary collapse
- DATE_COLUMN =
0- RUT_COLUMN =
2- AMOUNT_COLUMN =
5
Instance Method Summary collapse
- #any_deposits? ⇒ Boolean
- #deposit_range ⇒ Object
- #deposits_from_txt ⇒ Object
- #deposits_txt_url ⇒ Object
- #format_rut(rut) ⇒ Object
- #format_transactions(transactions) ⇒ Object
- #select_deposits_range ⇒ Object
- #timezone ⇒ Object
- #total_deposits ⇒ Object
- #validate_deposits(deposits) ⇒ Object
- #wait_for_deposits_fetch ⇒ Object
Instance Method Details
#any_deposits? ⇒ Boolean
70 71 72 73 74 75 |
# File 'lib/bank_api/clients/banco_security/concerns/deposits.rb', line 70 def any_deposits? browser.search( "#gridPrincipalRecibidas " \ ".k-label:contains('No se han encontrado transacciones para la búsqueda seleccionada.')" ).none? end |
#deposit_range ⇒ Object
42 43 44 45 46 47 |
# File 'lib/bank_api/clients/banco_security/concerns/deposits.rb', line 42 def deposit_range @deposit_range ||= begin today = timezone.utc_to_local(Time.now).to_date { start: (today - @days_to_check), end: today } end end |
#deposits_from_txt ⇒ Object
25 26 27 28 29 30 |
# File 'lib/bank_api/clients/banco_security/concerns/deposits.rb', line 25 def deposits_from_txt return [] unless any_deposits? download = browser.download(deposits_txt_url) transactions = download.content.split("\n").drop(1).map { |r| r.split("|") } format_transactions(transactions) end |
#deposits_txt_url ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/bank_api/clients/banco_security/concerns/deposits.rb', line 49 def deposits_txt_url account_number = CGI.escape(selenium_browser.execute_script('return nCuenta')) start_ = CGI.escape("#{deposit_range[:start].strftime('%m/%d/%Y')} 00:00:00") end_ = CGI.escape("#{deposit_range[:end].strftime('%m/%d/%Y')} 00:00:00") "https://www.bancosecurity.cl/ConvivenciaEmpresas/CartolasTEF/Download/" + "CrearTxTRecibidas?numeroCuenta=#{account_number}&monto=0&" + "fechaInicio=#{start_}&fechaFin=#{end_}&estado=1" end |
#format_rut(rut) ⇒ Object
58 59 60 61 62 |
# File 'lib/bank_api/clients/banco_security/concerns/deposits.rb', line 58 def format_rut(rut) verification_digit = rut[-1] without_verification_digit = rut[0..-2].reverse.scan(/.{1,3}/).join(".").reverse "#{without_verification_digit}-#{verification_digit}" end |
#format_transactions(transactions) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/bank_api/clients/banco_security/concerns/deposits.rb', line 32 def format_transactions(transactions) transactions.map do |t| { rut: format_rut(t[RUT_COLUMN]), date: timezone.local_to_utc(DateTime.parse(t[DATE_COLUMN])).to_date, amount: t[AMOUNT_COLUMN].to_i } end end |
#select_deposits_range ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/bank_api/clients/banco_security/concerns/deposits.rb', line 9 def select_deposits_range browser.search('.BusquedaPorDefectoRecibida a:contains("búsqueda avanzada")').click browser.search('#RadioEntreFechasRecibido').click browser.search('#datePickerInicioRecibidas').set deposit_range[:start].strftime('%d/%m/%Y') browser.search('#datePickerFinRecibido').set deposit_range[:end].strftime('%d/%m/%Y') wait('.ContenedorSubmitRecibidas .btn_buscar').click wait_for_deposits_fetch end |
#timezone ⇒ Object
85 86 87 |
# File 'lib/bank_api/clients/banco_security/concerns/deposits.rb', line 85 def timezone @timezone ||= Timezone['America/Santiago'] end |
#total_deposits ⇒ Object
64 65 66 67 68 |
# File 'lib/bank_api/clients/banco_security/concerns/deposits.rb', line 64 def total_deposits pages_info = wait(".k-pager-info") matches = pages_info.text.match(/(\d+)[a-z\s-]+(\d+)[a-z\s-]+(\d+)/) matches[3].to_i end |
#validate_deposits(deposits) ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/bank_api/clients/banco_security/concerns/deposits.rb', line 77 def validate_deposits(deposits) total_deposits_ = total_deposits unless deposits.count == total_deposits_ raise BankApi::Deposit::QuantityError, "Expected #{total_deposits_} deposits," + " got #{deposits.count}." end end |
#wait_for_deposits_fetch ⇒ Object
18 19 20 21 22 23 |
# File 'lib/bank_api/clients/banco_security/concerns/deposits.rb', line 18 def wait_for_deposits_fetch goto_frame query: '#mainFrame' goto_frame query: 'iframe[name="central"]', should_reset: false wait('.k-loading-image') { browser.search('.k-loading-image').any? } wait('.k-loading-image') { browser.search('.k-loading-image').none? } end |