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 =
[:user, :password]

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
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?

  
  @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

#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



56
57
58
59
60
# File 'lib/bankscrap/bank.rb', line 56

def (iban)
  accounts.find do ||
    .iban.delete(' ') == iban.delete(' ')
  end
end

#fetch_accountsObject



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_forObject



52
53
54
# File 'lib/bankscrap/bank.rb', line 52

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

#loginObject

Interface method placeholders



44
45
46
# File 'lib/bankscrap/bank.rb', line 44

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