bank_api 0.1.4 → 0.2.0

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: e97136ba0665a58f442afd35ef6972fa05f0ba8f643f28eecde6a0ec5d56bb9e
4
- data.tar.gz: eca8bedfa6c6171895821f6bfbc0e4994d7d682159900fc19dd73f8fc43db877
3
+ metadata.gz: 460ff4b31aaf7bbccba226a8a50560054af00e35859ce5169009d9204451ef09
4
+ data.tar.gz: 5d65c9f756ed6eb837e02bd82a21c169112d82943e70f9f0ba569e3527ee6113
5
5
  SHA512:
6
- metadata.gz: 04b8718ab8a7b9f67ad4d98084e067f379610198566c8564a8ffbab495560511ebca7865fb7be8f149615c28e2ca4dfaeb2e5418a731f966ed70de3bdc85c106
7
- data.tar.gz: 061ac7769fcc5e48ba034df0987f70b19c23e1b064186c9a60ce5b39c3b3b001e10d90572ae5bfa4969ba8925fdadd013116d823d175baedac35acd02ca2ddbf
6
+ metadata.gz: de3fee34aced5a6e31eb5d68f9ff69a5f84c19de7a002935a48de4c022eb42234e7b72ca967214d0e2c057ca15d7a9111c7140cbadbfde3e56d8c04be67bf928
7
+ data.tar.gz: 5e2ef565565b2f001494782c329be680da35a3d23ad3d171e58de858ad3a0fb11cf2ceeb7aa71c496b32389d7bea8421fb45e1a1898e5827300c936323325a86
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bank_api (0.1.4)
4
+ bank_api (0.2.0)
5
5
  pincers
6
6
  timezone (~> 1.0)
7
7
 
@@ -12,10 +12,10 @@ GEM
12
12
  ffi (~> 1.0, >= 1.0.11)
13
13
  coderay (1.1.2)
14
14
  diff-lcs (1.3)
15
- ffi (1.9.18)
15
+ ffi (1.9.23)
16
16
  method_source (0.9.0)
17
17
  mini_portile2 (2.3.0)
18
- nokogiri (1.8.1)
18
+ nokogiri (1.8.2)
19
19
  mini_portile2 (~> 2.3.0)
20
20
  pincers (0.7.12)
21
21
  nokogiri (~> 1.6)
@@ -42,7 +42,7 @@ GEM
42
42
  childprocess (~> 0.5)
43
43
  rubyzip (~> 1.0)
44
44
  websocket (~> 1.0)
45
- timezone (1.2.9)
45
+ timezone (1.2.10)
46
46
  websocket (1.2.5)
47
47
 
48
48
  PLATFORMS
