Class: InvestecOpenApi::Client
- Inherits:
-
Object
- Object
- InvestecOpenApi::Client
- Defined in:
- lib/investec_open_api/client.rb
Instance Method Summary collapse
- #accounts ⇒ Object
- #authenticate! ⇒ Object
- #balance(account_id) ⇒ Object
- #transactions(account_id, options = {}) ⇒ Object
- #transfer_multiple(account_id, transfers, profile_id = nil) ⇒ Object
Instance Method Details
#accounts ⇒ Object
16 17 18 19 20 21 |
# File 'lib/investec_open_api/client.rb', line 16 def accounts response = connection.get("za/pb/v1/accounts") response.body["data"]["accounts"].map do |account_raw| InvestecOpenApi::Models::Account.from_api(account_raw) end end |
#authenticate! ⇒ Object
12 13 14 |
# File 'lib/investec_open_api/client.rb', line 12 def authenticate! @token = get_oauth_token["access_token"] end |
#balance(account_id) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/investec_open_api/client.rb', line 37 def balance(account_id) endpoint_url = "za/pb/v1/accounts/#{account_id}/balance" response = connection.get(endpoint_url) raise "Error fetching balance" if response.body["data"].nil? InvestecOpenApi::Models::Balance.from_api(response.body["data"]) end |
#transactions(account_id, options = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/investec_open_api/client.rb', line 23 def transactions(account_id, = {}) endpoint_url = "za/pb/v1/accounts/#{account_id}/transactions" unless .empty? query_string = URI.encode_www_form(.camelize) endpoint_url += "?#{query_string}" end response = connection.get(endpoint_url) response.body["data"]["transactions"].map do |transaction_raw| InvestecOpenApi::Models::Transaction.from_api(transaction_raw) end end |
#transfer_multiple(account_id, transfers, profile_id = nil) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/investec_open_api/client.rb', line 46 def transfer_multiple( account_id, transfers, profile_id = nil ) endpoint_url = "za/pb/v1/accounts/#{account_id}/transfermultiple" data = { transferList: transfers.map(&:to_h), } data[:profileId] = profile_id if profile_id response = connection.post( endpoint_url, JSON.generate(data) ) response.body end |