Sha256: 2729ca0b18a806340015fe420b87dcc636e4fb19285801f8b6c17adfe2135208

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

require 'rest-client'
require 'json'

module Ibanomat
  URL = 'https://www.sparkasse.de/bin/servlets/sparkasse/iban'

  def self.find(options)
    raise ArgumentError.new unless options.is_a?(Hash)
    raise ArgumentError.new('Option :bank_code is missing!') if options[:bank_code].empty?
    raise ArgumentError.new('Option :bank_account_number is missing!') if options[:bank_account_number].empty?

    response = RestClient.get URL, {
                                :params => {
                                  'b' => options[:bank_code],
                                  'a' => options[:bank_account_number]
                                },
                                :accept => :json
                              }
    if response.code == 200
      hash = JSON.parse(response)

      { :bank_name           => hash['Institutsname'],
        :bic                 => hash['BIC'],
        :iban                => hash['IBAN'],
        :bank_code           => hash['BLZ'],
        :bank_account_number => hash['KtoNr'],
        :return_code         => hash['RetCode']
      }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ibanomat-1.2.0 lib/ibanomat/client.rb