Sha256: 24dcaf057e35609bf1535861a29e442d3ddbf1027e1ef69775c3580f2d901e35

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

require 'rest-client'
require 'json'

module Ibanomat
  URL = 'http://www.sparkasse.de/firmenkunden/konto-karte/iban-resources/iban/iban.php'

  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_code_number is missing!') if options[:bank_account_number].empty?

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

      case hash['RetCode']
      when '00'
        { :bank_name => hash['Institutsname'],
          :bic       => hash['BIC'],
          :iban      => hash['IBAN']
        }
      else
        :error
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ibanomat-0.0.2 lib/ibanomat/client.rb
ibanomat-0.0.1 lib/ibanomat/client.rb