Class: InvestecOpenApi::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/investec_open_api/client.rb

Instance Method Summary collapse

Instance Method Details

#accountsObject



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 ||
    InvestecOpenApi::Models::Account.from_api()
  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()
  endpoint_url = "za/pb/v1/accounts/#{}/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(, options = {})
  endpoint_url = "za/pb/v1/accounts/#{}/transactions"

  unless options.empty?
    query_string = URI.encode_www_form(options.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

Parameters:



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(
  ,
  transfers,
  profile_id = nil
)
  endpoint_url = "za/pb/v1/accounts/#{}/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