Class: Banks::Csas
- Inherits:
-
Object
- Object
- Banks::Csas
- Defined in:
- lib/banks/csas.rb
Instance Method Summary collapse
- #accounts ⇒ Object
- #ibans ⇒ Object
- #initialize(token, config) ⇒ Csas constructor
- #transaction_get(url, trans, page) ⇒ Object
- #transactions(time_start = nil, time_end = nil, iban = nil) ⇒ Object
Constructor Details
#initialize(token, config) ⇒ Csas
6 7 8 9 |
# File 'lib/banks/csas.rb', line 6 def initialize(token, config) @config = config @token = get_token(token) end |
Instance Method Details
#accounts ⇒ Object
11 12 13 |
# File 'lib/banks/csas.rb', line 11 def accounts JSON.parse(RestClient.get(@config[:base_uri] + '/netbanking/my/accounts', headers), symbolize_keys: true)['accounts'] end |
#ibans ⇒ Object
15 16 17 |
# File 'lib/banks/csas.rb', line 15 def ibans accounts.collect{|ac| ac['accountno']['cz-iban']} end |
#transaction_get(url, trans, page) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/banks/csas.rb', line 31 def transaction_get(url, trans, page) response = JSON.parse(RestClient.get(url+"&page=#{page}", headers), symbolize_keys: true) response['transactions'].each do |tr| trans << { id: tr['id'], date: tr['bookingDate'], amount: tr['amount']['value'], currency: tr['amount']['currency'], account: "#{tr['accountParty']['accountPrefix']}#{tr['accountParty']['accountNumber']}/#{tr['accountParty']['bankCode']}", bank: tr['accountParty']['iban'], name: tr['accountParty']['partyInfo'], variable_symbol: tr['variableSymbol'], message: tr['payeeNote'] } end transaction_get(url, trans, response['nextPage']) if response['nextPage'] != response['pageNumber'] trans end |
#transactions(time_start = nil, time_end = nil, iban = nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/banks/csas.rb', line 19 def transactions(time_start = nil, time_end = nil, iban = nil) url = @config[:base_uri] + '/netbanking/cz/my/accounts/' + iban.to_s + '/transactions' url += "?dateStart=#{time_start.iso8601}" if time_start.present? url += "#{url =~ /\?/ ? '&' : '?'}dateEnd=#{time_end.iso8601}" if time_end.present? # RestClient.log = 'stdout' trans = [] transaction_get(url, trans, 0) trans end |