Class: Nordea::Account
- Defined in:
- lib/nordea/resources/account.rb
Instance Attribute Summary collapse
-
#balance ⇒ Object
Returns the value of attribute balance.
-
#currency ⇒ Object
Returns the value of attribute currency.
-
#index ⇒ Object
Returns the value of attribute index.
-
#name ⇒ Object
Returns the value of attribute name.
-
#session ⇒ Object
Returns the value of attribute session.
Class Method Summary collapse
Instance Method Summary collapse
- #account_type_name ⇒ Object
- #balance_to_s(decimals = 2) ⇒ Object
- #deposit(amount, currency = 'SEK', options = {}) ⇒ Object
-
#initialize(fields = {}, command_params = {}, session = nil) ⇒ Account
constructor
A new instance of Account.
- #to_command_params ⇒ Object
- #to_s ⇒ Object
-
#transactions(reload = false) ⇒ Object
TODO move shared transaction fetching to Nordea::Resource and call super.
- #withdraw(amount, currency = 'SEK', options = {}) ⇒ Object
Methods inherited from Resource
Constructor Details
#initialize(fields = {}, command_params = {}, session = nil) ⇒ Account
Returns a new instance of Account.
3 4 5 6 7 |
# File 'lib/nordea/resources/account.rb', line 3 def initialize(fields = {}, command_params = {}, session = nil) @name, @balance, @currency, @index = fields[:name], fields[:balance], fields[:currency], fields[:index] @command_params = command_params @session = session end |
Instance Attribute Details
#balance ⇒ Object
Returns the value of attribute balance.
9 10 11 |
# File 'lib/nordea/resources/account.rb', line 9 def balance @balance end |
#currency ⇒ Object
Returns the value of attribute currency.
9 10 11 |
# File 'lib/nordea/resources/account.rb', line 9 def currency @currency end |
#index ⇒ Object
Returns the value of attribute index.
9 10 11 |
# File 'lib/nordea/resources/account.rb', line 9 def index @index end |
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/nordea/resources/account.rb', line 9 def name @name end |
#session ⇒ Object
Returns the value of attribute session.
9 10 11 |
# File 'lib/nordea/resources/account.rb', line 9 def session @session end |
Class Method Details
.new_from_xml(xml_node, session) ⇒ Object
36 37 38 39 40 |
# File 'lib/nordea/resources/account.rb', line 36 def self.new_from_xml(xml_node, session) xml_node = Hpricot(xml_node) unless xml_node.class.to_s =~ /^Hpricot::/ xml_node = xml_node.at("anchor") unless xml_node.name == 'anchor' new _setup_fields(xml_node), _setup_command_params(xml_node), session end |
Instance Method Details
#account_type_name ⇒ Object
11 |
# File 'lib/nordea/resources/account.rb', line 11 def account_type_name; 'konton' end |
#balance_to_s(decimals = 2) ⇒ Object
32 33 34 |
# File 'lib/nordea/resources/account.rb', line 32 def balance_to_s(decimals = 2) %Q{%.#{decimals}f} % balance end |
#deposit(amount, currency = 'SEK', options = {}) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/nordea/resources/account.rb', line 74 def deposit(amount, currency = 'SEK', = {}) .symbolize_keys! from = .delete(:withdraw_from) raise ArgumentError unless from.is_a?(Nordea::Account) from.withdraw(amount, currency, .merge(:deposit_to => self)) end |
#to_command_params ⇒ Object
13 14 15 |
# File 'lib/nordea/resources/account.rb', line 13 def to_command_params @command_params end |
#to_s ⇒ Object
28 29 30 |
# File 'lib/nordea/resources/account.rb', line 28 def to_s "#{name}: #{balance_to_s} #{currency}" end |
#transactions(reload = false) ⇒ Object
TODO move shared transaction fetching to Nordea::Resource and call super
18 19 20 21 22 23 24 25 26 |
# File 'lib/nordea/resources/account.rb', line 18 def transactions(reload = false) @transactions = nil if reload @transactions ||= begin doc = session.request(Commands::TRANSACTIONS, to_command_params).parse_xml doc.search('go[@href="#trans"]').inject([]) do |all, node| all << Transaction.new_from_xml(node) end end end |
#withdraw(amount, currency = 'SEK', options = {}) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/nordea/resources/account.rb', line 42 def withdraw(amount, currency = 'SEK', = {}) .symbolize_keys! to = [:deposit_to] raise ArgumentError, "options[:deposit_to] must be a Nordea::Account" unless to.is_a?(Nordea::Account) currency, amount = currency.to_s, amount.to_s.sub(".", ",") from_account_info = [index, currency, name].join(":") to_account_info = [to.index, to.currency, to.name].join(":") params = { :from_account_info => from_account_info, :to_account_info => to_account_info, :amount => amount, :currency_code => currency } session.request(Nordea::Commands::TRANSFER_TO_OWN_ACCOUNT_PHASE_1, params) session.request(Nordea::Commands::TRANSFER_TO_OWN_ACCOUNT_PHASE_2, params) session.request(Nordea::Commands::TRANSFER_TO_OWN_ACCOUNT_PHASE_3, { :currency_code => currency, :from_account_number => index, :from_account_name => name, :to_account_number => to.index, :to_account_name => to.name, :amount => amount, :exchange_rate => "0", :from_currency_code => currency, :to_currency_code => currency }) session.accounts(true) end |