Class: AqBanking::Commander
- Inherits:
-
Object
- Object
- AqBanking::Commander
- Defined in:
- lib/aq_banking/commander.rb
Defined Under Namespace
Classes: Result, SystemCmdError
Constant Summary collapse
- DEFAULT_TIMEOUT =
120
Instance Method Summary collapse
- #account_exists?(bank_code:, user_id:) ⇒ Boolean
- #account_valid?(bank_code:, account_number:) ⇒ Boolean
- #add_account(server_url:, hbci_version:, bank_code:, user_id:, user_name: '') ⇒ Object
- #call_getsysid(pin_file:, user_id:, bank_code:) ⇒ Object
- #send_request(bank_code, account_number, pin_file, from: nil, to: nil) ⇒ String
-
#send_request!(server_url:, hbci_version: '220', bank_code:, user_id:, password:, account_number:, user_name: '', from: nil, to: nil) ⇒ String
sends a request, but creates the account and fetches the sysid if neccessary.
- #with_pin(bank_code, user_id, password, &block) ⇒ Object
Instance Method Details
#account_exists?(bank_code:, user_id:) ⇒ Boolean
72 73 74 75 |
# File 'lib/aq_banking/commander.rb', line 72 def account_exists?(bank_code:, user_id:) result = run "aqhbci-tool4 listusers" result.stdout.include?("Bank: de/#{bank_code} User Id: #{user_id}") end |
#account_valid?(bank_code:, account_number:) ⇒ Boolean
64 65 66 67 |
# File 'lib/aq_banking/commander.rb', line 64 def account_valid?(bank_code:, account_number:) result = run "ktoblzcheck #{bank_code} #{account_number}" result.success? end |
#add_account(server_url:, hbci_version:, bank_code:, user_id:, user_name: '') ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/aq_banking/commander.rb', line 77 def add_account(server_url:, hbci_version:, bank_code:, user_id:, user_name: '') cmd = "" cmd << "#{aq_hbci} adduser -t pintan --context=1" cmd << " -b #{bank_code} -u #{user_id}" cmd << %Q( -N "#{user_name}") cmd << %Q( --hbciversion=#{hbci_version}) cmd << %Q( -s "#{server_url}") run_or_raise(cmd, 'could not add account').success? end |
#call_getsysid(pin_file:, user_id:, bank_code:) ⇒ Object
88 89 90 91 92 |
# File 'lib/aq_banking/commander.rb', line 88 def call_getsysid(pin_file:, user_id:, bank_code:) cmd = "#{aq_hbci} -P #{pin_file} getsysid -u #{user_id} -b #{bank_code}" run_or_raise(cmd, 'Could not get sysid. This might be because the userId or password is wrong. Check if these are the credentials with which you log into your online banking.') end |
#send_request(bank_code, account_number, pin_file, from: nil, to: nil) ⇒ String
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/aq_banking/commander.rb', line 21 def send_request(bank_code, account_number, pin_file, from: nil, to: nil) from = Date.parse(from) if from.is_a? String to = Date.parse(to) if to.is_a? String cmd = "#{aq_cli} -P #{pin_file} request -b #{bank_code} -a #{account_number}" cmd << " --fromdate=#{from.strftime("%Y%m%d")}" if from cmd << " --todate=#{to.strftime("%Y%m%d")}" if to cmd << " --transactions --balance" result = run_or_raise cmd, 'request failed' result.stdout end |
#send_request!(server_url:, hbci_version: '220', bank_code:, user_id:, password:, account_number:, user_name: '', from: nil, to: nil) ⇒ String
sends a request, but creates the account and fetches the sysid if neccessary
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/aq_banking/commander.rb', line 47 def send_request!(server_url:, hbci_version: '220', bank_code:, user_id:, password:, account_number:, user_name: '', from: nil, to: nil) raise ArgumentError.new("unknown hbci_version: \"#{hbci_version}\"") unless HBCI_VERSIONS.include? hbci_version raise ArgumentError.new("server url must be present") unless server_url.present? with_pin bank_code, user_id, password do |pin_file_path| unless account_exists? bank_code: bank_code, user_id: user_id add_account(server_url: server_url, hbci_version: hbci_version, bank_code: bank_code, user_id: user_id, user_name: user_name) call_getsysid pin_file: pin_file_path, user_id: user_id, bank_code: bank_code end send_request(bank_code, account_number, pin_file_path, from: from, to: to) end end |
#with_pin(bank_code, user_id, password, &block) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/aq_banking/commander.rb', line 35 def with_pin bank_code, user_id, password, &block pin_file = build_pin_file bank_code: bank_code, user_id: user_id, password: password block.call(pin_file.path) if block ensure pin_file.close! end |