Class: QuestradeApi::REST::Balance
- Defined in:
- lib/questrade_api/rest/balance.rb
Overview
Constant Summary
Constants inherited from Base
QuestradeApi::REST::Base::BASE_ENDPOINT
Instance Attribute Summary collapse
-
#account_id ⇒ Object
Returns the value of attribute account_id.
Attributes inherited from Base
#authorization, #connection, #data, #endpoint, #id, #raw_body
Class Method Summary collapse
- .endpoint(account_id) ⇒ Object
-
.fetch(authorization, account_number) ⇒ OpenStruct(per_currency_balances, combined_balances, sod_per_currency_balances, sod_combined_balances), Faraday::Response
Fetch account balances.
Instance Method Summary collapse
-
#initialize(params) ⇒ Balance
constructor
A new instance of Balance.
Methods inherited from Base
#build_attributes, #build_data, connection, #fetch, post, #url
Constructor Details
#initialize(params) ⇒ Balance
Returns a new instance of Balance.
9 10 11 12 13 14 |
# File 'lib/questrade_api/rest/balance.rb', line 9 def initialize(params) @account_id = params[:account_id] @raw_body = params[:data] build_data(params[:data]) if @raw_body end |
Instance Attribute Details
#account_id ⇒ Object
Returns the value of attribute account_id.
7 8 9 |
# File 'lib/questrade_api/rest/balance.rb', line 7 def account_id @account_id end |
Class Method Details
.endpoint(account_id) ⇒ Object
42 43 44 |
# File 'lib/questrade_api/rest/balance.rb', line 42 def self.endpoint(account_id) "#{BASE_ENDPOINT}/accounts/#{account_id}/balances" end |
.fetch(authorization, account_number) ⇒ OpenStruct(per_currency_balances, combined_balances, sod_per_currency_balances, sod_combined_balances), Faraday::Response
Fetch account balances
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/questrade_api/rest/balance.rb', line 23 def self.fetch(, account_number) response = super(access_token: .access_token, endpoint: endpoint(account_number), url: .url) result = OpenStruct.new(per_currency_balances: [], combined_balances: [], sod_per_currency_balances: [], sod_combined_balances: []) if response.status == 200 parse_balances(account_number, response.body).each do |key, value| result.send("#{key}=", value) end end result end |