@@ -0,0 +1,151 @@
1
+ require 'timezone'
2
+
3
+ require 'bank_api/clients/base_client'
4
+
5
+ module BankApi::Clients::BancoSecurity
6
+ class CompanyClient < BankApi::Clients::BaseClient
7
+ BASE_URL = 'https://empresas.bancosecurity.cl/'
8
+
9
+ DATE_COLUMN = 0
10
+ RUT_COLUMN = 2
11
+ AMOUNT_COLUMN = 5
12
+
13
+ NUMBER_OF_COLUMNS = 7
14
+
15
+ def initialize(config = BankApi::Configuration.new)
16
+ @user_rut = config.banco_security.user_rut
17
+ @password = config.banco_security.password
18
+ @company_rut = config.banco_security.company_rut
19
+ super
20
+ end
21
+
22
+ def get_deposits
23
+ login
24
+ goto_company_dashboard
25
+ goto_deposits
26
+ select_deposits_range
27
+ deposits = any_deposits? ? extract_deposits_from_html : []
28
+ browser.close
29
+ deposits
30
+ end
31
+
32
+ def validate_credentials
33
+ raise BankApi::MissingCredentialsError if [
34
+ @user_rut,
35
+ @password,
36
+ @company_rut
37
+ ].any?(&:nil?)
38
+ end
39
+
40
+ def login
41
+ goto_login
42
+ set_login_values
43
+ click_login_button
44
+ end
45
+
46
+ def goto_login
47
+ if session_expired?
48
+ browser.search("button:contains('Ingresa nuevamente')").click
49
+ browser.search("a:contains('Empresas')").click
50
+ else
51
+ browser.goto BASE_URL
52
+ browser.search('#mrcBtnIngresa').click
53
+ end
54
+ end
55
+
56
+ def session_expired?
57
+ browser.search("button:contains('Ingresa nuevamente')").any?
58
+ end
59
+
60
+ def set_login_values
61
+ browser.search('#lrut').set @user_rut
62
+ browser.search('#lpass').set @password
63
+ end
64
+
65
+ def click_login_button
66
+ browser.search('input[name="Entrar"]').click
67
+ end
68
+
69
+ def goto_company_dashboard
70
+ goto_frame query: '#mainFrame'
71
+ goto_frame(query: 'iframe[name="central"]', should_reset: false)
72
+ selenium_browser.execute_script(
73
+ "submitEntrar(true,1,#{without_verifier_digit_or_separators(@company_rut)}," +
74
+ "'#{verifier_digit(@company_rut)}');"
75
+ )
76
+ end
77
+
78
+ def goto_deposits
79
+ goto_frame query: '#topFrame'
80
+ selenium_browser.execute_script(
81
+ "MM_goToURL('parent.frames[\\'topFrame\\']','../menu/MenuTopTransferencias.asp'," +
82
+ "'parent.frames[\\'leftFrame\\']','../menu/MenuTransferencias.asp'," +
83
+ "'parent.frames[\\'mainFrame\\']','../../../noticias/transferencias.asp');"
84
+ )
85
+ selenium_browser.execute_script(
86
+ "MM_goToURL('parent.frames[\\'mainFrame\\']'," +
87
+ "'/empresas/RedirectConvivencia.asp?urlRedirect=CartolasTEF/Home/Index')"
88
+ )
89
+ goto_frame query: '#mainFrame'
90
+ goto_frame query: 'iframe[name="central"]', should_reset: false
91
+ wait('a.k-link:contains("Recibidas")').click
92
+ end
93
+
94
+ def select_deposits_range
95
+ browser.search('.BusquedaPorDefectoRecibida a:contains("búsqueda avanzada")').click
96
+ browser.search('#RadioEntreFechasRecibido').click
97
+ browser.search('#datePickerInicioRecibidas').set deposit_range[:start]
98
+ browser.search('#datePickerFinRecibido').set deposit_range[:end]
99
+ browser.search('.ContenedorSubmitRecibidas .btn_buscar').click
100
+ wait_for_deposits_fetch
101
+ end
102
+
103
+ def wait_for_deposits_fetch
104
+ goto_frame query: '#mainFrame'
105
+ goto_frame query: 'iframe[name="central"]', should_reset: false
106
+ wait('.k-loading-image') { browser.search('.k-loading-image').count.zero? }
107
+ end
108
+
109
+ def extract_deposits_from_html
110
+ deposits = []
111
+ deposit = {}
112
+ browser.search('#gridPrincipalRecibidas tbody td').each_with_index do |div, index|
113
+ if (index % NUMBER_OF_COLUMNS) == RUT_COLUMN
114
+ deposit[:rut] = div.text
115
+ elsif (index % NUMBER_OF_COLUMNS) == DATE_COLUMN
116
+ deposit[:date] = Date.parse div.text
117
+ elsif (index % NUMBER_OF_COLUMNS) == AMOUNT_COLUMN
118
+ deposit[:amount] = div.text.gsub(/[\. $]/, '').to_i
119
+ elsif ((index + 1) % NUMBER_OF_COLUMNS).zero?
120
+ deposits << deposit
121
+ deposit = {}
122
+ end
123
+ end
124
+ deposits
125
+ end
126
+
127
+ def deposit_range
128
+ @deposit_range ||= begin
129
+ timezone = Timezone['America/Santiago']
130
+ {
131
+ start: (timezone.utc_to_local(Time.now).to_date - @days_to_check).strftime('%d/%m/%Y'),
132
+ end: timezone.utc_to_local(Time.now).to_date.strftime('%d/%m/%Y')
133
+ }
134
+ end
135
+ end
136
+
137
+ def any_deposits?
138
+ browser.search(
139
+ ".k-label:contains('No se han encontrado transacciones para la búsqueda seleccionada.')"
140
+ ).any?
141
+ end
142
+
143
+ def goto_frame(query: nil, should_reset: true)
144
+ sleep 1
145
+ browser.goto frame: :top if should_reset
146
+ frame = wait(query) if query
147
+ browser.goto(frame: frame)
148
+ sleep 0.2
149
+ end
150
+ end
151
+ end
@@ -35,7 +35,11 @@ module BankApi::Clients
35
35
  end
