bank_api 0.6.2 → 0.7.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3ee63798e44803986aa2a2a9428500311aaddf896d9d9d0dd537b12705be2cfe
4
- data.tar.gz: d2449dd880b2056573e3977aefc1610e82e5a8f59a1f66814aa9f7bcb4377c41
3
+ metadata.gz: 5c662404a8d0dc38f26dfca622c9a22437b6db2fd7afc97e654cf66adb2edd02
4
+ data.tar.gz: 5cefd91e473f411bed2637111e18a63fa2b185c6f64c9aa1c03a8e0d270bd701
5
5
  SHA512:
6
- metadata.gz: 45e2cbbff9ffd1e26903c8c79566b141761460d5b4190ca05be78d6e6e71b92a4ac9122ac318380bb0dd72598f50cc496c018e3ff725c3b83addc5c8bdcc2641
7
- data.tar.gz: 17a5e5827d454eec7f0e892a1173b117ab39acac44625a50779fe8569485bad294bdfa317de5b8ac4e32ebbb005af667b185eb4ad8ff214eb860afdc97467b35
6
+ metadata.gz: 9c34c055bf07cb81e49c5624ac43c68701e4c36f42ed20d39daaecd4a2639e84bfdaa59bab7c3e52e506475527285394d49a02f02a4e945f3f6709b3d70ae3f4
7
+ data.tar.gz: 1ba1ace8c489633af961c19dacc9b13d4f8801bfdbfcc11ea52c75fb8473f7588b14d0c09890221476bfa8b3ab872acfd437f1e434736f6e0bd82f163d2c02e0
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bank_api (0.6.2)
4
+ bank_api (0.7.0)
5
5
  pincers
6
6
  rest-client
7
7
  timezone (~> 1.0)
@@ -21,8 +21,8 @@ module BankApi
21
21
  yield(configuration)
22
22
  end
23
23
 
24
- def self.get_bdc_recent_company_deposits
25
- Clients::BancoDeChileCompanyClient.new(configuration).get_recent_deposits
24
+ def self.get_bdc_recent_company_deposits(options = {})
25
+ Clients::BancoDeChileCompanyClient.new(configuration).get_recent_deposits(options)
26
26
  end
27
27
 
28
28
  def self.get_bdc_account_balance(account_number)
@@ -8,15 +8,9 @@ module BankApi::Clients
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
10
  COMPANY_DEPOSITS_TXT_URL = 'https://www.empresas.bancochile.cl/GlosaInternetEmpresaRecibida/RespuestaConsultaRecibidaAction.do'
11
+ COMPANY_ACCOUNT_DEPOSITS_URL = 'https://www.empresas.bancochile.cl/CCOLSaldoMovimientosWEB/selectorCuentas.do?accion=initSelectorCuentas&cuenta=001642711701&moneda=CTD#page=page-1'
11
12
  COMPANY_CC_BALANCE_URL = 'https://www.empresas.bancochile.cl/CCOLDerivadorWEB/selectorCuentas.do?accion=initSelectorCuentas&opcion=saldos&moduloProducto=CC'
12
13
 
13
- DATE_COLUMN = 0
14
- RUT_COLUMN = 4
15
- AMOUNT_COLUMN = 6
16
- STATE_COLUMN = 7
17
-
18
- NUMBER_OF_COLUMNS = 9
19
-
20
14
  def initialize(config = BankApi::Configuration.new)
21
15
  @bdc_company_rut = config.bdc_company_rut
22
16
  @bdc_user_rut = config.bdc_user_rut
@@ -82,16 +76,29 @@ module BankApi::Clients
82
76
  browser.search('table.detalleSaldosMov tr:first-child > td.aRight.bold').text
83
77
  end
84
78
 
85
- def get_deposits(_options = {})
79
+ def get_deposits(options = {})
86
80
  login
87
- goto_deposits
88
- select_deposits_range
89
- deposits = deposits_from_txt
90
- deposits
81
+
82
+ if options[:source] == :account_details
83
+ return get_deposits_from_balance_section
84
+ end
85
+
86
+ get_deposits_from_transfers_section
91
87
  ensure
92
88
  browser.close
93
89
  end
94
90
 
91
+ def get_deposits_from_balance_section
92
+ goto_account_deposits
93
+ account_deposits_from_txt
94
+ end
95
+
96
+ def get_deposits_from_transfers_section
97
+ goto_deposits
98
+ select_deposits_range
99
+ deposits_from_txt
100
+ end
101
+
95
102
  def login
96
103
  goto_login_url
97
104
  set_login_values
@@ -114,10 +121,22 @@ module BankApi::Clients
114
121
  browser.search('.btn_amarillodegrade').click
115
122
  end
116
123
 
124
+ def goto_account_deposits
125
+ browser.goto COMPANY_ACCOUNT_DEPOSITS_URL
126
+ end
127
+
117
128
  def goto_deposits
118
129
  browser.goto COMPANY_DEPOSITS_URL
119
130
  end
120
131
 
132
+ def account_deposits_from_txt
133
+ url = browser.search("#expoDato_child > a:nth-child(3)").attribute(:href)
134
+ result = browser.download(url)
135
+ .content.encode("UTF-8", "iso-8859-3")
136
+ .delete("\r").split("\n").drop(2)
137
+ format_account_transactions(result)
138
+ end
139
+
121
140
  def select_deposits_range
122
141
  browser.search('input[name=initDate]').set(deposit_range[:start])
123
142
  first_account = browser.search("select[name=ctaCorriente] option").find do |account|
@@ -160,20 +179,44 @@ module BankApi::Clients
160
179
 
161
180
  def split_transactions(transactions_str)
162
181
  transactions_str.delete("\r").split("\n").drop(1).map { |r| r.split(";") }.select do |t|
163
- t[STATE_COLUMN] == "Aprobada"
182
+ t[7] == "Aprobada"
164
183
  end
165
184
  end
166
185
 
167
186
  def format_transactions(transactions)
168
187
  transactions.map do |t|
169
188
  {
170
- rut: t[RUT_COLUMN],
171
- date: Date.parse(t[DATE_COLUMN]),
172
- amount: t[AMOUNT_COLUMN].to_i
189
+ client: format_client_name(t[3]),
190
+ rut: t[4],
191
+ date: Date.parse(t[0]),
192
+ time: nil,
193
+ amount: t[6].to_i
194
+ }
195
+ end
196
+ end
197
+
198
+ def format_account_transactions(transactions)
199
+ transactions.inject([]) do |memo, t|
200
+ parts = t.split(";")
201
+ amount = parts[3].to_i
202
+ next memo if amount.zero?
203
+
204
+ memo << {
205
+ client: format_client_name(parts[1]),
206
+ rut: nil,
207
+ date: Date.parse(parts[0]),
208
+ time: nil,
209
+ amount: amount
173
210
  }
211
+
212
+ memo
174
213
  end
175
214
  end
176
215
 
216
+ def format_client_name(name)
217
+ name.to_s.split("DE:").last.to_s.strip
218
+ end
219
+
177
220
  def deposits_params(from_date, to_date)
178
221
  {
179
222
  'accion' => 'exportarTxtOperaciones',
@@ -1,3 +1,3 @@
1
1
  module BankApi
2
- VERSION = "0.6.2"
2
+ VERSION = "0.7.0"
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.6.2
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - oaestay
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-09-25 00:00:00.000000000 Z
11
+ date: 2018-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pincers