up_bank_api/
lib.rs

1
2
3//! This library is to be used to simplify the access of Up Bank data through
4//! Rust applications.
5
6// use serde::{Deserialize, Serialize};
7pub use restson::{RestClient, blocking, Error};
8
9/// Module for all Transaction related data
10pub mod transactions;
11/// Module for all Account related data
12pub mod accounts;
13/// Module for all Category related data
14pub mod categories;
15/// Module for all Tag related data
16pub mod tags;
17/// Module for elements which are not to any specific data type, such as `Pagination<T>`
18pub mod general;
19
20mod test;
21
22/// Pass in your Up Bank token, returns an *async* RestClient where
23/// the API can be easily called, with the required results returned.
24///
25/// Example:
26///
27/// ```
28/// if let Ok(client) = get_new_client(String::from("Bearer up:demo:rtHR7D3eBEqKPiIT")) {
29///     let accounts: AccountListsResponse = client.get(()).await.unwrap();
30/// }
31/// ```
32pub fn get_new_client(token: String) -> Result<RestClient, Error> {
33    let key= format!("Bearer  {}", token);
34    let mut client = RestClient::new("https://api.up.com.au/api/v1/")?;
35    client.set_header("Authorization", &key)?;
36    Ok(client)
37}
38
39/// Pass in your Up Bank token, returns a *blocking* RestClient where
40/// the API can be easily called, with the required results returned.
41/// 
42/// Example:
43///
44/// ```
45/// if let Ok(client) = get_new_blocking_client(String::from("Bearer up:demo:rtHR7D3eBEqKPiIT")) {
46///     let accounts: AccountListsResponse = client.get(()).unwrap();
47/// }
48/// ```
49pub fn get_new_blocking_client(token: String) -> Result<blocking::RestClient, Error> {
50    let key= format!("Bearer  {}", token);
51    let mut client = RestClient::new_blocking("https://api.up.com.au/api/v1/")?;
52    client.set_header("Authorization", &key)?;
53    Ok(client)
54}
55
56
57// use crate::accounts::{AccountId, AccountResponse, AccountsListResponse};
58// use crate::categories::{CategoriesListResponse, CategoryResponse, CategoryId};
59// use crate::tags::{TagListResponse};
60// use crate::transactions::{TransactionId, TransactionListResponse, TransactionResponse};
61
62// fn main() {
63//     let mut client = RestClient::new_blocking("https://api.up.com.au/api/v1/").unwrap();
64
65//     let key= format!("Bearer  {}", "up:yeah:key-goes-here");
66//     client.set_header("Authorization", &key).unwrap();
67
68//     let _accounts: AccountsListResponse = client.get(()).unwrap();
69//     let _account: AccountResponse = client.get(
70//         AccountId::new("49908555-f6e9-42fa-9a02-8de302aecb51")
71//     ).unwrap();
72
73//     let _categories: CategoriesListResponse = client.get(()).unwrap();
74//     let _category: CategoryResponse = client.get(
75//         CategoryId::new("home")
76//     ).unwrap();
77
78//     let _tags: TagListResponse = client.get(()).unwrap();
79
80//     let _transactions: TransactionListResponse = client.get(()).unwrap();
81//     let _transaction: TransactionResponse = client
82//         .get(TransactionId::new("f45ca050-3d44-40bd-9c4c-a24e05fdfe8d")).unwrap();
83
84//     // if let Some(link) = &_transactions.links.next {
85//     //     println!("Getting next page");
86//     //     let page = link.get(&mut client).unwrap();
87//     //     println!("Paged data: {:?}", page);
88//     // };
89
90//     if let Some(new_link) = _transactions.links.next.clone() {
91//         let mut curr_link = Some(new_link);
92//         let mut page_number = 1u32;
93
94//         loop {
95//             println!("Page number: {}", page_number);
96//             page_number += 1;
97//             if let Some(link) = &curr_link {
98//                 println!("Asking for data");
99//                 let data = link.get_blocking(&mut client).unwrap();
100//                 println!("Got data");
101//                 curr_link = data.links.next;
102//             } else {
103//                 break;
104//             }
105//         }
106//     }
107    
108// }
109