bankscrap-bbva 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +33 -0
- data/Rakefile +2 -0
- data/bankscrap-bbva.gemspec +23 -0
- data/lib/bankscrap-bbva.rb +2 -0
- data/lib/bankscrap/bbva/bank.rb +172 -0
- data/lib/bankscrap/bbva/version.rb +5 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5ef32ec6a56dd9b9352ca60ff3a86b14e9b70f21
|
4
|
+
data.tar.gz: ad37699ac93f8a959cd8562a0e6dd590a466bbdb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 023c42192b35b82f99a8fe7f4e704e42a2419fbf0963a8317131ffe7299e75eb820d68ae09a341134480f08c5358bd54f49001f5e58639b7ffb5771d59c8c62e
|
7
|
+
data.tar.gz: ff6b7afb3e00a79649cd3b4313f094de12ad50032d7d80b7172a4dead6337d96f63e31d42bf5e9dc3c08c1bbd59c96bb1b2730e4dca58ee729775183a51ee1a4
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Raúl Marcos
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Bankscrap::BBVA
|
2
|
+
|
3
|
+
Bankscrap adapter for the API behind BBVA's [mobile app](https://play.google.com/store/apps/developer?id=BBVA&hl=en).
|
4
|
+
This adapter is only valid for personal accounts (the ones that work with that mobile APP), not for company accounts.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'bankscrap-bbva'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install bankscrap-bbva
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
For usage instructions please read [Bankscrap readme](https://github.com/bankscrap/bankscrap/blob/refactor/README.md#usage).
|
25
|
+
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
1. Fork it ( https://github.com/[my-github-username]/bankscrap-bbva/fork )
|
30
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
31
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
32
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
33
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bankscrap/bbva/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "bankscrap-bbva"
|
8
|
+
spec.version = Bankscrap::BBVA::VERSION
|
9
|
+
spec.authors = ['Javier Cuevas']
|
10
|
+
spec.email = ["javier@diacode.com"]
|
11
|
+
spec.summary = %q{BBVA adapter for Bankscrap}
|
12
|
+
spec.homepage = ""
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_runtime_dependency "bankscrap", "~> 1.0"
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
end
|
@@ -0,0 +1,172 @@
|
|
1
|
+
require 'bankscrap'
|
2
|
+
|
3
|
+
module Bankscrap
|
4
|
+
module BBVA
|
5
|
+
class Bank < ::Bankscrap::Bank
|
6
|
+
BASE_ENDPOINT = 'https://servicios.bbva.es'
|
7
|
+
LOGIN_ENDPOINT = '/DFAUTH/slod/DFServletXML'
|
8
|
+
PRODUCTS_ENDPOINT = '/ENPP/enpp_mult_web_mobility_02/products/v1'
|
9
|
+
ACCOUNT_ENDPOINT = '/ENPP/enpp_mult_web_mobility_02/accounts/'
|
10
|
+
# BBVA expects an identifier before the actual User Agent, but 12345 works fine
|
11
|
+
USER_AGENT = '12345;Android;LGE;Nexus 5;1080x1776;Android;5.1.1;BMES;4.4;xxhd'
|
12
|
+
|
13
|
+
def initialize(user, password, log: false, debug: false, extra_args: nil)
|
14
|
+
@user = format_user(user.dup)
|
15
|
+
@password = password
|
16
|
+
@log = log
|
17
|
+
@debug = debug
|
18
|
+
|
19
|
+
initialize_connection
|
20
|
+
|
21
|
+
add_headers(
|
22
|
+
'User-Agent' => USER_AGENT,
|
23
|
+
'BBVA-User-Agent' => USER_AGENT,
|
24
|
+
'Accept-Language' => 'spa',
|
25
|
+
'Content-Language' => 'spa',
|
26
|
+
'Accept' => 'application/json',
|
27
|
+
'Accept-Charset' => 'UTF-8',
|
28
|
+
'Connection' => 'Keep-Alive',
|
29
|
+
'Host' => 'bancamovil.grupobbva.com',
|
30
|
+
'Cookie2' => '$Version=1'
|
31
|
+
)
|
32
|
+
|
33
|
+
login
|
34
|
+
super
|
35
|
+
end
|
36
|
+
|
37
|
+
# Fetch all the accounts for the given user
|
38
|
+
# Returns an array of Bankscrap::Account objects
|
39
|
+
def fetch_accounts
|
40
|
+
log 'fetch_accounts'
|
41
|
+
|
42
|
+
# Even if the required method is an HTTP POST
|
43
|
+
# the API requires a funny header that says is a GET
|
44
|
+
# otherwise the request doesn't work.
|
45
|
+
response = with_headers('BBVA-Method' => 'GET') do
|
46
|
+
post(BASE_ENDPOINT + PRODUCTS_ENDPOINT)
|
47
|
+
end
|
48
|
+
|
49
|
+
json = JSON.parse(response)
|
50
|
+
json['accounts'].map { |data| build_account(data) }
|
51
|
+
end
|
52
|
+
|
53
|
+
# Fetch transactions for the given account.
|
54
|
+
# By default it fetches transactions for the last month,
|
55
|
+
# The maximum allowed by the BBVA API is the last 3 years.
|
56
|
+
#
|
57
|
+
# Account should be a Bankscrap::Account object
|
58
|
+
# Returns an array of Bankscrap::Transaction objects
|
59
|
+
def fetch_transactions_for(account, start_date: Date.today - 1.month, end_date: Date.today)
|
60
|
+
from_date = start_date.strftime('%Y-%m-%d')
|
61
|
+
|
62
|
+
# Misteriously we need a specific content-type here
|
63
|
+
funny_headers = {
|
64
|
+
'Content-Type' => 'application/json; charset=UTF-8',
|
65
|
+
'BBVA-Method' => 'GET'
|
66
|
+
}
|
67
|
+
|
68
|
+
# The API accepts a toDate param that we could pass the end_date argument,
|
69
|
+
# however when we pass the toDate param, the API stops returning the account balance.
|
70
|
+
# Therefore we need to take a workaround: only filter with fromDate and loop
|
71
|
+
# over all the available pages, filtering out the movements that doesn't match
|
72
|
+
# the end_date argument.
|
73
|
+
url = BASE_ENDPOINT +
|
74
|
+
ACCOUNT_ENDPOINT +
|
75
|
+
account.id +
|
76
|
+
"/movements/v1?fromDate=#{from_date}"
|
77
|
+
|
78
|
+
offset = nil
|
79
|
+
pagination_balance = nil
|
80
|
+
transactions = []
|
81
|
+
|
82
|
+
with_headers(funny_headers) do
|
83
|
+
# Loop over pagination
|
84
|
+
loop do
|
85
|
+
new_url = offset ? (url + "&offset=#{offset}") : url
|
86
|
+
new_url = pagination_balance ? (new_url + "&paginationBalance=#{pagination_balance}") : new_url
|
87
|
+
json = JSON.parse(post(new_url))
|
88
|
+
|
89
|
+
unless json['movements'].blank?
|
90
|
+
# As explained before, we have to discard records newer than end_date.
|
91
|
+
filtered_movements = json['movements'].select { |m| Date.parse(m['operationDate']) <= end_date }
|
92
|
+
|
93
|
+
transactions += filtered_movements.map do |data|
|
94
|
+
build_transaction(data, account)
|
95
|
+
end
|
96
|
+
offset = json['offset']
|
97
|
+
pagination_balance = json['paginationBalance']
|
98
|
+
end
|
99
|
+
|
100
|
+
break unless json['thereAreMoreMovements'] == true
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
transactions
|
105
|
+
end
|
106
|
+
|
107
|
+
private
|
108
|
+
|
109
|
+
# As far as we know there are two types of identifiers BBVA uses
|
110
|
+
# 1) A number of 7 characters that gets passed to the API as it is
|
111
|
+
# 2) A DNI number, this needs to transformed before it get passed to the API
|
112
|
+
# Example: "49021740T" will become "0019-049021740T"
|
113
|
+
def format_user(user)
|
114
|
+
user.upcase!
|
115
|
+
|
116
|
+
if user.match(/^[0-9]{8}[A-Z]$/)
|
117
|
+
# It's a DNI
|
118
|
+
"0019-0#{user}"
|
119
|
+
else
|
120
|
+
user
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def login
|
125
|
+
log 'login'
|
126
|
+
params = {
|
127
|
+
'origen' => 'enpp',
|
128
|
+
'eai_tipoCP' => 'up',
|
129
|
+
'eai_user' => @user,
|
130
|
+
'eai_password' => @password
|
131
|
+
}
|
132
|
+
post(BASE_ENDPOINT + LOGIN_ENDPOINT, fields: params)
|
133
|
+
end
|
134
|
+
|
135
|
+
# Build an Account object from API data
|
136
|
+
def build_account(data)
|
137
|
+
Account.new(
|
138
|
+
bank: self,
|
139
|
+
id: data['id'],
|
140
|
+
name: data['name'],
|
141
|
+
available_balance: data['availableBalance'],
|
142
|
+
balance: data['availableBalance'],
|
143
|
+
currency: data['currency'],
|
144
|
+
iban: data['iban'],
|
145
|
+
description: "#{data['typeDescription']} #{data['familyCode']}"
|
146
|
+
)
|
147
|
+
end
|
148
|
+
|
149
|
+
# Build a transaction object from API data
|
150
|
+
def build_transaction(data, account)
|
151
|
+
Transaction.new(
|
152
|
+
account: account,
|
153
|
+
id: data['id'],
|
154
|
+
amount: transaction_amount(data),
|
155
|
+
description: data['conceptDescription'] || data['description'],
|
156
|
+
effective_date: Date.strptime(data['operationDate'], '%Y-%m-%d'),
|
157
|
+
currency: data['currency'],
|
158
|
+
balance: transaction_balance(data)
|
159
|
+
)
|
160
|
+
end
|
161
|
+
|
162
|
+
def transaction_amount(data)
|
163
|
+
Money.new(data['amount'] * 100, data['currency'])
|
164
|
+
end
|
165
|
+
|
166
|
+
def transaction_balance(data)
|
167
|
+
return unless data['accountBalanceAfterMovement']
|
168
|
+
Money.new(data['accountBalanceAfterMovement'] * 100, data['currency'])
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bankscrap-bbva
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Javier Cuevas
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bankscrap
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- javier@diacode.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- bankscrap-bbva.gemspec
|
68
|
+
- lib/bankscrap-bbva.rb
|
69
|
+
- lib/bankscrap/bbva/bank.rb
|
70
|
+
- lib/bankscrap/bbva/version.rb
|
71
|
+
homepage: ''
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 2.6.4
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: BBVA adapter for Bankscrap
|
95
|
+
test_files: []
|