/investec-api-rust

A rust client for Investec APIs

Primary LanguageRust

investec-api-rust

A rust client for Investec APIs.

WIP. See Roadmap below.

The goal of this crate is to make it easy to call Investec APIs from Rust programs.

Installation

Add the crate to your Cargo project:

cargo add --git https://github.com/jandremarais/investec-api-rust

Usage

Create the client by reading the client_id, client_secret and api_key from environment variables and authenitcate to get an access token:

# .env
INVESTEC_CLIENT_ID=
INVESTEC_CLIENT_SECRET=
INVESTEC_API_KEY=
let mut client = Client::from_env().build()?;
client.authenticate()?;

To enable auto refresh of the access tokens and caching to local file system, create the client as follows:

let client = Client::from_env()
    .local_token()
    .refresh_auth()
    .build()?;

If you want the client to point to the sandbox environment:

let client = Client::sandbox();

Once the client is created, making requests to the endpoints are simple. e.g. getting accounts:

let accounts = client.get_accounts().await?;

or getting account transactions:

let from_date = NaiveDate::from_ymd_opt(2023, 10, 1);
let to_date = NaiveDate::from_ymd_opt(2023, 10, 3);
let t_type = TransactionType::CardPurchases;
let transactions = client
    .get_account_transactions("1234", from_date, to_date, Some(t_type))
    .await?;

or paying beneficiary:

let beneficiary_id = "1234";
let my_account_id = "4321";
let payment = Payment::to(beneficiary_id)
    .amount(1.0)
    .my_reference("test me")
    .their_reference("test them")
    .build()?;
let response = client.pay_single(my_account_id, payment).await?;

See examples/basic.rs for an end-to-end example. You can run it with:

cargo run --examples basic

Roadmap

  • implement account info endpoints
  • implement inter account transfers
  • add basic example
  • basic documentation
  • implement beneficiary payments endpoints
  • implement document endpoints
  • add example for account transfer
  • add example for beneficary payments
  • better error management and test coverage for errors
  • publish on crates.io
  • wasm support