bank_api 0.4.4 → 0.5.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 +4 -4
- data/Gemfile.lock +2 -2
- data/lib/bank_api.rb +8 -5
- data/lib/bank_api/clients/banco_de_chile_company_client.rb +1 -1
- data/lib/bank_api/clients/banco_security/company_client.rb +22 -6
- data/lib/bank_api/clients/banco_security/concerns/deposits.rb +45 -7
- data/lib/bank_api/clients/base_client.rb +6 -4
- data/lib/bank_api/clients/navigation/banco_security/company_navigation.rb +4 -0
- data/lib/bank_api/sign_deposits.rb +2 -1
- data/lib/bank_api/values/deposit_entry.rb +4 -2
- 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: cd569e27d05057177eb55bd22f5ea7e715e1320543d49343a684cd12a3ed53b5
|
4
|
+
data.tar.gz: 1421ca3ecfa79b5c441849470666099ee5b0e2429550e186a5ff3273d0a9707a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd21fb3ebd6cac2413c52c04066012cd5893eaee3ddbe898d91a1164037590f345c7a9746bb6c9fa2cc22b1b639fe4adddf3a45b4d6c9da684e66ef39a92015e
|
7
|
+
data.tar.gz: 4e90b787dc4120d7735a28058d9d973544abc6661bd12393a40361c07c9882b8b61821811f7d351431b57c54168199607b3d48e82249518fc8a9a4174df2011f
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
bank_api (0.
|
4
|
+
bank_api (0.5.0)
|
5
5
|
pincers
|
6
6
|
rest-client
|
7
7
|
timezone (~> 1.0)
|
@@ -60,7 +60,7 @@ GEM
|
|
60
60
|
diff-lcs (>= 1.2.0, < 2.0)
|
61
61
|
rspec-support (~> 3.7.0)
|
62
62
|
rspec-support (3.7.0)
|
63
|
-
rubyzip (1.2.
|
63
|
+
rubyzip (1.2.2)
|
64
64
|
selenium-webdriver (2.53.4)
|
65
65
|
childprocess (~> 0.5)
|
66
66
|
rubyzip (~> 1.0)
|
data/lib/bank_api.rb
CHANGED
@@ -27,20 +27,23 @@ module BankApi
|
|
27
27
|
|
28
28
|
module BancoSecurity
|
29
29
|
def self.get_account_balance(account_number)
|
30
|
-
|
30
|
+
company_instance.get_balance(account_number)
|
31
31
|
end
|
32
32
|
|
33
|
-
def self.get_recent_company_deposits
|
34
|
-
|
33
|
+
def self.get_recent_company_deposits(options = {})
|
34
|
+
company_instance.get_recent_deposits(options)
|
35
35
|
end
|
36
36
|
|
37
37
|
def self.company_transfer(transfer_data)
|
38
|
-
|
38
|
+
company_instance.transfer(transfer_data)
|
39
39
|
end
|
40
40
|
|
41
41
|
def self.company_batch_transfers(transfers_data)
|
42
|
+
company_instance.batch_transfers(transfers_data)
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.company_instance
|
42
46
|
Clients::BancoSecurity::CompanyClient.new(BankApi.configuration)
|
43
|
-
.batch_transfers(transfers_data)
|
44
47
|
end
|
45
48
|
end
|
46
49
|
end
|
@@ -37,14 +37,15 @@ module BankApi::Clients::BancoSecurity
|
|
37
37
|
find_account_balance(account_number)
|
38
38
|
end
|
39
39
|
|
40
|
-
def get_deposits
|
40
|
+
def get_deposits(options = {})
|
41
41
|
login
|
42
42
|
goto_company_dashboard
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
43
|
+
|
44
|
+
if options[:source] == :account_details
|
45
|
+
return get_deposits_from_balance_section(options[:account_number])
|
46
|
+
end
|
47
|
+
|
48
|
+
get_deposits_from_transfers_section
|
48
49
|
ensure
|
49
50
|
browser.close
|
50
51
|
end
|
@@ -71,6 +72,21 @@ module BankApi::Clients::BancoSecurity
|
|
71
72
|
browser.close
|
72
73
|
end
|
73
74
|
|
75
|
+
def get_deposits_from_transfers_section
|
76
|
+
goto_deposits
|
77
|
+
select_deposits_range
|
78
|
+
deposits = deposits_from_txt
|
79
|
+
validate_deposits(deposits) unless deposits.empty?
|
80
|
+
deposits
|
81
|
+
end
|
82
|
+
|
83
|
+
def get_deposits_from_balance_section(account_number)
|
84
|
+
fail "missing :account_number option" unless account_number
|
85
|
+
goto_balance
|
86
|
+
goto_account_details(account_number.to_s)
|
87
|
+
deposits_from_account_details
|
88
|
+
end
|
89
|
+
|
74
90
|
def goto_frame(query: nil, should_reset: true)
|
75
91
|
sleep 1
|
76
92
|
super
|
@@ -2,10 +2,6 @@
|
|
2
2
|
|
3
3
|
module BankApi::Clients::BancoSecurity
|
4
4
|
module Deposits
|
5
|
-
DATE_COLUMN = 0
|
6
|
-
RUT_COLUMN = 2
|
7
|
-
AMOUNT_COLUMN = 5
|
8
|
-
|
9
5
|
def select_deposits_range
|
10
6
|
browser.search('.BusquedaPorDefectoRecibida a:contains("búsqueda avanzada")').click
|
11
7
|
browser.search('#RadioEntreFechasRecibido').click
|
@@ -29,16 +25,54 @@ module BankApi::Clients::BancoSecurity
|
|
29
25
|
format_transactions(transactions)
|
30
26
|
end
|
31
27
|
|
28
|
+
def deposits_from_account_details
|
29
|
+
data = browser.download(
|
30
|
+
deposits_account_details_url
|
31
|
+
).content.encode("UTF-8", "iso-8859-3").split("\r\n")
|
32
|
+
transactions = data[3, data.count - 11].reverse
|
33
|
+
format_account_transactions(transactions)
|
34
|
+
end
|
35
|
+
|
32
36
|
def format_transactions(transactions)
|
33
37
|
transactions.map do |t|
|
38
|
+
datetime = DateTime.parse(t[0])
|
34
39
|
{
|
35
|
-
|
36
|
-
|
37
|
-
|
40
|
+
client: t[1],
|
41
|
+
rut: format_rut(t[2]),
|
42
|
+
date: timezone.local_to_utc(datetime).to_date,
|
43
|
+
time: datetime,
|
44
|
+
amount: t[5].to_i
|
38
45
|
}
|
39
46
|
end
|
40
47
|
end
|
41
48
|
|
49
|
+
def format_account_transactions(transactions)
|
50
|
+
transactions.inject([]) do |memo, t|
|
51
|
+
parts = t.split(";")
|
52
|
+
amount = parts[4].delete(",").to_i
|
53
|
+
next memo if amount.zero?
|
54
|
+
client = extract_client_name(parts[1])
|
55
|
+
next memo unless client
|
56
|
+
|
57
|
+
memo << {
|
58
|
+
client: client,
|
59
|
+
rut: nil,
|
60
|
+
date: Date.strptime(parts[0], "%d/%m"),
|
61
|
+
time: nil,
|
62
|
+
amount: amount
|
63
|
+
}
|
64
|
+
|
65
|
+
memo
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def extract_client_name(text)
|
70
|
+
parts = text.to_s.split(" De ")
|
71
|
+
parts = text.to_s.split(" DE ") if parts.count == 1
|
72
|
+
return text if parts.count > 2
|
73
|
+
parts.last.to_s.strip
|
74
|
+
end
|
75
|
+
|
42
76
|
def deposit_range
|
43
77
|
@deposit_range ||= begin
|
44
78
|
today = timezone.utc_to_local(Time.now).to_date
|
@@ -55,6 +89,10 @@ module BankApi::Clients::BancoSecurity
|
|
55
89
|
"fechaInicio=#{start_}&fechaFin=#{end_}&estado=1"
|
56
90
|
end
|
57
91
|
|
92
|
+
def deposits_account_details_url
|
93
|
+
browser.search("a:contains('Descargar TXT')").first.attribute("href")
|
94
|
+
end
|
95
|
+
|
58
96
|
def format_rut(rut)
|
59
97
|
verification_digit = rut[-1]
|
60
98
|
without_verification_digit = rut[0..-2].reverse.scan(/.{1,3}/).join(".").reverse
|
@@ -11,9 +11,9 @@ module BankApi::Clients
|
|
11
11
|
@days_to_check = config.days_to_check
|
12
12
|
end
|
13
13
|
|
14
|
-
def get_recent_deposits
|
14
|
+
def get_recent_deposits(options = {})
|
15
15
|
validate_credentials
|
16
|
-
parse_entries(get_deposits)
|
16
|
+
parse_entries(get_deposits(options))
|
17
17
|
end
|
18
18
|
|
19
19
|
def transfer(transfer_data)
|
@@ -42,7 +42,7 @@ module BankApi::Clients
|
|
42
42
|
raise NotImplementedError
|
43
43
|
end
|
44
44
|
|
45
|
-
def get_deposits
|
45
|
+
def get_deposits(_options = {})
|
46
46
|
raise NotImplementedError
|
47
47
|
end
|
48
48
|
|
@@ -122,8 +122,10 @@ module BankApi::Clients
|
|
122
122
|
BankApi::Values::DepositEntry.new(
|
123
123
|
entry[:amount],
|
124
124
|
entry[:date],
|
125
|
+
entry[:time],
|
125
126
|
entry[:rut],
|
126
|
-
bank_name
|
127
|
+
bank_name,
|
128
|
+
entry[:client]
|
127
129
|
)
|
128
130
|
end
|
129
131
|
BankApi::SignDeposits.sign(deposit_entries)
|
@@ -67,6 +67,10 @@ module BankApi::Clients::Navigation
|
|
67
67
|
goto_frame query: 'iframe[name="central"]', should_reset: false
|
68
68
|
end
|
69
69
|
|
70
|
+
def goto_account_details(account_number)
|
71
|
+
wait("a.clickable:contains(\"#{account_number}\")").click
|
72
|
+
end
|
73
|
+
|
70
74
|
def goto_transfer_form
|
71
75
|
goto_frame query: '#topFrame'
|
72
76
|
selenium_browser.execute_script(
|
@@ -37,6 +37,7 @@ module BankApi::SignDeposits
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def entry_key(entry)
|
40
|
-
|
40
|
+
rut_or_client = entry.rut || entry.client.to_s.downcase.delete(' ')
|
41
|
+
"#{entry.amount}|#{entry.date}|#{rut_or_client}|#{entry.bank}"
|
41
42
|
end
|
42
43
|
end
|
@@ -1,12 +1,14 @@
|
|
1
1
|
module BankApi::Values
|
2
2
|
class DepositEntry
|
3
|
-
attr_accessor :amount, :date, :rut, :signature, :bank
|
3
|
+
attr_accessor :client, :amount, :date, :time, :rut, :signature, :bank
|
4
4
|
|
5
|
-
def initialize(amount, date, rut, bank)
|
5
|
+
def initialize(amount, date, time, rut, bank, client)
|
6
6
|
@amount = amount
|
7
7
|
@date = date
|
8
|
+
@time = time
|
8
9
|
@rut = rut
|
9
10
|
@bank = bank
|
11
|
+
@client = client
|
10
12
|
end
|
11
13
|
end
|
12
14
|
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.
|
4
|
+
version: 0.5.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-
|
11
|
+
date: 2018-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pincers
|