bank_scrap 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bank_scrap/banks/ing.rb +68 -70
- data/lib/bank_scrap/banks/ing/numbers/{pinpad0.png → 0.png} +0 -0
- data/lib/bank_scrap/banks/ing/numbers/{pinpad1.png → 1.png} +0 -0
- data/lib/bank_scrap/banks/ing/numbers/{pinpad2.png → 2.png} +0 -0
- data/lib/bank_scrap/banks/ing/numbers/{pinpad3.png → 3.png} +0 -0
- data/lib/bank_scrap/banks/ing/numbers/{pinpad4.png → 4.png} +0 -0
- data/lib/bank_scrap/banks/ing/numbers/{pinpad5.png → 5.png} +0 -0
- data/lib/bank_scrap/banks/ing/numbers/{pinpad6.png → 6.png} +0 -0
- data/lib/bank_scrap/banks/ing/numbers/{pinpad7.png → 7.png} +0 -0
- data/lib/bank_scrap/banks/ing/numbers/{pinpad8.png → 8.png} +0 -0
- data/lib/bank_scrap/banks/ing/numbers/{pinpad9.png → 9.png} +0 -0
- data/lib/bank_scrap/version.rb +1 -1
- metadata +12 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5728e4928e376190709d30ebacdcedb8fef94113
|
4
|
+
data.tar.gz: 911e7754d1e4d5c5c188ec25c1e19e3e39854b64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e215a5088f8c0e212d8b2e51f1e5a51a7018ba6c6fb1706d2f6b3dfb36bb40d6bc20096331b653e34bc105dd8203ca0f7975f8bced8543ffd229b2503a40ef41
|
7
|
+
data.tar.gz: fd9c1b0500c2c9932ed4460bbcfd31ea8a960b438eb21a299f037865736aa341b8535a4a8b2e83f6163b8e5f9f75ea0540adecc1c46ad86eac68ccf1179d6965
|
data/lib/bank_scrap/banks/ing.rb
CHANGED
@@ -5,15 +5,15 @@ require 'tempfile'
|
|
5
5
|
|
6
6
|
module BankScrap
|
7
7
|
class Ing < Bank
|
8
|
-
|
9
8
|
BASE_ENDPOINT = 'https://ing.ingdirect.es/'
|
10
9
|
LOGIN_ENDPOINT = BASE_ENDPOINT + 'genoma_login/rest/session'
|
11
10
|
POST_AUTH_ENDPOINT = BASE_ENDPOINT + 'genoma_api/login/auth/response'
|
12
11
|
CLIENT_ENDPOINT = BASE_ENDPOINT + 'genoma_api/rest/client'
|
13
12
|
PRODUCTS_ENDPOINT = BASE_ENDPOINT + 'genoma_api/rest/products'
|
14
13
|
|
15
|
-
SAMPLE_WIDTH
|
16
|
-
SAMPLE_HEIGHT
|
14
|
+
SAMPLE_WIDTH = 30
|
15
|
+
SAMPLE_HEIGHT = 30
|
16
|
+
SAMPLE_ROOT_PATH = '/ing/numbers'
|
17
17
|
|
18
18
|
def initialize(user, password, log: false, debug: false, extra_args:)
|
19
19
|
@dni = user
|
@@ -28,8 +28,8 @@ module BankScrap
|
|
28
28
|
super
|
29
29
|
end
|
30
30
|
|
31
|
-
def
|
32
|
-
log '
|
31
|
+
def balances
|
32
|
+
log 'get_balances'
|
33
33
|
balances = {}
|
34
34
|
total_balance = 0
|
35
35
|
@accounts.each do |account|
|
@@ -41,23 +41,17 @@ module BankScrap
|
|
41
41
|
balances
|
42
42
|
end
|
43
43
|
|
44
|
-
def raw_accounts_data
|
45
|
-
@raw_accounts_data
|
46
|
-
end
|
47
|
-
|
48
44
|
def fetch_accounts
|
49
45
|
log 'fetch_accounts'
|
50
|
-
set_headers(
|
51
|
-
|
46
|
+
set_headers(
|
47
|
+
'Accept' => '*/*',
|
52
48
|
'Content-Type' => 'application/json; charset=utf-8'
|
53
|
-
|
49
|
+
)
|
54
50
|
|
55
51
|
@raw_accounts_data = JSON.parse(get(PRODUCTS_ENDPOINT))
|
56
52
|
|
57
|
-
@raw_accounts_data.
|
58
|
-
if account['iban']
|
59
|
-
build_account(account)
|
60
|
-
end
|
53
|
+
@raw_accounts_data.map do |account|
|
54
|
+
build_account(account) if account['iban']
|
61
55
|
end.compact
|
62
56
|
end
|
63
57
|
|
@@ -67,9 +61,9 @@ module BankScrap
|
|
67
61
|
# The API allows any limit to be passed, but we better keep
|
68
62
|
# being good API citizens and make a loop with a short limit
|
69
63
|
params = {
|
70
|
-
fromDate: start_date.strftime(
|
71
|
-
toDate: end_date.strftime(
|
72
|
-
limit: 25,
|
64
|
+
fromDate: start_date.strftime('%d/%m/%Y'),
|
65
|
+
toDate: end_date.strftime('%d/%m/%Y'),
|
66
|
+
limit: 25,
|
73
67
|
offset: 0
|
74
68
|
}
|
75
69
|
|
@@ -77,7 +71,9 @@ module BankScrap
|
|
77
71
|
loop do
|
78
72
|
request = get("#{PRODUCTS_ENDPOINT}/#{account.id}/movements", params)
|
79
73
|
json = JSON.parse(request)
|
80
|
-
transactions += json['elements'].
|
74
|
+
transactions += json['elements'].map do |transaction|
|
75
|
+
build_transaction(transaction, account)
|
76
|
+
end
|
81
77
|
params[:offset] += 25
|
82
78
|
break if (params[:offset] > json['total']) || json['elements'].blank?
|
83
79
|
end
|
@@ -93,12 +89,12 @@ module BankScrap
|
|
93
89
|
end
|
94
90
|
|
95
91
|
def login
|
96
|
-
set_headers(
|
97
|
-
|
92
|
+
set_headers(
|
93
|
+
'Accept' => 'application/json, text/javascript, */*; q=0.01',
|
98
94
|
'Content-Type' => 'application/json; charset=utf-8'
|
99
|
-
|
95
|
+
)
|
100
96
|
|
101
|
-
|
97
|
+
params = {
|
102
98
|
loginDocument: {
|
103
99
|
documentType: 0,
|
104
100
|
document: @dni.to_s
|
@@ -108,74 +104,76 @@ module BankScrap
|
|
108
104
|
device: 'desktop'
|
109
105
|
}
|
110
106
|
|
111
|
-
response = JSON.parse(post(LOGIN_ENDPOINT,
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
pinpad_numbers_paths = save_pinpad_numbers(pinpad)
|
116
|
-
pinpad_numbers = recognize_pinpad_numbers(pinpad_numbers_paths)
|
107
|
+
response = JSON.parse(post(LOGIN_ENDPOINT, params.to_json))
|
108
|
+
current_pinpad_paths = save_pinpad_numbers(response['pinpad'])
|
109
|
+
pinpad_numbers = recognize_pinpad_numbers(current_pinpad_paths)
|
117
110
|
|
118
|
-
get_correct_positions(pinpad_numbers,
|
111
|
+
get_correct_positions(pinpad_numbers, response['pinPositions'])
|
119
112
|
end
|
120
113
|
|
121
114
|
def pass_pinpad(positions)
|
122
|
-
|
123
|
-
"Accept" => 'application/json, text/javascript, */*; q=0.01',
|
124
|
-
'Content-Type' => 'application/json; charset=utf-8'
|
125
|
-
})
|
126
|
-
|
127
|
-
param = "{\"pinPositions\": #{positions}}"
|
128
|
-
response = put(LOGIN_ENDPOINT, param)
|
115
|
+
response = put(LOGIN_ENDPOINT, { pinPositions: positions }.to_json)
|
129
116
|
JSON.parse(response)['ticket']
|
130
117
|
end
|
131
118
|
|
132
119
|
def post_auth(ticket)
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
120
|
+
set_headers(
|
121
|
+
'Accept' => 'application/json, text/javascript, */*; q=0.01',
|
122
|
+
'Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8'
|
123
|
+
)
|
137
124
|
|
138
|
-
|
139
|
-
|
125
|
+
params = "ticket=#{ticket}&device=desktop"
|
126
|
+
post(POST_AUTH_ENDPOINT, params)
|
140
127
|
end
|
141
128
|
|
142
129
|
def save_pinpad_numbers(pinpad)
|
143
|
-
|
144
|
-
pinpad.each_with_index do |digit,index|
|
130
|
+
current_pinpad_paths = []
|
131
|
+
pinpad.each_with_index do |digit, index|
|
145
132
|
tmp = Tempfile.new(["pinpad_number_#{index}", '.png'])
|
146
|
-
File.open(tmp.path, 'wb'){ |f| f.write(Base64.decode64(digit)) }
|
147
|
-
|
133
|
+
File.open(tmp.path, 'wb') { |f| f.write(Base64.decode64(digit)) }
|
134
|
+
current_pinpad_paths << tmp.path
|
148
135
|
end
|
149
136
|
|
150
|
-
|
137
|
+
current_pinpad_paths
|
151
138
|
end
|
152
139
|
|
153
|
-
def recognize_pinpad_numbers(
|
154
|
-
|
155
|
-
|
140
|
+
def recognize_pinpad_numbers(current_pinpad_paths)
|
141
|
+
real_numbers = []
|
142
|
+
current_numbers = Magick::ImageList.new(*current_pinpad_paths)
|
156
143
|
0.upto(9) do |i|
|
157
|
-
|
158
|
-
|
144
|
+
current_number_img = current_numbers[i]
|
145
|
+
pixel_diffs = []
|
159
146
|
0.upto(9) do |j|
|
160
|
-
|
161
|
-
|
162
|
-
img = Magick::ImageList.new(File.join(File.dirname(__FILE__), "/ing/numbers/pinpad#{j}.png")).first
|
163
|
-
number_pixels_sample = img.get_pixels(0, 0, SAMPLE_WIDTH, SAMPLE_HEIGHT)
|
164
|
-
diff = 0
|
165
|
-
pinpad_pixels_sample.each_with_index do |pixel, index|
|
166
|
-
sample_pixel = number_pixels_sample[index]
|
167
|
-
diff += (pixel.red - sample_pixel.red).abs +
|
168
|
-
(pixel.green - sample_pixel.green).abs +
|
169
|
-
(pixel.blue - sample_pixel.blue).abs
|
170
|
-
end
|
171
|
-
differences << diff
|
147
|
+
sample_number_img = Magick::ImageList.new(sample_number_path(j)).first
|
148
|
+
pixel_diffs << images_diff(sample_number_img, current_numbers[i])
|
172
149
|
end
|
150
|
+
real_numbers << pixel_diffs.each_with_index.min.last
|
151
|
+
end
|
152
|
+
real_numbers
|
153
|
+
end
|
173
154
|
|
174
|
-
|
175
|
-
|
155
|
+
def sample_number_path(number)
|
156
|
+
File.join(File.dirname(__FILE__), "#{SAMPLE_ROOT_PATH}/#{number}.png")
|
157
|
+
end
|
158
|
+
|
159
|
+
def images_diff(sample_number_img, current_number_img)
|
160
|
+
diff = 0
|
161
|
+
sample_pixels = pixels_from_coordinates(sample_number_img, 0, 0)
|
162
|
+
current_pixels = pixels_from_coordinates(current_number_img, 0, 0)
|
163
|
+
current_pixels.each_with_index do |pixel, index|
|
164
|
+
sample_pixel = sample_pixels[index]
|
165
|
+
red_diff = (pixel.red - sample_pixel.red).abs
|
166
|
+
green_diff = (pixel.green - sample_pixel.green).abs
|
167
|
+
blue_diff = (pixel.blue - sample_pixel.blue).abs
|
168
|
+
|
169
|
+
diff += red_diff + green_diff + blue_diff
|
176
170
|
end
|
177
171
|
|
178
|
-
|
172
|
+
diff
|
173
|
+
end
|
174
|
+
|
175
|
+
def pixels_from_coordinates(img, x, y)
|
176
|
+
img.get_pixels(x, y, SAMPLE_WIDTH, SAMPLE_HEIGHT)
|
179
177
|
end
|
180
178
|
|
181
179
|
def get_correct_positions(pinpad_numbers, positions)
|
@@ -212,7 +210,7 @@ module BankScrap
|
|
212
210
|
id: data['uuid'],
|
213
211
|
amount: data['amount'],
|
214
212
|
currency: data['EUR'],
|
215
|
-
effective_date: data['effectiveDate'],
|
213
|
+
effective_date: Date.strptime(data['effectiveDate'], "%d/%m/%Y"),
|
216
214
|
description: data['description'],
|
217
215
|
balance: data['balance']
|
218
216
|
)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/bank_scrap/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bank_scrap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ismael Sánchez
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2015-
|
14
|
+
date: 2015-02-03 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|
@@ -186,16 +186,16 @@ files:
|
|
186
186
|
- lib/bank_scrap/banks/bankinter.rb
|
187
187
|
- lib/bank_scrap/banks/bbva.rb
|
188
188
|
- lib/bank_scrap/banks/ing.rb
|
189
|
-
- lib/bank_scrap/banks/ing/numbers/
|
190
|
-
- lib/bank_scrap/banks/ing/numbers/
|
191
|
-
- lib/bank_scrap/banks/ing/numbers/
|
192
|
-
- lib/bank_scrap/banks/ing/numbers/
|
193
|
-
- lib/bank_scrap/banks/ing/numbers/
|
194
|
-
- lib/bank_scrap/banks/ing/numbers/
|
195
|
-
- lib/bank_scrap/banks/ing/numbers/
|
196
|
-
- lib/bank_scrap/banks/ing/numbers/
|
197
|
-
- lib/bank_scrap/banks/ing/numbers/
|
198
|
-
- lib/bank_scrap/banks/ing/numbers/
|
189
|
+
- lib/bank_scrap/banks/ing/numbers/0.png
|
190
|
+
- lib/bank_scrap/banks/ing/numbers/1.png
|
191
|
+
- lib/bank_scrap/banks/ing/numbers/2.png
|
192
|
+
- lib/bank_scrap/banks/ing/numbers/3.png
|
193
|
+
- lib/bank_scrap/banks/ing/numbers/4.png
|
194
|
+
- lib/bank_scrap/banks/ing/numbers/5.png
|
195
|
+
- lib/bank_scrap/banks/ing/numbers/6.png
|
196
|
+
- lib/bank_scrap/banks/ing/numbers/7.png
|
197
|
+
- lib/bank_scrap/banks/ing/numbers/8.png
|
198
|
+
- lib/bank_scrap/banks/ing/numbers/9.png
|
199
199
|
- lib/bank_scrap/cli.rb
|
200
200
|
- lib/bank_scrap/config.rb
|
201
201
|
- lib/bank_scrap/locale/en.yml
|