bank_api 0.7.6 → 0.7.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 886af5ed1c68d928ae5d94d6e25ad64be7f5bd6b764e0077b1522dd9ba14776a
4
- data.tar.gz: c9577fc968bac4ed8e6c5df548ac13ae44e3a4a9abc616a41c3b7e248989e1b2
3
+ metadata.gz: 94b0f3f7f91bbb4833ef3c4b95773116f8dc0979a045254e7f595b6b4143020a
4
+ data.tar.gz: f18540be2dde9b842bbe2e0594d6ff9d3222739327039a2e3e0c09565df783d0
5
5
  SHA512:
6
- metadata.gz: 0f2beaff4e27168e47ba068470e0c181fcbdba91772c0ab690e780b2c2f7f2498a3790abc983c660ab5d98f538980d04397939aeffcb6fa8924ead05ccf2b523
7
- data.tar.gz: 354ead4117bf1215be1f4fbf400e1c1f5db7602c527010df13245bc180799a02548721589ba8a52a2f5158d88d7e9c2b1865cb5eba3b1c651f9d6ad39c66b288
6
+ metadata.gz: c6e54aaa6d7a9cbf0569cc2e2d50eef305df7d2a25ce14be34077bf41108d2f7159e9f9845dfc001a0f484a7d383794d4fa946819a5631a3cd37de6eb18f68aa
7
+ data.tar.gz: 8b50fb49d428367b92e3bfe42a19c37e8c962c9a8adc70b9d73c834fbf9d284cb33e54ad540eaf596757b91a393022ba4d95fa468fb56b1e977ec7d99716fa8a
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bank_api (0.7.6)
4
+ bank_api (0.7.7)
5
5
  pincers
6
6
  rest-client
7
7
  timezone (~> 1.0)
@@ -1,7 +1,10 @@
1
1
  # coding: utf-8
2
+ require 'rest-client'
2
3
 
3
4
  module BankApi::Clients::BancoSecurity
4
5
  module Deposits
6
+ SESSION_VALIDATION = "https://www.bancosecurity.cl/empresas/SessionValidation.asp"
7
+
5
8
  def select_deposits_range
6
9
  browser.search('.BusquedaPorDefectoRecibida a:contains("búsqueda avanzada")').click
7
10
  browser.search('#RadioEntreFechasRecibido').click
@@ -33,13 +36,28 @@ module BankApi::Clients::BancoSecurity
33
36
  end
34
37
 
35
38
  def deposits_from_txt
36
- wait("") { any_deposits? }
37
39
  raise BankApi::Deposit::FetchError, "Couldn't fetch deposits" unless any_deposits?
40
+ setup_authentication
38
41
  download = browser.download(deposits_txt_url)
39
42
  transactions = download.content.split("\n").drop(1).map { |r| r.split("|") }
43
+ if transactions.empty?
44
+ raise BankApi::Deposit::FetchError, "Couldn't fetch deposits, received #{download.content}"
45
+ end
40
46
  format_transactions(transactions)
41
47
  end
42
48
 
49
+ def setup_authentication
50
+ response = RestClient::Request.execute(
51
+ url: SESSION_VALIDATION, method: :post, headers: session_headers
52
+ )
53
+ new_cookies = response.headers[:set_cookie].first.delete(" ").split(";").map do |a|
54
+ a.split("=")
55
+ end
56
+ new_cookies.each do |key, value|
57
+ selenium_browser.manage.add_cookie(name: key, value: value)
58
+ end
59
+ end
60
+
43
61
  def deposits_from_account_details
44
62
  data = browser.download(
45
63
  deposits_account_details_url
@@ -92,13 +110,33 @@ module BankApi::Clients::BancoSecurity
92
110
  end
93
111
  end
94
112
 
113
+ def session_headers
114
+ {
115
+ "Origin" => "https://www.bancosecurity.cl",
116
+ "Accept-Encoding" => "gzip, deflate, br",
117
+ "Accept-Language" => "en-US,en;q=0.9",
118
+ "User-Agent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 " +
119
+ "(KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36",
120
+ "Accept" => "*/*",
121
+ "Referer" => "https://www.bancosecurity.cl/ConvivenciaEmpresas/CartolasTEF/Home?" + "
122
+ tipoTransaccion=Recibidas",
123
+ "X-Requested-With" => "XMLHttpRequest",
124
+ "Connection" => "keep-alive",
125
+ "Content-Length" => "0",
126
+ "Cookie" => cookies
127
+ }
128
+ end
129
+
130
+ def cookies
131
+ selenium_browser.manage.all_cookies.map do |cookie|
132
+ "#{cookie[:name]}=#{cookie[:value]}"
133
+ end.join("; ")
134
+ end
135
+
95
136
  def deposits_txt_url
96
- account_number = CGI.escape(selenium_browser.execute_script('return nCuenta'))
97
- start_ = CGI.escape("#{deposit_range[:start].strftime('%m/%d/%Y')} 00:00:00")
98
- end_ = CGI.escape("#{deposit_range[:end].strftime('%m/%d/%Y')} 00:00:00")
99
- "https://www.bancosecurity.cl/ConvivenciaEmpresas/CartolasTEF/Download/" +
100
- "CrearTxTRecibidas?numeroCuenta=#{account_number}&monto=0&" +
101
- "fechaInicio=#{start_}&fechaFin=#{end_}&estado=1"
137
+ selenium_browser.execute_script("console.log(DescargarDocumentoTxtRecibidas)")
138
+ log = selenium_browser.manage.logs.get(:browser).last
139
+ /url = '(.*)';/.match(log.message).captures.first
102
140
  end
103
141
 
104
142
  def deposits_account_details_url
@@ -1,3 +1,3 @@
1
1
  module BankApi
2
- VERSION = "0.7.6"
2
+ VERSION = "0.7.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bank_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.6
4
+ version: 0.7.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - oaestay
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-08 00:00:00.000000000 Z
11
+ date: 2018-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pincers
@@ -194,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
194
  version: '0'
195
195
  requirements: []
196
196
  rubyforge_project:
197
- rubygems_version: 2.7.8
197
+ rubygems_version: 2.7.7
198
198
  signing_key:
199
199
  specification_version: 4
200
200
  summary: Wrapper for chilean banks