This repository has been archived by the owner on Sep 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Meta and Transactional Data modules
- Loading branch information
system32uwu
committed
Mar 27, 2022
1 parent
3682d81
commit 5762d57
Showing
10 changed files
with
299 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
use crate::{ | ||
api::Api, | ||
util::{self, types::Provider}, | ||
}; | ||
use colored::*; | ||
use dialoguer::{theme::ColorfulTheme, Select}; | ||
use std::{thread, time::Duration}; | ||
|
||
fn menu_options() -> Vec<String> { | ||
return vec![ | ||
String::from("List providers"), | ||
String::from("Get Provider details"), | ||
String::from("↵ Back"), | ||
]; | ||
} | ||
|
||
async fn list_providers(api: &Api) -> Vec<Provider> { | ||
return api.list_providers().await; | ||
} | ||
|
||
async fn get_provider_details(providers: &Vec<Provider>) -> &Provider { | ||
let provider_selection = Select::with_theme(&ColorfulTheme::default()) | ||
.with_prompt("Select a provider (🠕/🠗)") | ||
.default(0) | ||
.items(&providers[..]) | ||
.interact() | ||
.unwrap(); | ||
|
||
return &providers[provider_selection]; | ||
} | ||
|
||
pub async fn menu(api: &Api) { | ||
let mut selection: usize; | ||
println!("Fetching cached providers..."); | ||
let mut cached_providers: Vec<Provider> = list_providers(api).await; | ||
|
||
match api.api_key { | ||
Some(_) => loop { | ||
util::clear_console(); | ||
util::print_top_message(); | ||
|
||
selection = Select::with_theme(&ColorfulTheme::default()) | ||
.with_prompt("Select an option (🠕/🠗)") | ||
.default(0) | ||
.items(&menu_options()[..]) | ||
.interact() | ||
.unwrap(); | ||
|
||
match selection { | ||
0 => { | ||
cached_providers = list_providers(api).await; | ||
for provider in &cached_providers { | ||
println!("{}", provider) | ||
} | ||
util::back_menu(); | ||
} | ||
1 => { | ||
let provider_details = get_provider_details(&cached_providers).await; | ||
println!( | ||
"{:#?}", | ||
serde_json::from_str::<Provider>( | ||
&serde_json::to_string(&provider_details) | ||
.unwrap() | ||
.to_string() | ||
) | ||
.unwrap() | ||
); | ||
util::back_menu(); | ||
} | ||
2 | _ => break, | ||
}; | ||
}, | ||
None => { | ||
println!( | ||
"{}", | ||
"API Key is not set. Please do so before using this module.".red() | ||
); | ||
thread::sleep(Duration::from_millis(1700)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
use crate::{ | ||
api::Api, | ||
db, | ||
util::{self, types::Account}, | ||
}; | ||
use colored::*; | ||
use dialoguer::{theme::ColorfulTheme, Select}; | ||
use std::{thread, time::Duration}; | ||
|
||
fn menu_options() -> Vec<String> { | ||
return vec![ | ||
String::from("Get accounts"), | ||
String::from("List credit cards"), | ||
String::from("↵ Back"), | ||
]; | ||
} | ||
|
||
async fn get_accounts(api: &Api, user_key: String) -> Vec<Account> { | ||
match api.get_accounts(user_key).await { | ||
Ok(response) => response.accounts, | ||
Err(e) => { | ||
println!("{}", e); | ||
vec![] | ||
} | ||
} | ||
} | ||
|
||
async fn get_credit_cards(api: &Api, user_key: String) -> Vec<util::types::CreditCard> { | ||
match api.get_credit_cards(user_key).await { | ||
Ok(response) => response.credit_cards, | ||
Err(e) => { | ||
println!("{}", e); | ||
vec![] | ||
} | ||
} | ||
} | ||
|
||
pub async fn menu(api: &Api) { | ||
let mut selection: usize; | ||
|
||
match api.api_key { | ||
Some(_) => match db::get_user_key() { | ||
Some(user_key) => loop { | ||
util::clear_console(); | ||
util::print_top_message(); | ||
|
||
selection = Select::with_theme(&ColorfulTheme::default()) | ||
.with_prompt("Select an option (🠕/🠗)") | ||
.default(0) | ||
.items(&menu_options()[..]) | ||
.interact() | ||
.unwrap(); | ||
|
||
match selection { | ||
0 => { | ||
let accounts = get_accounts(api, user_key.clone()).await; | ||
util::clear_console(); | ||
for account in &accounts { | ||
println!("{}\n", account) | ||
} | ||
util::back_menu(); | ||
} | ||
1 => { | ||
let credit_cards = get_credit_cards(api, user_key.clone()).await; | ||
util::clear_console(); | ||
for cc in &credit_cards { | ||
println!("{}\n", cc) | ||
} | ||
util::back_menu(); | ||
} | ||
2 | _ => break, | ||
}; | ||
}, | ||
None => { | ||
println!( | ||
"{}", | ||
"You're not logged in. Please do so before using this module.".red() | ||
); | ||
thread::sleep(Duration::from_millis(1700)); | ||
} | ||
}, | ||
None => { | ||
println!( | ||
"{}", | ||
"API Key is not set. Please do so before using this module.".red() | ||
); | ||
thread::sleep(Duration::from_millis(1700)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.