bank_api 0.7.3 → 0.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/bank_api/clients/banco_de_chile_company_client.rb +41 -30
- data/lib/bank_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f2f4a9a510aa0be5c38a8ca5334288bb54e18ed4c331a9041d1a429d3a6465b
|
4
|
+
data.tar.gz: 619066eb0753d40b8eba8779243302c1b40df0fadb99d9498fd242787ef62db8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 738db258a350678887dc01087758e13deb84cc6a0e80bfb27eab363ac79fb312c7f33b5cb7791c22a690e14a236f4982e1c35b6314c25bc122d778f01a255ce6
|
7
|
+
data.tar.gz: 41a00c54ffa933d16faeaf780a3ca931a62e37d8fbfab038b5810ff2e1efa4f0ec582f78588968c33ccd3ed5f0ef7cd68c383c7daf652fae0b21328c15db2ef2
|
data/Gemfile.lock
CHANGED
@@ -7,6 +7,7 @@ module BankApi::Clients
|
|
7
7
|
class BancoDeChileCompanyClient < BaseClient
|
8
8
|
COMPANY_LOGIN_URL = 'https://www.empresas.bancochile.cl/cgi-bin/navega?pagina=enlinea/login_fus'
|
9
9
|
COMPANY_DEPOSITS_URL = 'https://www.empresas.bancochile.cl/GlosaInternetEmpresaRecibida/ConsultaRecibidaAction.do'
|
10
|
+
COMPANY_PREPARE_DEPOSITS_URL = 'https://www.empresas.bancochile.cl/GlosaInternetEmpresaRecibida/RespuestaConsultaRecibidaAction.do'
|
10
11
|
COMPANY_DEPOSITS_TXT_URL = 'https://www.empresas.bancochile.cl/GlosaInternetEmpresaRecibida/RespuestaConsultaRecibidaAction.do'
|
11
12
|
COMPANY_ACCOUNT_DEPOSITS_URL = 'https://www.empresas.bancochile.cl/CCOLSaldoMovimientosWEB/selectorCuentas.do?accion=initSelectorCuentas&cuenta=001642711701&moneda=CTD#page=page-1'
|
12
13
|
COMPANY_CC_BALANCE_URL = 'https://www.empresas.bancochile.cl/CCOLDerivadorWEB/selectorCuentas.do?accion=initSelectorCuentas&opcion=saldos&moduloProducto=CC'
|
@@ -95,7 +96,6 @@ module BankApi::Clients
|
|
95
96
|
|
96
97
|
def get_deposits_from_transfers_section
|
97
98
|
goto_deposits
|
98
|
-
select_deposits_range
|
99
99
|
deposits_from_txt
|
100
100
|
end
|
101
101
|
|
@@ -137,36 +137,17 @@ module BankApi::Clients
|
|
137
137
|
format_account_transactions(result)
|
138
138
|
end
|
139
139
|
|
140
|
-
def select_deposits_range
|
141
|
-
browser.search('input[name=initDate]').set(deposit_range[:start])
|
142
|
-
first_account = browser.search("select[name=ctaCorriente] option").find do |account|
|
143
|
-
account.value.include? @bdc_account
|
144
|
-
end.value
|
145
|
-
browser.search("select[name=ctaCorriente]").set by_value: first_account
|
146
|
-
browser.search('#consultar').click
|
147
|
-
end
|
148
|
-
|
149
140
|
def validate_banchile_status!
|
150
141
|
unless browser.search(".textoerror:contains('no podemos atenderle')").none?
|
151
142
|
raise "Banchile is down"
|
152
143
|
end
|
153
144
|
end
|
154
145
|
|
155
|
-
def any_deposits?
|
156
|
-
browser.search('table#sin_datos').none?
|
157
|
-
end
|
158
|
-
|
159
|
-
def total_results
|
160
|
-
browser.search("#pager .encabezadotabla:contains(\"Operaciones encontradas\")")
|
161
|
-
.text[/\d+/].to_i
|
162
|
-
end
|
163
|
-
|
164
146
|
def deposits_from_txt
|
165
|
-
|
166
|
-
return [] unless any_deposits?
|
147
|
+
prepare_deposits
|
167
148
|
response = RestClient::Request.execute(
|
168
149
|
url: COMPANY_DEPOSITS_TXT_URL, method: :post, headers: session_headers,
|
169
|
-
payload:
|
150
|
+
payload: deposits_txt_payload(deposit_range[:start], deposit_range[:end]), verify_ssl: false
|
170
151
|
)
|
171
152
|
raise "Banchile is down" if response.body.include? "no podemos atenderle"
|
172
153
|
|
@@ -177,6 +158,14 @@ module BankApi::Clients
|
|
177
158
|
raise e
|
178
159
|
end
|
179
160
|
|
161
|
+
def prepare_deposits
|
162
|
+
RestClient::Request.execute(
|
163
|
+
url: COMPANY_PREPARE_DEPOSITS_URL, method: :post, headers: session_headers,
|
164
|
+
payload: prepare_deposits_payload(deposit_range[:start], deposit_range[:end]),
|
165
|
+
verify_ssl: false
|
166
|
+
)
|
167
|
+
end
|
168
|
+
|
180
169
|
def split_transactions(transactions_str)
|
181
170
|
transactions_str.delete("\r").split("\n").drop(1).map { |r| r.split(";") }.select do |t|
|
182
171
|
t[7] == "Aprobada"
|
@@ -217,28 +206,50 @@ module BankApi::Clients
|
|
217
206
|
name.to_s.split("DE:").last.to_s.strip
|
218
207
|
end
|
219
208
|
|
220
|
-
def
|
209
|
+
def base_payload(from_date, to_date)
|
221
210
|
{
|
222
|
-
'accion' => 'exportarTxtOperaciones',
|
223
211
|
'initDate' => from_date,
|
224
212
|
'endDate' => to_date,
|
225
|
-
'ctaCorriente' =>
|
213
|
+
'ctaCorriente' => padded_account,
|
226
214
|
'nada' => 'nada'
|
227
215
|
}
|
228
216
|
end
|
229
217
|
|
218
|
+
def padded_account
|
219
|
+
"0" * (12 - @bdc_account.length) + @bdc_account
|
220
|
+
end
|
221
|
+
|
222
|
+
def prepare_deposits_payload(from_date, to_date)
|
223
|
+
base_payload(from_date, to_date).merge('accion' => 'buscarOperaciones')
|
224
|
+
end
|
225
|
+
|
226
|
+
def deposits_txt_payload(from_date, to_date)
|
227
|
+
base_payload(from_date, to_date).merge('accion' => 'exportarTxtOperaciones')
|
228
|
+
end
|
229
|
+
|
230
230
|
def session_headers
|
231
231
|
{
|
232
|
-
"
|
232
|
+
"Pragma" => "no-cache",
|
233
|
+
"Connection" => "keep-alive",
|
234
|
+
"Cache-Control" => "no-cache",
|
235
|
+
"Upgrade-Insecure-Requests" => 1,
|
233
236
|
"Content-Type" => "application/x-www-form-urlencoded",
|
234
|
-
"
|
235
|
-
|
237
|
+
"Origin" => "https://www.empresas.bancochile.cl",
|
238
|
+
"User-Agent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 " +
|
239
|
+
"(KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36",
|
240
|
+
"Accept" => "text/html,application/xhtml+xml,application/xml;q=0.9," +
|
241
|
+
"image/webp,image/apng,*/*;q=0.8",
|
236
242
|
"Accept-Encoding" => "gzip, deflate, br",
|
237
|
-
"
|
238
|
-
"RespuestaConsultaRecibidaAction.do"
|
243
|
+
"Cookie" => cookies
|
239
244
|
}
|
240
245
|
end
|
241
246
|
|
247
|
+
def cookies
|
248
|
+
selenium_browser.manage.all_cookies.map do |cookie|
|
249
|
+
"#{cookie[:name]}=#{cookie[:value]}"
|
250
|
+
end.join("; ")
|
251
|
+
end
|
252
|
+
|
242
253
|
def cookie(name)
|
243
254
|
selenium_browser.manage.cookie_named(name)[:value]
|
244
255
|
end
|
data/lib/bank_api/version.rb
CHANGED
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.
|
4
|
+
version: 0.7.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- oaestay
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-10-
|
11
|
+
date: 2018-10-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pincers
|