Class: Balanced::BankAccount

Inherits:
Object
  • Object
show all
Includes:
Resource
Defined in:
lib/balanced_ach/resources/bank_account.rb

Instance Attribute Summary

Attributes included from Resource

#attributes

Instance Method Summary collapse

Methods included from Resource

#copy_from, #destroy, #find, included, #method_missing, #reload, #save

Constructor Details

#initialize(attributes = {}) ⇒ BankAccount

Returns a new instance of BankAccount.



5
6
7
8
9
10
11
# File 'lib/balanced_ach/resources/bank_account.rb', line 5

def initialize attributes = {}
  Balanced::Utils.stringify_keys! attributes
  unless attributes.has_key? 'uri'
    attributes['uri'] = self.class.uri
  end
  super attributes
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Balanced::Resource

Instance Method Details

#credit(params) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/balanced_ach/resources/bank_account.rb', line 22

def credit params
  amount = params.fetch(:amount) {nil}
  if amount.nil?
    raise "amount is required"
  end
  response = Balanced.post(self.credits_uri, :amount => amount)
  self.class.construct_from_response response.body
end

#debit(params) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/balanced_ach/resources/bank_account.rb', line 13

def debit params
  amount = params.fetch(:amount) {nil}
  if amount.nil?
    raise "amount is required"
  end
  response = Balanced.post(self.debits_uri, :amount => amount)
  self.class.construct_from_response response.body
end

#unstoreObject



31
32
33
# File 'lib/balanced_ach/resources/bank_account.rb', line 31

def unstore
  Balanced.delete(self.uri)
end