36
36
 
37
37
  def browser
38
- @browser ||= Pincers.for_webdriver(driver)
38
+ @browser ||= Pincers.for_webdriver(driver, wait_timeout: 35.0)
39
+ end
40
+
41
+ def selenium_browser
42
+ @browser.document
39
43
  end
40
44
 
41
45
  def driver(width = 1024, heigth = 768)
@@ -58,6 +62,19 @@ module BankApi::Clients
58
62
  d
59
63
  end
60
64
 
65
+ def wait(query)
66
+ count = 0
67
+ timeout = browser.config[:wait_timeout]
68
+ interval = browser.config[:wait_interval]
69
+ fulfilled = false
70
+ while !fulfilled && count < timeout
71
+ fulfilled = block_given? ? yield : browser.search(query).any?
72
+ sleep interval
73
+ count += interval
74
+ end
75
+ browser.search(query)
76
+ end
77
+
61
78
  def parse_entries(entries)
62
79
  deposit_entries = entries.map do |entry|
63
80
  BankApi::Values::DepositEntry.new(
@@ -0,0 +1,11 @@
1
+ module BankApi::Configs
2
+ class BancoSecurity
3
+ attr_accessor :user_rut, :password, :company_rut
4
+
5
+ def initialize
6
+ @user_rut = nil
7
+ @password = nil
8
+ @company_rut = nil
9
+ end
10
+ end
11
+ end
@@ -9,5 +9,9 @@ module BankApi
9
9
 
10
10
  @days_to_check = 6
11
11
  end
12
+
13
+ def banco_security
14
+ @banco_security ||= BankApi::Configs::BancoSecurity.new
15
+ end
12
16
  end
13
17
  end
@@ -1,3 +1,3 @@
1
1
  module BankApi
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/bank_api.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require "bank_api/configuration"
2
+ require "bank_api/configs/banco_security"
2
3
  require "bank_api/version"
3
4
  require 'bank_api/clients/banco_de_chile_company_client'
5
+ require 'bank_api/clients/banco_security/company_client'
4
6
 
5
7
  module BankApi
6
8
  class << self
@@ -22,4 +24,10 @@ module BankApi
22
24
  def self.get_bdc_recent_company_deposits
23
25
  Clients::BancoDeChileCompanyClient.new(configuration).get_recent_deposits
24
26
  end
27
+
28
+ module BancoSecurity
29
+ def self.get_recent_company_deposits
30
+ Clients::BancoSecurity::CompanyClient.new(BankApi.configuration).get_recent_deposits
31
+ end
32
+ end
25
33
  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.1.4
4
+ version: 0.2.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-01-26 00:00:00.000000000 Z
11
+ date: 2018-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pincers
@@ -116,7 +116,9 @@ files:
116
116
  - bin/setup
117
117
  - lib/bank_api.rb
118
118
  - lib/bank_api/clients/banco_de_chile_company_client.rb
119
+ - lib/bank_api/clients/banco_security/company_client.rb
119
120
  - lib/bank_api/clients/base_client.rb
121
+ - lib/bank_api/configs/banco_security.rb
120
122
  - lib/bank_api/configuration.rb
121
123
  - lib/bank_api/exceptions.rb
122
124
  - lib/bank_api/sign_deposits.rb
@@ -143,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
145
  version: '0'
144
146
  requirements: []
145
147
  rubyforge_project:
146
- rubygems_version: 2.7.4
148
+ rubygems_version: 2.7.6
147
149
  signing_key:
148
150
  specification_version: 4
149
151
  summary: Wrapper for chilean banks