czech_banks_parser 0.0.1 → 0.0.2
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/.gitignore +1 -1
- data/README.md +96 -0
- data/czech_banks_parser.gemspec +1 -1
- data/lib/banks/csas.rb +31 -6
- data/lib/banks/fio.rb +1 -1
- data/lib/czech_banks_parser.rb +7 -4
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02b6f09487b8f5996d133e6508414c3b87c837e4
|
4
|
+
data.tar.gz: a46b19f3a24957b2cc3f38f204a82efc4c20c85e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65d26cfa0eb74655f38c81bbea70776226a47cc1f12bac70fb05aa717140d68802272ac98b32aa16ece3d882a58cffec94baeb0700889030ef33422cd220ab92
|
7
|
+
data.tar.gz: 942d9c93d29a309e7be7b06658699e7ffaf07ac3f81c8dfeb450a5967e5a7bc55d9dbedbddf40148d6042664461067b43f54baf17d0fe3758ca67bf3f3e6fee2
|
data/.gitignore
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
.idea
|
2
|
-
|
2
|
+
*.gem
|
data/README.md
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
Connect Czech banks FIO and CSAS with your Ruby application
|
2
|
+
|
3
|
+
# Initializing API
|
4
|
+
|
5
|
+
### FIO:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
|
9
|
+
token = 'sdiohsiodgsr75rg7e8r7gh' # FIO bank token
|
10
|
+
|
11
|
+
@parser = CzechBanksParser.new.connect(token, 'fio')
|
12
|
+
|
13
|
+
```
|
14
|
+
|
15
|
+
### CSAS:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
|
19
|
+
token = 'sdiohsiodgsr75rg7e8r7gh' # CSAS Oauth2 refresh token
|
20
|
+
|
21
|
+
opts = {}
|
22
|
+
opts[:web_api_key] = CSAS_WEB_API_KEY
|
23
|
+
opts[:client_id] = CSAS_CLIENT_ID
|
24
|
+
opts[:secret] = CSAS_SECRET
|
25
|
+
otps[:mode] = 'production' # or sandbox
|
26
|
+
|
27
|
+
@parser = CzechBanksParser.new(opts).connect(token, 'csas')
|
28
|
+
|
29
|
+
```
|
30
|
+
|
31
|
+
|
32
|
+
# Downloading transactions
|
33
|
+
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
|
37
|
+
date_from = Date.today - 1.week
|
38
|
+
date_to = Date.today
|
39
|
+
iban = 'CZ8788665897' # important only for CSAS
|
40
|
+
|
41
|
+
@parser.transactions(date_from, date_to, iban).each do |tr|
|
42
|
+
# output: {trans_id: tr[:id], variable_symbol: tr[:variable_symbol], date: tr[:date], amount: tr[:amount], currency: tr[:currency], from_account: tr[:account], bank: tr[:bank], name: tr[:name], message: tr[:message]}
|
43
|
+
end
|
44
|
+
|
45
|
+
```
|
46
|
+
|
47
|
+
# Other
|
48
|
+
|
49
|
+
### Obtaining CSAS refresh token
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
|
53
|
+
class BankTokensController < ApplicationController
|
54
|
+
load_resource :account
|
55
|
+
load_resource through: :account
|
56
|
+
|
57
|
+
def auth
|
58
|
+
config = parser.config(params[:state])
|
59
|
+
redirect_to "#{config[:auth_uri]}?state=profil&redirect_uri=#{callback_account_bank_tokens_url(@account)}&client_id=#{config[:client_id]}&response_type=code&access_type=offline"
|
60
|
+
end
|
61
|
+
|
62
|
+
def callback
|
63
|
+
config = parser.config('csas')
|
64
|
+
redirect_to "#{config[:token_uri]}?grant_type=authorization_code&code=#{params[:code]}&client_id=#{config[:client_id]}&client_secret=#{config[:secret]}&redirect_uri=#{get_token_account_bank_tokens_url(@account)}&state=csas"
|
65
|
+
end
|
66
|
+
|
67
|
+
def get_token
|
68
|
+
if params[:refresh_token].present?
|
69
|
+
|
70
|
+
ibans = parser.connect(params[:refresh_token], 'csas').ibans # get accounts ibans from CSAS
|
71
|
+
|
72
|
+
if ibans.include?(@account.bank_account.iban)
|
73
|
+
bt = @account.bank_tokens.new(bank: 'csas', token: params[:refresh_token], active: true)
|
74
|
+
bt.save!
|
75
|
+
redirect_to accounts_path, notice: t('bank_account_connected')
|
76
|
+
else
|
77
|
+
flash[:error] = t('no_iban_match', iban: @account.bank_account.iban, ibans: ibans.join(', '))
|
78
|
+
redirect_to accounts_path
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def parser
|
86
|
+
CzechBanksParser.new({web_api_key: CSAS_WEB_API_KEY, client_id: CSAS_CLIENT_ID, secret: CSAS_SECRET})
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
```
|
93
|
+
|
94
|
+
# About
|
95
|
+
|
96
|
+
© Author: Richard Lapiš
|
data/czech_banks_parser.gemspec
CHANGED
data/lib/banks/csas.rb
CHANGED
@@ -9,19 +9,44 @@ module Banks
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def accounts
|
12
|
-
JSON.parse(RestClient.get(@config[:base_uri] + '/netbanking/my/accounts', headers),
|
12
|
+
JSON.parse(RestClient.get(@config[:base_uri] + '/netbanking/my/accounts', headers), symbolize_keys: true)['accounts']
|
13
13
|
end
|
14
14
|
|
15
15
|
def ibans
|
16
|
-
accounts.collect{|ac| ac[
|
16
|
+
accounts.collect{|ac| ac['accountno']['cz-iban']}
|
17
17
|
end
|
18
18
|
|
19
19
|
def transactions(time_start = nil, time_end = nil, iban = nil)
|
20
|
-
url = @config[:base_uri] + '/netbanking/my/accounts/' + iban.to_s + '/transactions'
|
20
|
+
url = @config[:base_uri] + '/netbanking/cz/my/accounts/' + iban.to_s + '/transactions'
|
21
21
|
url += "?dateStart=#{time_start.iso8601}" if time_start.present?
|
22
22
|
url += "#{url =~ /\?/ ? '&' : '?'}dateEnd=#{time_end.iso8601}" if time_end.present?
|
23
23
|
|
24
|
-
|
24
|
+
# RestClient.log = 'stdout'
|
25
|
+
|
26
|
+
trans = []
|
27
|
+
transaction_get(url, trans, 0)
|
28
|
+
trans
|
29
|
+
end
|
30
|
+
|
31
|
+
def transaction_get(url, trans, page)
|
32
|
+
response = JSON.parse(RestClient.get(url+"&page=#{page}", headers), symbolize_keys: true)
|
33
|
+
|
34
|
+
response['transactions'].each do |tr|
|
35
|
+
trans << {
|
36
|
+
id: tr['id'],
|
37
|
+
date: tr['bookingDate'],
|
38
|
+
amount: tr['amount']['value'],
|
39
|
+
currency: tr['amount']['currency'],
|
40
|
+
account: "#{tr['accountParty']['accountPrefix']}#{tr['accountParty']['accountNumber']}/#{tr['accountParty']['bankCode']}",
|
41
|
+
bank: tr['accountParty']['iban'],
|
42
|
+
name: tr['accountParty']['partyInfo'],
|
43
|
+
variable_symbol: tr['variableSymbol'],
|
44
|
+
message: tr['payeeNote']
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
transaction_get(url, trans, response['nextPage']) if response['nextPage'] != response['pageNumber']
|
49
|
+
trans
|
25
50
|
end
|
26
51
|
|
27
52
|
private
|
@@ -31,8 +56,8 @@ module Banks
|
|
31
56
|
end
|
32
57
|
|
33
58
|
def get_token(token)
|
34
|
-
response = RestClient.post @config[:token_uri], {grant_type: 'refresh_token', client_id: @config[:client_id], client_secret: @config[:secret], refresh_token: token}
|
35
|
-
JSON.parse(response,
|
59
|
+
response = RestClient.post @config[:token_uri], {grant_type: 'refresh_token', client_id: @config[:client_id], redirect_uri: '/', client_secret: @config[:secret], refresh_token: token}, content_type: 'application/x-www-form-urlencoded'
|
60
|
+
JSON.parse(response, symbolize_keys: true)['access_token']
|
36
61
|
end
|
37
62
|
end
|
38
63
|
end
|
data/lib/banks/fio.rb
CHANGED
@@ -6,7 +6,7 @@ module Banks
|
|
6
6
|
@token = token
|
7
7
|
end
|
8
8
|
|
9
|
-
def transactions(time_start, time_end, iban)
|
9
|
+
def transactions(time_start, time_end, iban = nil)
|
10
10
|
url = "#{@config[:base_uri]}/periods/#{@token}/#{time_start.strftime('%Y-%m-%d')}/#{time_end.strftime('%Y-%m-%d')}/transactions.json"
|
11
11
|
|
12
12
|
trans = []
|
data/lib/czech_banks_parser.rb
CHANGED
@@ -3,8 +3,11 @@ require 'banks/fio.rb'
|
|
3
3
|
require 'banks/csas.rb'
|
4
4
|
|
5
5
|
class CzechBanksParser
|
6
|
-
def initialize(
|
6
|
+
def initialize(opts = {})
|
7
7
|
@opts = opts
|
8
|
+
end
|
9
|
+
|
10
|
+
def connect(token, bank)
|
8
11
|
case bank
|
9
12
|
when 'csas' then Banks::Csas.new(token, config('csas'))
|
10
13
|
when 'fio' then Banks::Fio.new(token, config('fio'))
|
@@ -16,9 +19,9 @@ class CzechBanksParser
|
|
16
19
|
case state
|
17
20
|
when 'csas'
|
18
21
|
{
|
19
|
-
base_uri: 'https://
|
20
|
-
auth_uri: 'https://
|
21
|
-
token_uri: 'https://
|
22
|
+
base_uri: @opts[:mode] == 'production' ? '' : 'https://www.csast.csas.cz/webapi/api/v3',
|
23
|
+
auth_uri: @opts[:mode] == 'production' ? '' : 'https://www.csast.csas.cz/widp/oauth2/auth',
|
24
|
+
token_uri: @opts[:mode] == 'production' ? '' : 'https://www.csast.csas.cz/widp/oauth2/token',
|
22
25
|
client_id: @opts[:client_id],
|
23
26
|
secret: @opts[:secret],
|
24
27
|
web_api_key: @opts[:web_api_key]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: czech_banks_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Lapiš
|
@@ -14,20 +14,20 @@ dependencies:
|
|
14
14
|
name: rest-client
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 1.6.7
|
20
|
-
- -
|
20
|
+
- - '>='
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: 1.6.7
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: 1.6.7
|
30
|
-
- -
|
30
|
+
- - '>='
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 1.6.7
|
33
33
|
description: A parser from Czech Banks API's - CSAS, FIO
|
@@ -36,7 +36,8 @@ executables: []
|
|
36
36
|
extensions: []
|
37
37
|
extra_rdoc_files: []
|
38
38
|
files:
|
39
|
-
-
|
39
|
+
- .gitignore
|
40
|
+
- README.md
|
40
41
|
- czech_banks_parser.gemspec
|
41
42
|
- lib/banks/csas.rb
|
42
43
|
- lib/banks/fio.rb
|
@@ -51,12 +52,12 @@ require_paths:
|
|
51
52
|
- lib
|
52
53
|
required_ruby_version: !ruby/object:Gem::Requirement
|
53
54
|
requirements:
|
54
|
-
- -
|
55
|
+
- - '>='
|
55
56
|
- !ruby/object:Gem::Version
|
56
57
|
version: 2.0.0
|
57
58
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
59
|
requirements:
|
59
|
-
- -
|
60
|
+
- - '>='
|
60
61
|
- !ruby/object:Gem::Version
|
61
62
|
version: '0'
|
62
63
|
requirements: []
|