Investec Open API v0.1.0 InvestecOpenApi.Client View Source
This module deals with authenticating storing access_token between api calls.
Link to this section Summary
Functions
Authenticate returning a session that can be used for subsequent API calls
Automatically check if the access_token is expired or not. If it is expired,
a new session will automatically be started.
Link to this section Types
Specs
Link to this section Functions
Specs
call_generate_token(t()) :: {t(), InvestecOpenApi.HTTP.response()}
Specs
Authenticate returning a session that can be used for subsequent API calls
Methods:
- Using
new/1to useclient_idandclient_secretdefined in application config.
Example
iex> {:ok, client} = InvestecOpenApi.Client.new()
...> client.access_token
"Ms9OsZkyrhBZd5yQJgfEtiDy4t2c"Please note that it will raise error if client_id and client_secret is not found in your config.
- Using
new(client_id, client_secret)to authenticate with specific credentials
Example
iex> {:ok, client} = InvestecOpenApi.Client.new("thisIsmysecretclientId", "verySuperSecureSecret")
...> client.access_token
"Ms9OsZkyrhBZd5yQJgfEtiDy4t2c"- Using an existing
%Client{}as parameter. This is useful when you want to re-authenticate when a session has expired.
Example
iex> {:ok, client} = InvestecOpenApi.Client.new()
...> assert client.access_token == "Ms9OsZkyrhBZd5yQJgfEtiDy4t2c"
...> {:ok, client} = InvestecOpenApi.Client.new(client)
...> client.access_token
"Ms9OsZkyrhBZd5yQJgfEtiDy4t2c" Specs
Specs
Specs
Automatically check if the access_token is expired or not. If it is expired,
a new session will automatically be started.
Example
iex> client = InvestecOpenApi.Client.validate_access_token_still_valid(%InvestecOpenApi.Client{
...> access_token: "oldExpiredToken",
...> client_id: "thisIsmysecretclientId",
...> client_secret: "verySuperSecureSecret",
...> expires_at: 0, # Simulating an expired token
...> method: :token
...> })
...> refute client.access_token == "oldExpiredToken"
...> client_update = InvestecOpenApi.Client.validate_access_token_still_valid(client)
...> assert client_update.access_token == client.access_token
...> client.access_token
"Ms9OsZkyrhBZd5yQJgfEtiDy4t2c"