module KontoAPI
Constants
- BANKNAME_URL
- DEFAULT_TIMEOUT
- IBAN_AND_BIC_URL
- RootCA
- VALIDITY_URL
Public Instance Methods
api_key()
click to toggle source
# File lib/kontoapi-ruby.rb, line 20 def api_key @@api_key end
api_key=(key)
click to toggle source
# File lib/kontoapi-ruby.rb, line 17 def api_key=(key) @@api_key = key end
bank_name(bank_code)
click to toggle source
# 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)
click to toggle source
# 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
timeout()
click to toggle source
# File lib/kontoapi-ruby.rb, line 28 def timeout @@timeout || DEFAULT_TIMEOUT end
timeout=(new_timeout)
click to toggle source
# File lib/kontoapi-ruby.rb, line 25 def timeout=(new_timeout) @@timeout = new_timeout end
valid?(options={})
click to toggle source
# 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
Private Instance Methods
ask_for(what, options={})
click to toggle source
# File lib/kontoapi-ruby.rb, line 57 def ask_for(what, options={}) raise 'Please set your API Key first (KontoAPI::api_key = "<your_key>"). You can get one at https://www.kontoapi.de/' unless api_key url = const_get("#{what}_URL".upcase).dup options.merge!( :key => api_key ) url.query_values = options body = get_url(url) parser = Yajl::Parser.new parser.parse(body) end
get_url(url)
click to toggle source
# File lib/kontoapi-ruby.rb, line 67 def get_url(url) http = Net::HTTP.new(url.host, 443) http.use_ssl = true http.read_timeout = timeout if File.directory? RootCA http.ca_path = RootCA http.verify_mode = OpenSSL::SSL::VERIFY_PEER http.verify_depth = 5 else http.verify_mode = OpenSSL::SSL::VERIFY_NONE end response = http.get url.request_uri, 'User-agent' => 'Konto API Ruby Client' case response when Net::HTTPSuccess, Net::HTTPOK response.body else response.error! end end