bankscrap-arquia 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 +20 -0
- data/README.md +52 -0
- data/Rakefile +1 -0
- data/bankscrap-arquia.gemspec +23 -0
- data/lib/bankscrap-arquia.rb +2 -0
- data/lib/bankscrap/arquia/bank.rb +162 -0
- data/lib/bankscrap/arquia/version.rb +5 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5da0a8be1c72e2f78a71e1de5bd7162b3f81eab6
|
4
|
+
data.tar.gz: cb67eb4591184e996e058d41d4f5f0afc07f66c3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8418b19ad9f11e3476f1538e37e812620f5464e7160f2b7ea53a122af6cfe874bf56a01ae8a60bed9bd615f78490f43e72a6be3abfba11c0f85570aa446baac2
|
7
|
+
data.tar.gz: e58074b6b0a58f4ac823ae0ce66cc42b77bc622efb4acaa421f79b4b066f5bf7ca5721da808b03a67a584207e9a526016646db6328763a077ff05d26052a4c68
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Bankscrap::Arquia
|
2
|
+
|
3
|
+
Bankscrap adapter for [Arquia Banca](https://www.arquia.es/) (only tested with personal accounts).
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'bankscrap-arquia'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install bankscrap-arquia
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
### From terminal
|
25
|
+
#### Bank account balance
|
26
|
+
|
27
|
+
$ bankscrap balance Arquia --user YOUR_USER --password YOUR_PASSWORD --extra=nif:YOUR_NIF
|
28
|
+
|
29
|
+
|
30
|
+
#### Transactions
|
31
|
+
|
32
|
+
$ bankscrap transactions Arquia --user YOUR_USER --password YOUR_PASSWORD --extra=nif:YOUR_NIF
|
33
|
+
|
34
|
+
---
|
35
|
+
|
36
|
+
For more details on usage instructions please read [Bankscrap readme](https://github.com/bankscrap/bankscrap/#usage).
|
37
|
+
|
38
|
+
### From Ruby code
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
require 'bankscrap-arquia'
|
42
|
+
arquia = Bankscrap::Arquia::Bank.new(YOUR_USER, YOUR_PASSWORD, extra_args: {nif: YOUR_NIF})
|
43
|
+
```
|
44
|
+
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
1. Fork it ( https://github.com/bankscrap/bankscrap-arquia/fork )
|
49
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
50
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
51
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
52
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -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/arquia/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'bankscrap-arquia'
|
8
|
+
spec.version = Bankscrap::Arquia::VERSION
|
9
|
+
spec.authors = ['Javier Cuevas']
|
10
|
+
spec.email = ['javi@diacode.com']
|
11
|
+
spec.summary = 'Arquia 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.3'
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
end
|
@@ -0,0 +1,162 @@
|
|
1
|
+
require 'bankscrap'
|
2
|
+
require 'securerandom'
|
3
|
+
|
4
|
+
module Bankscrap
|
5
|
+
module Arquia
|
6
|
+
class Bank < ::Bankscrap::Bank
|
7
|
+
|
8
|
+
# Define the endpoints for the Bank API here
|
9
|
+
BASE_ENDPOINT = 'https://api.arquia.es'.freeze
|
10
|
+
AUTH_ENDPOINT = '/api/Auth'.freeze
|
11
|
+
TOKEN_ENDPOINT = '/token'.freeze
|
12
|
+
USER_ENDPOINT = '/api/user'.freeze
|
13
|
+
PRODUCTS_ENDPOINT = '/api/products'.freeze
|
14
|
+
ACCOUNTS_ENDPOINT = '/api/accounts'.freeze
|
15
|
+
|
16
|
+
def initialize(user, password, log: false, debug: false, extra_args: nil)
|
17
|
+
@user = user
|
18
|
+
@password = password
|
19
|
+
@log = log
|
20
|
+
@debug = debug
|
21
|
+
@nif = extra_args.with_indifferent_access['nif'].dup.upcase
|
22
|
+
|
23
|
+
initialize_connection
|
24
|
+
|
25
|
+
add_headers(
|
26
|
+
'Authorization' => 'Bearer',
|
27
|
+
'api-version' => '2',
|
28
|
+
'Content-Type' => 'application/json; charset=utf-8',
|
29
|
+
'Host' => 'api.arquia.es',
|
30
|
+
'User-Agent' => ''
|
31
|
+
)
|
32
|
+
|
33
|
+
login
|
34
|
+
super
|
35
|
+
end
|
36
|
+
|
37
|
+
# Fetch all the accounts for the given user
|
38
|
+
#
|
39
|
+
# Should returns an array of Bankscrap::Account objects
|
40
|
+
def fetch_accounts
|
41
|
+
# First we need to fetch the products / views for the user
|
42
|
+
|
43
|
+
user_response = JSON.parse(get(BASE_ENDPOINT + USER_ENDPOINT))
|
44
|
+
view = user_response['views'].find { |view| view['type'] == 0}
|
45
|
+
view_id = view['id']
|
46
|
+
|
47
|
+
# Now we get the accounts for that product / view
|
48
|
+
products_response = JSON.parse(get(BASE_ENDPOINT + PRODUCTS_ENDPOINT + "/#{view_id}"))
|
49
|
+
|
50
|
+
# Find which products are accounts
|
51
|
+
products_response.select! do |product|
|
52
|
+
product['$type'] == 'Arquia.Backend.Domain.Models.Entities.Account, Arquia.Backend.Domain.Models'
|
53
|
+
end
|
54
|
+
|
55
|
+
products_response.map { |account| build_account(account) }
|
56
|
+
end
|
57
|
+
|
58
|
+
# Fetch transactions for the given account.
|
59
|
+
#
|
60
|
+
# Account should be a Bankscrap::Account object
|
61
|
+
# Should returns an array of Bankscrap::Account objects
|
62
|
+
def fetch_transactions_for(account, start_date: Date.today - 1.month, end_date: Date.today)
|
63
|
+
from = format_date(start_date)
|
64
|
+
to = format_date(end_date)
|
65
|
+
page = 1
|
66
|
+
transactions = []
|
67
|
+
|
68
|
+
loop do
|
69
|
+
url = BASE_ENDPOINT + ACCOUNTS_ENDPOINT + "/#{account.id}/extract/from/#{from}/to/#{to}/page/#{page}"
|
70
|
+
response = get(url)
|
71
|
+
json = JSON.parse(response)
|
72
|
+
transactions += json.map do |data|
|
73
|
+
build_transaction(data, account)
|
74
|
+
end
|
75
|
+
page += 1
|
76
|
+
break unless json.any?
|
77
|
+
end
|
78
|
+
|
79
|
+
transactions
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
|
84
|
+
def login
|
85
|
+
# First step for login: request keyboard positions
|
86
|
+
params = {
|
87
|
+
"$type" => "Arquia.Backend.Domain.Models.ValueObjects.IdentificationData, Arquia.Backend.Domain.Models",
|
88
|
+
"DocumentId" => @nif,
|
89
|
+
"UserName" => @user
|
90
|
+
}
|
91
|
+
auth_response = JSON.parse(post(BASE_ENDPOINT + AUTH_ENDPOINT, fields: params.to_json))
|
92
|
+
keyboard_order = auth_response['order']
|
93
|
+
required_pw_positions = auth_response['positions']
|
94
|
+
identifier = auth_response['identifier']
|
95
|
+
|
96
|
+
# Second step: get token
|
97
|
+
params = {
|
98
|
+
'client_id' => 'mobilefrontend',
|
99
|
+
'grant_type' => 'password',
|
100
|
+
'documentid' => @nif,
|
101
|
+
'username' => @user,
|
102
|
+
'positions' => get_correct_positions(keyboard_order, required_pw_positions),
|
103
|
+
'ChallengeId' => identifier,
|
104
|
+
'client_version' => '1.1.5'
|
105
|
+
}
|
106
|
+
|
107
|
+
# Note this request is a form type, not a json, that's why we don't use params.to_json
|
108
|
+
token_response = JSON.parse(post(BASE_ENDPOINT + TOKEN_ENDPOINT, fields: params))
|
109
|
+
token = token_response['access_token']
|
110
|
+
|
111
|
+
# Set the token as header for future requests
|
112
|
+
add_headers(
|
113
|
+
'Authorization' => "Bearer #{token}"
|
114
|
+
)
|
115
|
+
end
|
116
|
+
|
117
|
+
# Build an Account object from API data
|
118
|
+
def build_account(data)
|
119
|
+
Account.new(
|
120
|
+
bank: self,
|
121
|
+
id: data['numProd'],
|
122
|
+
name: data['description'],
|
123
|
+
available_balance: data['availableBalance'],
|
124
|
+
balance: data['balance'],
|
125
|
+
currency: 'EUR',
|
126
|
+
iban: data['iban']['ibanCode'],
|
127
|
+
description: data['description']
|
128
|
+
)
|
129
|
+
end
|
130
|
+
|
131
|
+
# Build a transaction object from API data
|
132
|
+
def build_transaction(data, account)
|
133
|
+
Transaction.new(
|
134
|
+
account: account,
|
135
|
+
id: data['id'],
|
136
|
+
amount: Money.new(data['amount'].to_f * 100, 'EUR'),
|
137
|
+
description: data['description'],
|
138
|
+
effective_date: data['valueDate'].to_date, # Format is 2016-05-02T00:00:00
|
139
|
+
currency: 'EUR', # We only know the API returns data['currency'] == 0 for EUR
|
140
|
+
balance: Money.new(data['balance'].to_f * 100, 'EUR')
|
141
|
+
)
|
142
|
+
end
|
143
|
+
|
144
|
+
private
|
145
|
+
|
146
|
+
# Example:
|
147
|
+
# @password = '12345678'
|
148
|
+
# get_correct_positions("4912650378", "03") => "20"
|
149
|
+
# Required position 0 is "1", which matches position 2
|
150
|
+
# Required position 3 is "4", which matches position 0
|
151
|
+
def get_correct_positions(keyboard_order, required_pw_positions)
|
152
|
+
required_pw_positions.chars.collect do |position|
|
153
|
+
keyboard_order.index(@password[position.to_i])
|
154
|
+
end.join
|
155
|
+
end
|
156
|
+
|
157
|
+
def format_date(date)
|
158
|
+
date.strftime('%Y-%m-%d')
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bankscrap-arquia
|
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-05-02 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.3
|
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.3
|
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
|
+
- javi@diacode.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- Gemfile.lock
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bankscrap-arquia.gemspec
|
69
|
+
- lib/bankscrap-arquia.rb
|
70
|
+
- lib/bankscrap/arquia/bank.rb
|
71
|
+
- lib/bankscrap/arquia/version.rb
|
72
|
+
homepage: ''
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.6.4
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Arquia adapter for Bankscrap
|
96
|
+
test_files: []
|