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 =
[:user, :password]
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 35 36 37 38 39 40 |
# 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}"] if value.blank? raise MissingCredential, "Missing credential: '#{field}'" else instance_variable_set("@#{field}", value) end 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 if self.respond_to?(:fetch_investments) @investments = fetch_investments end 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
56 57 58 59 60 |
# File 'lib/bankscrap/bank.rb', line 56 def account_with_iban(iban) accounts.find do |account| account.iban.delete(' ') == iban.delete(' ') end end |
#fetch_accounts ⇒ Object
48 49 50 |
# File 'lib/bankscrap/bank.rb', line 48 def fetch_accounts raise "#{self.class} should implement a fetch_account method" end |
#fetch_transactions_for ⇒ Object
52 53 54 |
# File 'lib/bankscrap/bank.rb', line 52 def fetch_transactions_for(*) raise "#{self.class} should implement a fetch_transactions method" end |
#login ⇒ Object
Interface method placeholders
44 45 46 |
# File 'lib/bankscrap/bank.rb', line 44 def login raise "#{self.class} should implement a login method" end |