Class: Bankscrap::Bank

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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?

  
  @accounts = fetch_accounts

  # Not all the adapters have support for investments
  @investments = fetch_investments if respond_to?(:fetch_investments)
end

Instance Attribute Details

#accountsObject

Returns the value of attribute accounts.



8
9
10
# File 'lib/bankscrap/bank.rb', line 8

def accounts
  @accounts
end

#headersObject

Returns the value of attribute headers.



8
9
10
# File 'lib/bankscrap/bank.rb', line 8

def headers
  @headers
end

#investmentsObject

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 (iban)
  accounts.find do ||
    .iban.delete(' ') == iban.delete(' ')
  end
end

#fetch_accountsObject



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_forObject



46
47
48
# File 'lib/bankscrap/bank.rb', line 46

def fetch_transactions_for(*)
  raise "#{self.class} should implement a fetch_transactions method"
end

#loginObject

Interface method placeholders



38
39
40
# File 'lib/bankscrap/bank.rb', line 38

def 
  raise "#{self.class} should implement a login method"
end