aboutsummaryrefslogtreecommitdiffstats
path: root/src/ynab/client.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-08-11 17:45:28 -0400
committerJesse Luehrs <doy@tozt.net>2019-08-11 17:45:28 -0400
commit909badee565c8e5164890b71da6a03b9efe16b28 (patch)
tree5a98249940e8ec848bc6634d979391947a1503fc /src/ynab/client.rs
parent53f34a6d47c43d96e5a3f5b368387776e9db7b02 (diff)
downloadynab-reimbursements-909badee565c8e5164890b71da6a03b9efe16b28.tar.gz
ynab-reimbursements-909badee565c8e5164890b71da6a03b9efe16b28.zip
refactor
Diffstat (limited to 'src/ynab/client.rs')
-rw-r--r--src/ynab/client.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/ynab/client.rs b/src/ynab/client.rs
new file mode 100644
index 0000000..a2fbdb3
--- /dev/null
+++ b/src/ynab/client.rs
@@ -0,0 +1,31 @@
+pub struct Client {
+ api: ynab_api::apis::client::APIClient,
+}
+
+impl Client {
+ pub fn new(key: &str) -> Self {
+ let mut ynab_config =
+ ynab_api::apis::configuration::Configuration::new();
+ ynab_config.api_key = Some(ynab_api::apis::configuration::ApiKey {
+ prefix: Some("Bearer".to_string()),
+ key: key.to_string(),
+ });
+ Self {
+ api: ynab_api::apis::client::APIClient::new(ynab_config),
+ }
+ }
+
+ pub fn default_budget(&self) -> super::budget::Budget {
+ let budgets =
+ self.api.budgets_api().get_budgets().unwrap().data.budgets;
+ let budget = budgets.iter().next().unwrap();
+ let full_budget = self
+ .api
+ .budgets_api()
+ .get_budget_by_id(&budget.id, 0)
+ .unwrap()
+ .data
+ .budget;
+ super::budget::Budget::new(&self.api, full_budget)
+ }
+}