Class: Bankscrap::Bank
- Inherits:
-
Object
- Object
- Bankscrap::Bank
- Defined in:
- lib/bankscrap/bank.rb
Defined Under Namespace
Classes: MissingCredential
Constant Summary collapse
- WEB_USER_AGENT =
'Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 4 Build/JOP40D) AppleWebKit/535.19 (KHTML, ' \ 'like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19'.freeze
- REQUIRED_CREDENTIALS =
i(user password).freeze
Instance Attribute Summary collapse
-
#accounts ⇒ Object
Returns the value of attribute accounts.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#investments ⇒ Object
Returns the value of attribute investments.
Instance Method Summary collapse
- #account_with_iban(iban) ⇒ Object
- #fetch_accounts ⇒ Object
- #fetch_transactions_for ⇒ Object
-
#initialize(credentials = {}) ⇒ Bank
constructor
A new instance of Bank.
-
#login ⇒ Object
Interface method placeholders.
Constructor Details
#initialize(credentials = {}) ⇒ Bank
Returns a new instance of Bank.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/bankscrap/bank.rb', line 14 def initialize(credentials = {}) # Assign required credentials as env vars. # If empty, use ENV vars as fallback: # BANKSCRAP_MY_BANK_USER, BANKSCRAP_MY_BANK_PASWORD, etc. self.class::REQUIRED_CREDENTIALS.each do |field| value = credentials.with_indifferent_access[field] || ENV["#{env_vars_prefix}_#{field.upcase}"] raise MissingCredential, "Missing credential: '#{field}'" if value.blank? instance_variable_set("@#{field}", value) end initialize_http_client # Bank adapters should use the yield block to do any required processing of credentials yield if block_given? login @accounts = fetch_accounts # Not all the adapters have support for investments @investments = fetch_investments if respond_to?(:fetch_investments) end |
Instance Attribute Details
#accounts ⇒ Object
Returns the value of attribute accounts.
8 9 10 |
# File 'lib/bankscrap/bank.rb', line 8 def accounts @accounts end |
#headers ⇒ Object
Returns the value of attribute headers.
8 9 10 |
# File 'lib/bankscrap/bank.rb', line 8 def headers @headers end |
#investments ⇒ Object
Returns the value of attribute investments.
8 9 10 |
# File 'lib/bankscrap/bank.rb', line 8 def investments @investments end |
Instance Method Details
#account_with_iban(iban) ⇒ Object
50 51 52 53 54 |
# File 'lib/bankscrap/bank.rb', line 50 def account_with_iban(iban) accounts.find do |account| account.iban.delete(' ') == iban.delete(' ') end end |
#fetch_accounts ⇒ Object
42 43 44 |
# File 'lib/bankscrap/bank.rb', line 42 def fetch_accounts raise "#{self.class} should implement a fetch_account method" end |
#fetch_transactions_for ⇒ Object
46 47 48 |
# File 'lib/bankscrap/bank.rb', line 46 def fetch_transactions_for(*) raise "#{self.class} should implement a fetch_transactions method" end |
#login ⇒ Object
Interface method placeholders
38 39 40 |
# File 'lib/bankscrap/bank.rb', line 38 def login raise "#{self.class} should implement a login method" end |