czech_banks_parser 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 90760afe5261a775da7b946a741ee042e2b5cd77
4
+ data.tar.gz: 5cc2a10717afe03b300b1d9a3ff5aed07b36ceb1
5
+ SHA512:
6
+ metadata.gz: ecdf88d215ded20ef1d3fd9053dd076099351cc11a21df63c68f5b8df18dd7dc21db61fb22ee58068397148ea12a8e90b940936655cefe168a0d945146e75b38
7
+ data.tar.gz: 37bc9c921fce49d6a3863a814a833590d5d1466254d121385bba532aaab7cfd7b179f132c87161cb0b7f5df8cb82ea5d7ec1c52dd5f541b47e10d31f06b318f5
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ .idea
2
+ .gem
@@ -0,0 +1,31 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "czech_banks_parser"
3
+ s.version = "0.0.1"
4
+ s.default_executable = "czech_banks_parser"
5
+ s.platform = Gem::Platform::RUBY
6
+ s.required_ruby_version = '>= 2.0.0'
7
+
8
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
+ s.authors = ["Richard Lapiš"]
10
+ s.date = %q{2016-09-30}
11
+ s.description = %q{A parser from Czech Banks API's - CSAS, FIO}
12
+ s.email = %q{richard.lapis@gmail.com}
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = []
15
+ s.homepage = %q{https://github.com/richardrails/czech_banks_parser}
16
+ s.require_paths = ["lib"]
17
+ s.rubygems_version = %q{1.6.2}
18
+ s.summary = %q{A parser from Czech Banks API's}
19
+ s.license = 'MIT'
20
+
21
+ s.add_runtime_dependency("rest-client", "~> 1.6.7", ">= 1.6.7")
22
+
23
+ if s.respond_to? :specification_version then
24
+ s.specification_version = 3
25
+
26
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
27
+ else
28
+ end
29
+ else
30
+ end
31
+ end
data/lib/banks/csas.rb ADDED
@@ -0,0 +1,38 @@
1
+ module Banks
2
+ class Csas
3
+ # 7777777777
4
+ # https://help.salesforce.com/apex/HTViewHelpDoc?id=remoteaccess_oauth_refresh_token_flow.htm&language=en_US
5
+
6
+ def initialize(token, config)
7
+ @config = config
8
+ @token = get_token(token)
9
+ end
10
+
11
+ def accounts
12
+ JSON.parse(RestClient.get(@config[:base_uri] + '/netbanking/my/accounts', headers), symbolize_names: true)[:accounts]
13
+ end
14
+
15
+ def ibans
16
+ accounts.collect{|ac| ac[:accountno][:iban]}
17
+ end
18
+
19
+ def transactions(time_start = nil, time_end = nil, iban = nil)
20
+ url = @config[:base_uri] + '/netbanking/my/accounts/' + iban.to_s + '/transactions'
21
+ url += "?dateStart=#{time_start.iso8601}" if time_start.present?
22
+ url += "#{url =~ /\?/ ? '&' : '?'}dateEnd=#{time_end.iso8601}" if time_end.present?
23
+
24
+ JSON.parse RestClient.get(url, headers), symbolize_names: true
25
+ end
26
+
27
+ private
28
+
29
+ def headers
30
+ {'WEB-API-key' => @config[:web_api_key], 'Authorization' => "Bearer #{@token}", accept: :json}
31
+ end
32
+
33
+ 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, symbolize_names: true)[:access_token]
36
+ end
37
+ end
38
+ end
data/lib/banks/fio.rb ADDED
@@ -0,0 +1,30 @@
1
+ module Banks
2
+ class Fio
3
+
4
+ def initialize(token, config)
5
+ @config = config
6
+ @token = token
7
+ end
8
+
9
+ def transactions(time_start, time_end, iban)
10
+ url = "#{@config[:base_uri]}/periods/#{@token}/#{time_start.strftime('%Y-%m-%d')}/#{time_end.strftime('%Y-%m-%d')}/transactions.json"
11
+
12
+ trans = []
13
+ JSON.parse(RestClient.get(url), symbolize_names: true)[:accountStatement][:transactionList][:transaction].each do |tr|
14
+ trans << {
15
+ id: tr[:column22].try(:[], :value),
16
+ date: tr[:column0].try(:[], :value),
17
+ amount: tr[:column1].try(:[], :value),
18
+ currency: tr[:column14].try(:[], :value),
19
+ account: "#{tr[:column2].try(:[], :value)}/#{tr[:column3].try(:[], :value)}",
20
+ bank: tr[:column12].try(:[], :value),
21
+ name: tr[:column7].try(:[], :value) || tr[:column9].try(:[], :value),
22
+ variable_symbol: tr[:column5].try(:[], :value),
23
+ message: tr[:column16].try(:[], :value)
24
+ }
25
+ end
26
+ trans
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,32 @@
1
+ require 'rest-client'
2
+ require 'banks/fio.rb'
3
+ require 'banks/csas.rb'
4
+
5
+ class CzechBanksParser
6
+ def initialize(token, bank, opts = {})
7
+ @opts = opts
8
+ case bank
9
+ when 'csas' then Banks::Csas.new(token, config('csas'))
10
+ when 'fio' then Banks::Fio.new(token, config('fio'))
11
+ else raise(NotImplementedError)
12
+ end
13
+ end
14
+
15
+ def config(state)
16
+ case state
17
+ when 'csas'
18
+ {
19
+ base_uri: 'https://api.csas.cz/sandbox/webapi/api/v1',
20
+ auth_uri: 'https://api.csas.cz/sandbox/widp/oauth2/auth',
21
+ token_uri: 'https://api.csas.cz/sandbox/widp/oauth2/token',
22
+ client_id: @opts[:client_id],
23
+ secret: @opts[:secret],
24
+ web_api_key: @opts[:web_api_key]
25
+ }
26
+ when 'fio'
27
+ {
28
+ base_uri: 'https://www.fio.cz/ib_api/rest'
29
+ }
30
+ end
31
+ end
32
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: czech_banks_parser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Richard Lapiš
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.6.7
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.6.7
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: 1.6.7
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.6.7
33
+ description: A parser from Czech Banks API's - CSAS, FIO
34
+ email: richard.lapis@gmail.com
35
+ executables: []
36
+ extensions: []
37
+ extra_rdoc_files: []
38
+ files:
39
+ - ".gitignore"
40
+ - czech_banks_parser.gemspec
41
+ - lib/banks/csas.rb
42
+ - lib/banks/fio.rb
43
+ - lib/czech_banks_parser.rb
44
+ homepage: https://github.com/richardrails/czech_banks_parser
45
+ licenses:
46
+ - MIT
47
+ metadata: {}
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 2.0.0
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project:
64
+ rubygems_version: 2.4.8
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: A parser from Czech Banks API's
68
+ test_files: []