Module: KontoAPI

Extended by:
KontoAPI
Included in:
KontoAPI
Defined in:
lib/kontoapi-ruby.rb

Constant Summary collapse

RootCA =
'/etc/ssl/certs'
VALIDITY_URL =
Addressable::URI.parse 'https://ask.kontoapi.de/for/validity.json'
BANKNAME_URL =
Addressable::URI.parse 'https://ask.kontoapi.de/for/bankname.json'
IBAN_AND_BIC_URL =
Addressable::URI.parse 'https://ask.kontoapi.de/for/iban_and_bic.json'
DEFAULT_TIMEOUT =
10
@@api_key =
nil
@@timeout =
nil

Instance Method Summary collapse

Instance Method Details

#api_keyObject



20
21
22
# File 'lib/kontoapi-ruby.rb', line 20

def api_key
  @@api_key
end

#api_key=(key) ⇒ Object



17
18
19
# File 'lib/kontoapi-ruby.rb', line 17

def api_key=(key)
  @@api_key = key
end

#bank_name(bank_code) ⇒ Object



38
39
40
41
42
# File 'lib/kontoapi-ruby.rb', line 38

def bank_name(bank_code)
  return nil if bank_code.to_s.strip.empty?
  response = ask_for(:bankname, { :blz => bank_code.to_s })
  response['answer'].empty? ? nil : response['answer']
end

#iban_and_bic(ktn, blz) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/kontoapi-ruby.rb', line 44

def iban_and_bic(ktn, blz)
  stripped_ktn = ktn.to_s.strip
  stripped_blz = blz.to_s.strip
  return nil if stripped_ktn.empty?
  return nil if stripped_blz.empty?
  response = ask_for(:iban_and_bic, { :ktn => stripped_ktn, :blz => stripped_blz })
  response['answer']
end

#timeoutObject



28
29
30
# File 'lib/kontoapi-ruby.rb', line 28

def timeout
  @@timeout || DEFAULT_TIMEOUT
end

#timeout=(new_timeout) ⇒ Object



25
26
27
# File 'lib/kontoapi-ruby.rb', line 25

def timeout=(new_timeout)
  @@timeout = new_timeout
end

#valid?(options = {}) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
# File 'lib/kontoapi-ruby.rb', line 32

def valid?(options={})
  return false  unless (!options[:ktn].to_s.strip.empty? && !options[:blz].to_s.strip.empty?) || !options[:iban].to_s.strip.empty? || !options[:bic].to_s.strip.empty?
  response = ask_for(:validity, options)
  response['answer'].eql?('yes')
end