sepa_clearer 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +13 -7
- data/data/deutsche_bundesbank.db +0 -0
- data/lib/sepa_clearer/clearer.rb +47 -5
- data/lib/sepa_clearer/deutsche_bundesbank.rb +10 -11
- data/lib/sepa_clearer/payment_provider.rb +23 -5
- data/lib/sepa_clearer/version.rb +1 -1
- data/sepa-clearer.gemspec +1 -0
- data/spec/clearer_spec.rb +5 -1
- data/spec/deutsche_bundesbank_spec.rb +9 -5
- data/spec/payment_provider_spec.rb +30 -3
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cbd32af62350c9dfef2b8ff7cd7a694d1619716b
|
4
|
+
data.tar.gz: 5e93b7e97b94e34c3c45e7ae66b250e860676f29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd98140704cdd382443eaec4db7c95003b1ed393a12a137eff2eae2ea377be2fbe05de044af4b50da20750da36a75969b6e1b4bd22342849202490ff719a0fd4
|
7
|
+
data.tar.gz: 0dc263db105322307eeac665494ad5ebab9ca8a20b8e3fd105122f626d63833eefcc77e9c1102e292cce4caffcc5fcdc7c96d517e69714973ef6c202a4a82b3e
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -5,15 +5,16 @@ system. The gem currently supports only "Deutsche Bundesbank" as a clearer. You
|
|
5
5
|
can fetch all providers and their capabilities or fetch only a unique provider
|
6
6
|
by his BIC.
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
The gem comes with a sqlite3 database which contains all data. In order to access
|
9
|
+
it, you need to have sqlite3 installed.
|
10
10
|
|
11
|
+
__Last data update: 2014-07-07__
|
11
12
|
|
12
13
|
## Installation
|
13
14
|
|
14
15
|
Add this line to your application's Gemfile:
|
15
16
|
|
16
|
-
gem '
|
17
|
+
gem 'sepa_clearer'
|
17
18
|
|
18
19
|
And then execute:
|
19
20
|
|
@@ -21,21 +22,26 @@ And then execute:
|
|
21
22
|
|
22
23
|
Or install it yourself as:
|
23
24
|
|
24
|
-
$ gem install
|
25
|
+
$ gem install sepa_clearer
|
25
26
|
|
26
27
|
|
27
28
|
## Usage
|
29
|
+
require 'sepa_clearer'
|
28
30
|
|
29
31
|
# Create a new cleaer instance
|
30
|
-
clearer = SepaClearer::Clearer.new
|
32
|
+
clearer = SepaClearer::Clearer.new
|
31
33
|
|
32
34
|
# Fetch all payment providers
|
33
35
|
clearer.all
|
34
36
|
# => [<PaymentProvider: …>, <PaymentProvider: …>]
|
35
37
|
|
36
38
|
# Fetch a single provider by his identifier code. The BIC is normalized (uppercase and 11 letters filled with X)
|
37
|
-
clearer.find_by_bic('DEIRGENDWAS')
|
38
|
-
# => <PaymentProvider: @bic="DEIRGENDWAS", @name="
|
39
|
+
provider = clearer.find_by_bic('DEIRGENDWAS')
|
40
|
+
# => <PaymentProvider: @bic="DEIRGENDWAS", @name="YOUR PROVIDER", @sct=false, @core=true, @cor1=true, @b2b=false>
|
41
|
+
|
42
|
+
# Get all capabilities
|
43
|
+
provider.capabilities
|
44
|
+
# => [:core, :cor1]
|
39
45
|
|
40
46
|
|
41
47
|
## Update clearer list
|
Binary file
|
data/lib/sepa_clearer/clearer.rb
CHANGED
@@ -1,20 +1,62 @@
|
|
1
|
+
require 'sqlite3'
|
2
|
+
|
1
3
|
module SepaClearer
|
2
4
|
class Clearer
|
3
|
-
|
4
|
-
|
5
|
+
attr_accessor :db
|
6
|
+
|
7
|
+
# Make sure we always have the correct order of columns
|
8
|
+
ATTRIBUTES = [:name, :bic, :sct, :core, :cor1, :b2b]
|
9
|
+
|
10
|
+
def initialize(db_name = 'deutsche_bundesbank')
|
11
|
+
self.db = SQLite3::Database.new File.join(File.dirname(__FILE__), '../..', "data/#{db_name}.db")
|
12
|
+
end
|
13
|
+
|
14
|
+
def add(provider)
|
15
|
+
data = boolean_to_integers(provider.to_a)
|
16
|
+
db.execute "INSERT INTO payment_providers (#{ATTRIBUTES.join(',')}) VALUES (?, ?, ?, ?, ?, ?)", data
|
5
17
|
end
|
6
18
|
|
7
19
|
def all
|
8
|
-
|
20
|
+
db.execute("SELECT #{ATTRIBUTES.join(',')} FROM payment_providers ORDER BY name").map do |row|
|
21
|
+
PaymentProvider.new(hash_from_result(row))
|
22
|
+
end
|
9
23
|
end
|
10
24
|
|
11
25
|
def find_by_bic(bic)
|
12
|
-
|
13
|
-
|
26
|
+
db.execute("SELECT #{ATTRIBUTES.join(',')} FROM payment_providers WHERE bic = ?", normalize_bic(bic)).map do |row|
|
27
|
+
PaymentProvider.new(hash_from_result(row))
|
28
|
+
end.first
|
14
29
|
end
|
15
30
|
|
16
31
|
def normalize_bic(bic)
|
17
32
|
bic.to_s.ljust(11, 'X').upcase
|
18
33
|
end
|
34
|
+
|
35
|
+
protected
|
36
|
+
|
37
|
+
def hash_from_result(raw_array)
|
38
|
+
raw_array_with_boolean = integers_to_boolean(raw_array)
|
39
|
+
Hash[ATTRIBUTES.zip(raw_array_with_boolean)]
|
40
|
+
end
|
41
|
+
|
42
|
+
def boolean_to_integers(array)
|
43
|
+
array.map do |element|
|
44
|
+
if element.kind_of?(TrueClass) || element.kind_of?(FalseClass)
|
45
|
+
element ? 1 : 0
|
46
|
+
else
|
47
|
+
element
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def integers_to_boolean(array)
|
53
|
+
array.map do |element|
|
54
|
+
if element.kind_of?(Integer)
|
55
|
+
element == 1
|
56
|
+
else
|
57
|
+
element
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
19
61
|
end
|
20
62
|
end
|
@@ -2,12 +2,12 @@ require 'csv'
|
|
2
2
|
|
3
3
|
module SepaClearer
|
4
4
|
class DeutscheBundesbank
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
MAPPING = {
|
6
|
+
service_sct: :sct,
|
7
|
+
service_sdd: :core,
|
8
|
+
service_cor1: :cor1,
|
9
|
+
service_b2b: :b2b
|
10
|
+
}
|
11
11
|
|
12
12
|
def data(file = nil)
|
13
13
|
@data ||= begin
|
@@ -20,11 +20,10 @@ module SepaClearer
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def parse_raw_data(data)
|
23
|
-
[
|
24
|
-
data[:name].strip.chomp,
|
25
|
-
data[:bic],
|
26
|
-
|
27
|
-
]
|
23
|
+
MAPPING.reduce({}) { |hsh,(key, service)| hsh[service] = (data[key] == '1'); hsh }.merge({
|
24
|
+
name: data[:name].strip.chomp,
|
25
|
+
bic: data[:bic].strip.chomp,
|
26
|
+
})
|
28
27
|
end
|
29
28
|
|
30
29
|
def default_data_file
|
@@ -2,12 +2,30 @@ module SepaClearer
|
|
2
2
|
class PaymentProvider
|
3
3
|
SERVICES = [:sct, :core, :cor1, :b2b]
|
4
4
|
|
5
|
-
attr_accessor :name, :bic, :
|
5
|
+
attr_accessor :name, :bic, :sct, :core, :cor1, :b2b
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
self.name = name
|
9
|
-
self.bic = bic
|
10
|
-
self.
|
7
|
+
def initialize(options = {})
|
8
|
+
self.name = options[:name]
|
9
|
+
self.bic = options[:bic]
|
10
|
+
self.sct = options[:sct] || false
|
11
|
+
self.core = options[:core] || false
|
12
|
+
self.cor1 = options[:cor1] || false
|
13
|
+
self.b2b = options[:b2b] || false
|
14
|
+
end
|
15
|
+
|
16
|
+
def capabilities
|
17
|
+
SERVICES.map { |s| [s, send(s)] }.select { |_,v| v }.map { |k,v| k }
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_hash
|
21
|
+
{
|
22
|
+
name: name,
|
23
|
+
bic: bic,
|
24
|
+
sct: sct,
|
25
|
+
core: core,
|
26
|
+
cor1: cor1,
|
27
|
+
b2b: b2b,
|
28
|
+
}
|
11
29
|
end
|
12
30
|
end
|
13
31
|
end
|
data/lib/sepa_clearer/version.rb
CHANGED
data/sepa-clearer.gemspec
CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
+
spec.add_dependency "sqlite3"
|
21
22
|
spec.add_development_dependency "bundler", "~> 1.6"
|
22
23
|
spec.add_development_dependency "rake", "~> 0"
|
23
24
|
spec.add_development_dependency "rspec", "~> 3"
|
data/spec/clearer_spec.rb
CHANGED
@@ -16,11 +16,15 @@ describe SepaClearer::Clearer do
|
|
16
16
|
expect(subject.find_by_bic('MYTHINGY')).to eq(nil)
|
17
17
|
end
|
18
18
|
|
19
|
-
it 'normalizes
|
19
|
+
it 'normalizes the bic before searching' do
|
20
20
|
allow(subject).to receive(:normalize_bic).and_return('AAA')
|
21
21
|
expect(subject.find_by_bic('MYTHINGY')).to eq(nil)
|
22
22
|
expect(subject).to have_received(:normalize_bic)
|
23
23
|
end
|
24
|
+
|
25
|
+
it 'returns an initialize object' do
|
26
|
+
expect(subject.find_by_bic('AABAFI22TMS').name).to eq('BANK OF ALAND PLC')
|
27
|
+
end
|
24
28
|
end
|
25
29
|
|
26
30
|
describe '#normalize_bic' do
|
@@ -3,20 +3,24 @@ require 'spec_helper'
|
|
3
3
|
describe SepaClearer::DeutscheBundesbank do
|
4
4
|
describe '#parse_raw_data' do
|
5
5
|
let(:data) { { name: "My Org \n", bic: 'QWERTZ12345', service_sct: '1' } }
|
6
|
-
|
7
|
-
|
6
|
+
|
7
|
+
it 'returns a hash' do
|
8
|
+
expect(subject.parse_raw_data(data)).to be_kind_of(Hash)
|
8
9
|
end
|
9
10
|
|
10
11
|
it 'cleans up the name' do
|
11
|
-
expect(subject.parse_raw_data(data)[
|
12
|
+
expect(subject.parse_raw_data(data)[:name]).to eq('My Org')
|
12
13
|
end
|
13
14
|
|
14
15
|
it 'returns the BIC' do
|
15
|
-
expect(subject.parse_raw_data(data)[
|
16
|
+
expect(subject.parse_raw_data(data)[:bic]).to eq('QWERTZ12345')
|
16
17
|
end
|
17
18
|
|
18
19
|
it 'maps the capabilities' do
|
19
|
-
expect(subject.parse_raw_data(data)[
|
20
|
+
expect(subject.parse_raw_data(data)[:sct]).to eq(true)
|
21
|
+
expect(subject.parse_raw_data(data)[:core]).to eq(false)
|
22
|
+
expect(subject.parse_raw_data(data)[:cor1]).to eq(false)
|
23
|
+
expect(subject.parse_raw_data(data)[:b2b]).to eq(false)
|
20
24
|
end
|
21
25
|
end
|
22
26
|
end
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe SepaClearer::PaymentProvider do
|
4
4
|
describe '.new' do
|
5
|
-
subject(:provider) { described_class.new('Testorg', 'SOMEVALIDID'
|
5
|
+
subject(:provider) { described_class.new(name: 'Testorg', bic: 'SOMEVALIDID') }
|
6
6
|
|
7
7
|
it 'sets the proper name' do
|
8
8
|
expect(provider.name).to eq('Testorg')
|
@@ -12,8 +12,35 @@ describe SepaClearer::PaymentProvider do
|
|
12
12
|
expect(provider.bic).to eq('SOMEVALIDID')
|
13
13
|
end
|
14
14
|
|
15
|
-
it '
|
16
|
-
expect(provider.capabilities).to eq([
|
15
|
+
it 'does not set any capabilities' do
|
16
|
+
expect(provider.capabilities).to eq([])
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#capabilities' do
|
21
|
+
subject(:provider) { described_class.new(sct: true, core: false, cor1: true, b2b: true) }
|
22
|
+
|
23
|
+
it 'returns all capabilities' do
|
24
|
+
expect(provider.capabilities).to eq([:sct, :cor1, :b2b])
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#to_hash' do
|
29
|
+
subject(:provider) { described_class.new(name: 'test', bic: 'bic', sct: true, core: false, cor1: true, b2b: true) }
|
30
|
+
|
31
|
+
it 'returns a hash' do
|
32
|
+
expect(provider.to_hash).to be_kind_of(Hash)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'sets correct values' do
|
36
|
+
expect(provider.to_hash).to match({
|
37
|
+
name: 'test',
|
38
|
+
bic: 'bic',
|
39
|
+
sct: true,
|
40
|
+
core: false,
|
41
|
+
cor1: true,
|
42
|
+
b2b: true
|
43
|
+
})
|
17
44
|
end
|
18
45
|
end
|
19
46
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sepa_clearer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maximilian Schulz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sqlite3
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -69,6 +83,7 @@ files:
|
|
69
83
|
- Rakefile
|
70
84
|
- bin/update_data
|
71
85
|
- data/deutsche_bundesbank.csv
|
86
|
+
- data/deutsche_bundesbank.db
|
72
87
|
- lib/sepa_clearer.rb
|
73
88
|
- lib/sepa_clearer/clearer.rb
|
74
89
|
- lib/sepa_clearer/deutsche_bundesbank.rb
|