iban_calculator 0.1.1 → 0.2.1
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/.travis.yml +6 -0
- data/CHANGELOG.md +8 -0
- data/README.md +2 -0
- data/iban_calculator.gemspec +1 -1
- data/lib/iban_calculator.rb +10 -6
- data/lib/iban_calculator/active_support.rb +35 -0
- data/lib/iban_calculator/iban_bic.rb +8 -7
- data/lib/iban_calculator/version.rb +1 -1
- data/spec/iban_bic_spec.rb +14 -1
- data/spec/iban_calculator_spec.rb +10 -0
- metadata +9 -7
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 8f9d8247ec70deaea3ad00409ad0fff286c12ed3
         | 
| 4 | 
            +
              data.tar.gz: 8351ce3d19b71e9f374f9cc38adb2335e6f84524
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 32dc7daebab254668bb75e6033d7402a652cb972a6a375b20df6be913edf16859916ef3835869b026af73a5f67e6ed2b2fd839df82d9dad6ce99d1363411bb73
         | 
| 7 | 
            +
              data.tar.gz: 67bc127a1c0aee343876467836543f1312e5de1fd166e631e77f18a63f51be76dc34d7bf3a4c924ae1445bc4bbf10106830510ba3a2a6dde7e8de35122a1c8d8
         | 
    
        data/.travis.yml
    ADDED
    
    
    
        data/CHANGELOG.md
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -1,3 +1,5 @@ | |
| 1 | 
            +
            [](https://travis-ci.org/railslove/iban_calculator)
         | 
| 2 | 
            +
             | 
| 1 3 | 
             
            # IbanCalculator
         | 
| 2 4 |  | 
| 3 5 | 
             
            A wrapper for ibanrechner.de API. It allows converting bank account data from legacy syntax to new SEPA IBAN/BIC.
         | 
    
        data/iban_calculator.gemspec
    CHANGED
    
    | @@ -18,7 +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 "activesupport", " | 
| 21 | 
            +
              spec.add_dependency "activesupport", ">= 3"
         | 
| 22 22 | 
             
              spec.add_dependency "savon", "~> 2"
         | 
| 23 23 |  | 
| 24 24 | 
             
              spec.add_development_dependency "bundler", "~> 1.6"
         | 
    
        data/lib/iban_calculator.rb
    CHANGED
    
    | @@ -1,4 +1,5 @@ | |
| 1 1 | 
             
            require 'iban_calculator/version'
         | 
| 2 | 
            +
            require 'active_support/version'
         | 
| 2 3 | 
             
            require 'active_support/configurable'
         | 
| 3 4 | 
             
            require 'active_support/core_ext/hash'
         | 
| 4 5 | 
             
            require 'logger'
         | 
| @@ -8,22 +9,25 @@ require 'iban_calculator/bic_candidate' | |
| 8 9 | 
             
            require 'iban_calculator/iban_bic'
         | 
| 9 10 | 
             
            require 'iban_calculator/iban_validator_response'
         | 
| 10 11 | 
             
            require 'iban_calculator/invalid_data'
         | 
| 12 | 
            +
            require 'iban_calculator/active_support' if ActiveSupport::VERSION::MAJOR == 3
         | 
| 11 13 |  | 
| 12 14 | 
             
            module IbanCalculator
         | 
| 13 15 | 
             
              # Extensions
         | 
| 14 16 | 
             
              include ActiveSupport::Configurable
         | 
| 15 17 |  | 
| 16 18 | 
             
              # Configuration
         | 
| 17 | 
            -
              config_accessor(:url) | 
| 18 | 
            -
              config_accessor(:user) | 
| 19 | 
            -
              config_accessor(:password) | 
| 20 | 
            -
              config_accessor(:logger) | 
| 19 | 
            +
              config_accessor(:url)          { 'https://ssl.ibanrechner.de/soap/?wsdl' }
         | 
| 20 | 
            +
              config_accessor(:user)         { '' }
         | 
| 21 | 
            +
              config_accessor(:password)     { '' }
         | 
| 22 | 
            +
              config_accessor(:logger)       { Logger.new(STDOUT) }
         | 
| 23 | 
            +
              config_accessor(:read_timeout) { 5 }
         | 
| 24 | 
            +
              config_accessor(:open_timeout) { 5 }
         | 
| 21 25 |  | 
| 22 26 | 
             
              # Errors
         | 
| 23 27 | 
             
              ServiceError = Class.new(StandardError)
         | 
| 24 28 |  | 
| 25 29 | 
             
              def self.calculate_iban(attributes = {})
         | 
| 26 | 
            -
                client = IbanBic.new(config | 
| 30 | 
            +
                client = IbanBic.new(config)
         | 
| 27 31 | 
             
                client.calculate_iban(attributes)
         | 
| 28 32 | 
             
              end
         | 
| 29 33 |  | 
| @@ -33,7 +37,7 @@ module IbanCalculator | |
| 33 37 | 
             
              end
         | 
| 34 38 |  | 
| 35 39 | 
             
              def self.execute(method, options = {})
         | 
| 36 | 
            -
                client = Savon.client(wsdl: config.url, logger: config.logger)
         | 
| 40 | 
            +
                client = Savon.client(wsdl: config.url, logger: config.logger, read_timeout: config.read_timeout, open_timeout: config.open_timeout)
         | 
| 37 41 | 
             
                client.call(method, message: options).tap do |response|
         | 
| 38 42 | 
             
                  status = response.body[:"#{method}_response"][:return][:result]
         | 
| 39 43 | 
             
                  fail(ServiceError, status) unless response.body[:"#{method}_response"][:return][:return_code]
         | 
| @@ -0,0 +1,35 @@ | |
| 1 | 
            +
            # these are methods implemented in active_support 4 which
         | 
| 2 | 
            +
            # are required to run this gem with active_support 3
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            module IbanCalculator
         | 
| 5 | 
            +
              include ActiveSupport::Configurable
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              # taken from: activesupport/lib/active_support/core_ext/hash/keys.rb
         | 
| 8 | 
            +
              Hash.class_eval do
         | 
| 9 | 
            +
                def deep_stringify_keys!
         | 
| 10 | 
            +
                  deep_transform_keys!{ |key| key.to_s }
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                def deep_transform_keys!(&block)
         | 
| 14 | 
            +
                  keys.each do |key|
         | 
| 15 | 
            +
                    value = delete(key)
         | 
| 16 | 
            +
                    self[yield(key)] = value.is_a?(Hash) ? value.deep_transform_keys!(&block) : value
         | 
| 17 | 
            +
                  end
         | 
| 18 | 
            +
                  self
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
            end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            class << IbanCalculator
         | 
| 24 | 
            +
              alias_method :old_config_accessor, :config_accessor
         | 
| 25 | 
            +
             | 
| 26 | 
            +
              def config_accessor(*names)
         | 
| 27 | 
            +
                old_config_accessor(*names)
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                return unless block_given?
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                names.each do |name|
         | 
| 32 | 
            +
                  send("#{name}=", yield)
         | 
| 33 | 
            +
                end
         | 
| 34 | 
            +
              end
         | 
| 35 | 
            +
            end
         | 
| @@ -27,13 +27,14 @@ module IbanCalculator | |
| 27 27 | 
             
                PROBABLY_VALID_RESPONSE_CODE = 32..127
         | 
| 28 28 | 
             
                SERVICE_ERROR_RESPONSE_CODE = 65536
         | 
| 29 29 |  | 
| 30 | 
            -
                attr_accessor :user, :password, :url, :logger
         | 
| 30 | 
            +
                attr_accessor :user, :password, :url, :logger, :config
         | 
| 31 31 |  | 
| 32 | 
            -
                def initialize( | 
| 33 | 
            -
                  self.user = user
         | 
| 34 | 
            -
                  self.password = password
         | 
| 35 | 
            -
                  self.url = url
         | 
| 36 | 
            -
                  self.logger = logger
         | 
| 32 | 
            +
                def initialize(config)
         | 
| 33 | 
            +
                  self.user = config.user
         | 
| 34 | 
            +
                  self.password = config.password
         | 
| 35 | 
            +
                  self.url = config.url
         | 
| 36 | 
            +
                  self.logger = config.logger
         | 
| 37 | 
            +
                  self.config = config
         | 
| 37 38 | 
             
                end
         | 
| 38 39 |  | 
| 39 40 | 
             
                # You should provide country, bank_code, and account_number. (cin, abi, and cab for Italian accounts)
         | 
| @@ -98,7 +99,7 @@ module IbanCalculator | |
| 98 99 | 
             
                end
         | 
| 99 100 |  | 
| 100 101 | 
             
                def client
         | 
| 101 | 
            -
                  @client ||= Savon.client(wsdl: url)
         | 
| 102 | 
            +
                  @client ||= Savon.client(wsdl: url, read_timeout: config.read_timeout, open_timeout: config.open_timeout)
         | 
| 102 103 | 
             
                end
         | 
| 103 104 | 
             
              end
         | 
| 104 105 | 
             
            end
         | 
    
        data/spec/iban_bic_spec.rb
    CHANGED
    
    | @@ -1,5 +1,18 @@ | |
| 1 | 
            +
            require 'ostruct'
         | 
| 2 | 
            +
             | 
| 1 3 | 
             
            describe IbanCalculator::IbanBic do
         | 
| 2 | 
            -
               | 
| 4 | 
            +
              let(:config) {
         | 
| 5 | 
            +
                OpenStruct.new(
         | 
| 6 | 
            +
                  user: 'user',
         | 
| 7 | 
            +
                  password: 'pass',
         | 
| 8 | 
            +
                  url: 'url',
         | 
| 9 | 
            +
                  logger: Logger.new(STDOUT),
         | 
| 10 | 
            +
                  read_timeout: 5,
         | 
| 11 | 
            +
                  open_timeout: 5
         | 
| 12 | 
            +
                )
         | 
| 13 | 
            +
              }
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              subject { described_class.new(config) }
         | 
| 3 16 |  | 
| 4 17 | 
             
              before { allow(subject.logger).to receive(:info) }
         | 
| 5 18 |  | 
| @@ -49,6 +49,16 @@ describe IbanCalculator do | |
| 49 49 | 
             
                end
         | 
| 50 50 | 
             
              end
         | 
| 51 51 |  | 
| 52 | 
            +
              describe '.calculate_iban' do
         | 
| 53 | 
            +
                let(:error_message) { 'Service could not handle the request' }
         | 
| 54 | 
            +
                let(:response) { { calculate_iban_response: { return: { return_code: '65536' } } } }
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                before { allow_any_instance_of(Savon::Client).to receive(:call) { double(body: response) } }
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                it 'raises a generic exception' do
         | 
| 59 | 
            +
                  expect { IbanCalculator.calculate_iban({}) }.to raise_error(IbanCalculator::ServiceError, error_message)
         | 
| 60 | 
            +
                end
         | 
| 61 | 
            +
              end
         | 
| 52 62 |  | 
| 53 63 | 
             
              describe '.execute' do
         | 
| 54 64 | 
             
                context 'invalid username and password' do
         | 
    
        metadata
    CHANGED
    
    | @@ -1,29 +1,29 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: iban_calculator
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.2.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Maximilian Schulz
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2018-05-24 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: activesupport
         | 
| 15 15 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 16 | 
             
                requirements:
         | 
| 17 | 
            -
                - - " | 
| 17 | 
            +
                - - ">="
         | 
| 18 18 | 
             
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            -
                    version: ' | 
| 19 | 
            +
                    version: '3'
         | 
| 20 20 | 
             
              type: :runtime
         | 
| 21 21 | 
             
              prerelease: false
         | 
| 22 22 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 23 | 
             
                requirements:
         | 
| 24 | 
            -
                - - " | 
| 24 | 
            +
                - - ">="
         | 
| 25 25 | 
             
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            -
                    version: ' | 
| 26 | 
            +
                    version: '3'
         | 
| 27 27 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 28 28 | 
             
              name: savon
         | 
| 29 29 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -89,6 +89,7 @@ extra_rdoc_files: [] | |
| 89 89 | 
             
            files:
         | 
| 90 90 | 
             
            - ".gitignore"
         | 
| 91 91 | 
             
            - ".rspec"
         | 
| 92 | 
            +
            - ".travis.yml"
         | 
| 92 93 | 
             
            - CHANGELOG.md
         | 
| 93 94 | 
             
            - Gemfile
         | 
| 94 95 | 
             
            - LICENSE.txt
         | 
| @@ -96,6 +97,7 @@ files: | |
| 96 97 | 
             
            - Rakefile
         | 
| 97 98 | 
             
            - iban_calculator.gemspec
         | 
| 98 99 | 
             
            - lib/iban_calculator.rb
         | 
| 100 | 
            +
            - lib/iban_calculator/active_support.rb
         | 
| 99 101 | 
             
            - lib/iban_calculator/bank.rb
         | 
| 100 102 | 
             
            - lib/iban_calculator/bic_candidate.rb
         | 
| 101 103 | 
             
            - lib/iban_calculator/iban_bic.rb
         | 
| @@ -128,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 128 130 | 
             
                  version: '0'
         | 
| 129 131 | 
             
            requirements: []
         | 
| 130 132 | 
             
            rubyforge_project: 
         | 
| 131 | 
            -
            rubygems_version: 2. | 
| 133 | 
            +
            rubygems_version: 2.6.14
         | 
| 132 134 | 
             
            signing_key: 
         | 
| 133 135 | 
             
            specification_version: 4
         | 
| 134 136 | 
             
            summary: Calculate IBAN and BIC for countries of Single European Payments Area (SEPA).
         |