Module: Jemquarie::Parser::Balance

Included in:
Balance
Defined in:
lib/jemquarie/parser/balance.rb

Instance Method Summary collapse

Instance Method Details

#parse_balance_response(response) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/jemquarie/parser/balance.rb', line 5

def parse_balance_response(response)
  result = generic_request_response(response)
  return result if result[:error]
  balances = []
  return balances unless result["XMLExtract"] && result["XMLExtract"]["yourclientsBalances"] && result["XMLExtract"]["yourclientsBalances"]["yourclientsBalance"]
  xml_balances = if result["XMLExtract"]["yourclientsBalances"]["yourclientsBalance"].is_a?(Hash)
    [result["XMLExtract"]["yourclientsBalances"]["yourclientsBalance"]]
  else
    result["XMLExtract"]["yourclientsBalances"]["yourclientsBalance"]
  end
  xml_balances.each do |balance|
    balances << parse_single_balance(balance)
  end
  balances
end