banktools-de 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f644a79480002d1cd803cd2eae18a277cd12ea8
4
- data.tar.gz: 7bb872deab831e3669c911c4540910a1a02ecf70
3
+ metadata.gz: f345d2155801661ec0ff314f20becde6475fd980
4
+ data.tar.gz: bc5c1b608d90a7d945ef8f7ec3327b39a74f4a16
5
5
  SHA512:
6
- metadata.gz: 3e5fa5cec11896056bb53e7046f636bd978e75c443e4fe9b1a39937f27fd7a870f041d0413b2179b70ec404527b530241267628edb3855328c9c7abc171cbdc5
7
- data.tar.gz: 8f93fb72571d481d5aee6eeb4b50e0cabd08cbb1b7c1486be9d8d15e18f845df2115131d69c1fe69cd928c1d31b5e551e533e62ad6212671969d9618030543b9
6
+ metadata.gz: 95edc5332504a760fa042731c15291d89e17c0573f8fa79b626a9996037c24faad2000aa1bfc6810acc79af4ee19d03f5ac61a5da4686e34d9ea1dc204539fa1
7
+ data.tar.gz: 5564d54c3a56a31fc52eb0b472e0a1824eebc2a1a9f5fa467f65e6a4c8d5f610a0aeabdef7b4a9d023222efbcd045623c34088bfab7f6f39b33907514dd732fa
data/banktools-de.gemspec CHANGED
@@ -18,7 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.require_paths = ["lib"]
19
19
 
20
20
  spec.add_dependency "attr_extras", ">= 4"
21
- spec.add_dependency "ibanomat" # Convert BLZ to IBAN/BIC
21
+ spec.add_dependency "memoit"
22
+ spec.add_dependency "ibanizator" # Convert BLZ to IBAN and lookup BIC from IBAN
22
23
  spec.add_development_dependency "bundler", "~> 1.5"
23
24
  spec.add_development_dependency "rake"
24
25
  spec.add_development_dependency "rspec"
@@ -1,12 +1,12 @@
1
- require "ibanomat"
1
+ require "memoit"
2
+ require "ibanizator"
2
3
  require "attr_extras/explicit"
3
4
 
4
5
  class BankTools::DE::IbanBicConverter
5
6
  extend AttrExtras.mixin
6
7
 
7
- class CouldNotConvertError < StandardError; end
8
- class ServiceUnavailable < StandardError; end
9
- class UnknownError < StandardError; end
8
+ class CouldNotConvertIbanError < StandardError; end
9
+ class CouldNotFindBicError < StandardError; end
10
10
 
11
11
  class IbanBic
12
12
  extend AttrExtras.mixin
@@ -16,27 +16,30 @@ class BankTools::DE::IbanBicConverter
16
16
  method_object [ :blz!, :account! ]
17
17
 
18
18
  def call
19
- account_data = get_account_data
20
- build_result(account_data)
19
+ IbanBic.new(iban, bic)
21
20
  end
22
21
 
23
22
  private
24
23
 
25
- def get_account_data
26
- Ibanomat.find(bank_code: blz, bank_account_number: account)
27
- rescue RestClient::RequestTimeout
28
- raise ServiceUnavailable
29
- rescue
30
- raise UnknownError
24
+ def iban
25
+ iban_object.iban_string
26
+ end
27
+
28
+ def bic
29
+ iban_object.extended_data.bic
30
+ rescue Ibanizator::BankDb::BankNotFoundError => e
31
+ raise CouldNotFindBicError.new(e.message)
31
32
  end
32
33
 
33
- def build_result(account_data)
34
- # Non-"00" values represent an Ibanomat warning or error.
35
- return_code = account_data.fetch(:return_code)
36
- raise CouldNotConvertError unless return_code == "00"
34
+ memoize \
35
+ def iban_object
36
+ iban_string = Ibanizator.new.calculate_iban(country_code: :de, bank_code: blz, account_number: account)
37
+ iban = Ibanizator.iban_from_string(iban_string)
37
38
 
38
- iban = account_data.fetch(:iban)
39
- bic = account_data.fetch(:bic)
40
- IbanBic.new(iban, bic)
39
+ if Ibanizator.iban_from_string(iban).valid?
40
+ iban
41
+ else
42
+ raise CouldNotConvertIbanError.new("Invalid IBAN: #{iban.iban_string}")
43
+ end
41
44
  end
42
45
  end
@@ -1,5 +1,5 @@
1
1
  module BankTools
2
2
  module DE
3
- VERSION = "2.0.0"
3
+ VERSION = "2.1.0"
4
4
  end
