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



44
45
46
47
48
49
# File 'lib/investec_open_api/client.rb', line 44

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

#pending_transactions(account_id, options = {}) ⇒ Object

Get pending transactions for an account

Parameters:

  • account_id (String)

    The id of the account to get pending transactions for

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :fromDate (String)

    Start date from which to get pending transactions

  • :toDate (String)

    End date for pending transactions



39
40
41
42
# File 'lib/investec_open_api/client.rb', line 39

def pending_transactions(, options = {})
  endpoint_url = "za/pb/v1/accounts/#{}/pending-transactions"
  perform_transaction_request(endpoint_url, options)
end

#transactions(account_id, options = {}) ⇒ Object

Get cleared transactions for an account

Parameters:

  • account_id (String)

    The id of the account to get transactions for

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :fromDate (String)

    Start date from which to get transactions

  • :toDate (String)

    End date for transactions

  • :transactionType (String)

    Type of transaction to filter by eg: CardPurchases, Deposits



29
30
31
32
# File 'lib/investec_open_api/client.rb', line 29

def transactions(, options = {})
  endpoint_url = "za/pb/v1/accounts/#{}/transactions"
  perform_transaction_request(endpoint_url, options)
end

#transfer_multiple(account_id, transfers, profile_id = nil) ⇒ Object

Parameters:



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/investec_open_api/client.rb', line 53

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