Class: BankAccountConnector

Inherits:
Object
  • Object
show all
Defined in:
app/lib/bank_account_connector.rb

Direct Known Subclasses

BankAccountConnectorExternal

Defined Under Namespace

Classes: HiddenField, PasswordField, TextField, TextItem

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bank_account) ⇒ BankAccountConnector

Returns a new instance of BankAccountConnector.



57
58
59
60
61
62
# File 'app/lib/bank_account_connector.rb', line 57

def initialize()
  @bank_account = 
  @auto_submit = nil
  @controls = []
  @count = 0
end

Instance Attribute Details

#auto_submitObject (readonly)

Returns the value of attribute auto_submit.



68
69
70
# File 'app/lib/bank_account_connector.rb', line 68

def auto_submit
  @auto_submit
end

#controlsObject (readonly)

Returns the value of attribute controls.



68
69
70
# File 'app/lib/bank_account_connector.rb', line 68

def controls
  @controls
end

#countObject (readonly)

Returns the value of attribute count.



68
69
70
# File 'app/lib/bank_account_connector.rb', line 68

def count
  @count
end

Class Method Details

.find(iban) ⇒ Object



50
51
52
53
54
55
# File 'app/lib/bank_account_connector.rb', line 50

def self.find(iban)
  @registered_classes.each do |klass|
    return klass if klass.handles(iban)
  end
  nil
end

.register(klass) ⇒ Object



46
47
48
# File 'app/lib/bank_account_connector.rb', line 46

def self.register(klass)
  @registered_classes.add klass
end

Instance Method Details

#confirm_text(code) ⇒ Object



74
75
76
# File 'app/lib/bank_account_connector.rb', line 74

def confirm_text(code)
  text t('.confirm', code: code)
end

#continuation_pointObject



109
110
111
# File 'app/lib/bank_account_connector.rb', line 109

def continuation_point
  @bank_account.import_continuation_point
end

#dumpObject



129
# File 'app/lib/bank_account_connector.rb', line 129

def dump; end

#finishObject



122
123
124
125
# File 'app/lib/bank_account_connector.rb', line 122

def finish
  @bank_account.last_import = Time.now
  @bank_account.save!
end

#hidden_field(name, value) ⇒ Object



93
94
95
# File 'app/lib/bank_account_connector.rb', line 93

def hidden_field(name, value)
  @controls += [HiddenField.new(name, value, 'HIDDEN')]
end

#ibanObject



64
65
66
# File 'app/lib/bank_account_connector.rb', line 64

def iban
  @bank_account.iban
end

#load(data) ⇒ Object



127
# File 'app/lib/bank_account_connector.rb', line 127

def load(data); end

#password_field(name, value = nil) ⇒ Object



97
98
99
# File 'app/lib/bank_account_connector.rb', line 97

def password_field(name, value = nil)
  @controls += [PasswordField.new(name, value, t(name))]
end

#set_balance(amount) ⇒ Object



101
102
103
# File 'app/lib/bank_account_connector.rb', line 101

def set_balance(amount)
  @bank_account.balance = amount
end

#set_balance_as_sumObject



105
106
107
# File 'app/lib/bank_account_connector.rb', line 105

def set_balance_as_sum
  @bank_account.balance = @bank_account.bank_transactions.sum(:amount)
end

#set_continuation_point(data) ⇒ Object



113
114
115
# File 'app/lib/bank_account_connector.rb', line 113

def set_continuation_point(data)
  @bank_account.import_continuation_point = data
end

#t(key, args = {}) ⇒ Object



131
132
133
134
135
# File 'app/lib/bank_account_connector.rb', line 131

def t(key, args = {})
  return t(".fields.#{key}") unless key.is_a? String

  I18n.t 'bank_account_connector' + key, args
end

#text(data) ⇒ Object



70
71
72
# File 'app/lib/bank_account_connector.rb', line 70

def text(data)
  @controls += [TextItem.new(data)]
end

#text_field(name, value = nil) ⇒ Object



89
90
91
# File 'app/lib/bank_account_connector.rb', line 89

def text_field(name, value = nil)
  @controls += [TextField.new(name, value, t(name))]
end

#update_or_create_transaction(external_id, data = {}) ⇒ Object



117
118
119
120
# File 'app/lib/bank_account_connector.rb', line 117

def update_or_create_transaction(external_id, data = {})
  @bank_account.bank_transactions.where(external_id: external_id).first_or_create.update(data)
  @count += 1
end

#wait_for_app(code) ⇒ Object



83
84
85
86
87
# File 'app/lib/bank_account_connector.rb', line 83

def wait_for_app(code)
  hidden_field :twofactor, code
  wait_with_text 3000, code
  nil
end

#wait_with_text(auto_submit, code) ⇒ Object



78
79
80
81
# File 'app/lib/bank_account_connector.rb', line 78

def wait_with_text(auto_submit, code)
  @auto_submit = auto_submit
  confirm_text code
end