5
5
  end
data/spec/account_spec.rb CHANGED
@@ -28,11 +28,11 @@ end
28
28
 
29
29
  describe BankTools::DE::Account, "#valid?" do
30
30
  it "is true with no errors" do
31
- expect(BankTools::DE::Account.new("12").valid?).to be_true
31
+ expect(BankTools::DE::Account.new("12").valid?).to be_truthy
32
32
  end
33
33
 
34
34
  it "is false with errors" do
35
- expect(BankTools::DE::Account.new("1").valid?).to be_false
35
+ expect(BankTools::DE::Account.new("1").valid?).to be_falsy
36
36
  end
37
37
  end
38
38
 
data/spec/blz_spec.rb CHANGED
@@ -19,11 +19,11 @@ end
19
19
 
20
20
  describe BankTools::DE::BLZ, "#valid?" do
21
21
  it "is true with no errors" do
22
- expect(BankTools::DE::BLZ.new("123 456 78").valid?).to be_true
22
+ expect(BankTools::DE::BLZ.new("123 456 78").valid?).to be_truthy
23
23
  end
24
24
 
25
25
  it "is false with errors" do
26
- expect(BankTools::DE::BLZ.new("1").valid?).to be_false
26
+ expect(BankTools::DE::BLZ.new("1").valid?).to be_falsy
27
27
  end
28
28
  end
29
29
 
@@ -2,39 +2,31 @@ require "spec_helper"
2
2
  require "banktools-de/iban_bic"
3
3
 
4
4
  describe BankTools::DE::IbanBicConverter, ".call" do
5
- let(:blz) { "abc" }
6
- let(:account) { "def" }
7
-
8
5
  it "returns the BIC and IBAN" do
9
- allow(Ibanomat).to receive(:find).and_return(iban: "some iban", bic: "some bic", return_code: "00")
6
+ blz = "25050180"
7
+ account = "39370089"
10
8
 
11
9
  actual = BankTools::DE::IbanBicConverter.call(blz: blz, account: account)
12
10
 
13
- expect(actual.iban).to eq("some iban")
14
- expect(actual.bic).to eq("some bic")
15
- end
16
-
17
- it "raises CouldNotConvertError on conversion errors" do
18
- allow(Ibanomat).to receive(:find).and_return(return_code: "1")
19
-
20
- expect {
21
- BankTools::DE::IbanBicConverter.call(blz: blz, account: account)
22
- }.to raise_error(BankTools::DE::IbanBicConverter::CouldNotConvertError)
11
+ expect(actual.iban).to eq("DE53250501800039370089")
12
+ expect(actual.bic).to eq("SPKHDE2HXXX")
23
13
  end
24
14
 
25
- it "raises ServiceUnavailable when the service is down" do
26
- allow(Ibanomat).to receive(:find).and_raise(RestClient::RequestTimeout)
15
+ it "raises CouldNotConvertIbanError on IBAN conversion errors" do
16
+ blz = "abc"
17
+ account = "def"
27
18
 
28
19
  expect {
29
20
  BankTools::DE::IbanBicConverter.call(blz: blz, account: account)
30
- }.to raise_error(BankTools::DE::IbanBicConverter::ServiceUnavailable)
21
+ }.to raise_error(BankTools::DE::IbanBicConverter::CouldNotConvertIbanError)
31
22
  end
32
23
 
33
- it "raises UnknownError on other errors" do
34
- allow(Ibanomat).to receive(:find).and_raise("unknown error")
24
+ it "raises CouldNotFindBicError on find BIC errors" do
25
+ blz = "21050171"
26
+ account = "12345678"
35
27
 
36
28
  expect {
37
29
  BankTools::DE::IbanBicConverter.call(blz: blz, account: account)
38
- }.to raise_error(BankTools::DE::IbanBicConverter::UnknownError)
30
+ }.to raise_error(BankTools::DE::IbanBicConverter::CouldNotFindBicError)
39
31
  end
40
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: banktools-de
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henrik Nyh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-15 00:00:00.000000000 Z
11
+ date: 2015-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: attr_extras
@@ -25,7 +25,21 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '4'
27
27
  - !ruby/object:Gem::Dependency
28
- name: ibanomat
28
+ name: memoit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: ibanizator
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - ">="
@@ -139,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
153
  version: '0'
140
154
  requirements: []
141
155
  rubyforge_project:
142
- rubygems_version: 2.2.2
156
+ rubygems_version: 2.4.8
143
157
  signing_key:
144
158
  specification_version: 4
145
159
  summary: Validate and normalize German Bankleitzahl (BLZ) and bank account numbers.