up_bank_api/
lib.rs

1//! This library is to be used to simplify the access of Up Bank data through
2//! Rust applications.
3
4// use serde::{Deserialize, Serialize};
5pub use restson::{self, blocking, Error, RestClient};
6
7/// Module for all Account related data
8pub mod accounts;
9/// Module for all Category related data
10pub mod categories;
11/// Module for all Tag related data
12pub mod tags;
13/// Module for all Transaction related data
14pub mod transactions;
15
16/// Module for elements which are not to any specific data type, such as `Pagination<T>`
17pub mod general;
18pub mod utility;
19
20#[cfg(test)]
21mod test;
22
23/// Pass in your Up Bank token, returns an *async* RestClient where
24/// the API can be easily called, with the required results returned.
25///
26/// Example:
27///
28/// ```
29/// if let Ok(client) = get_new_client(String::from("Bearer up:demo:rtHR7D3eBEqKPiIT")) {
30///     let accounts: AccountListsResponse = client.get(()).await.unwrap();
31/// }
32/// ```
33pub fn get_new_client(token: String) -> Result<RestClient, Error> {
34    let key = format!("Bearer  {}", token);
35    let mut client = RestClient::new("https://api.up.com.au/api/v1/")?;
36    client.set_header("Authorization", &key)?;
37    Ok(client)
38}
39
40/// Pass in your Up Bank token, returns a *blocking* RestClient where
41/// the API can be easily called, with the required results returned.
42///
43/// Example:
44///
45/// ```
46/// if let Ok(client) = get_new_blocking_client(String::from("Bearer up:demo:rtHR7D3eBEqKPiIT")) {
47///     let accounts: AccountListsResponse = client.get(()).unwrap();
48/// }
49/// ```
50pub fn get_new_blocking_client(token: String) -> Result<blocking::RestClient, Error> {
51    let key = format!("Bearer  {}", token);
52    let mut client = RestClient::new_blocking("https://api.up.com.au/api/v1/")?;
53    client.set_header("Authorization", &key)?;
54    Ok(client)
55}