aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock6
-rw-r--r--Cargo.toml2
-rw-r--r--src/ynab/budget.rs4
-rw-r--r--src/ynab/client.rs2
-rw-r--r--src/ynab/transaction.rs102
5 files changed, 99 insertions, 17 deletions
diff --git a/Cargo.lock b/Cargo.lock
index ed7dfe3..8b9d435 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1708,7 +1708,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "ynab-api"
-version = "2.0.0"
+version = "3.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"reqwest 0.9.19 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1726,7 +1726,7 @@ dependencies = [
"cursive_table_view 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
"directories 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"snafu 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
- "ynab-api 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "ynab-api 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[metadata]
@@ -1926,4 +1926,4 @@ dependencies = [
"checksum winreg 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b2986deb581c4fe11b621998a5e53361efe6b48a151178d0cd9eeffa4dc6acc9"
"checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e"
"checksum xi-unicode 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "12ea8eda4b1eb72f02d148402e23832d56a33f55d8c1b2d5bcdde91d79d47cb1"
-"checksum ynab-api 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2249731e972372209fd0d41e1db5da32312164d01e710159411138c753c2ba8"
+"checksum ynab-api 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "97b5ea12cb2bac72acfde41fad9e3d9c30e04415e87b95e6221375b6c76fc944"
diff --git a/Cargo.toml b/Cargo.toml
index 449fdea..6ff0ade 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -12,4 +12,4 @@ cursive = "0.12"
cursive_table_view = "0.10"
directories = "2.0"
snafu = "0.4"
-ynab-api = "2"
+ynab-api = "3"
diff --git a/src/ynab/budget.rs b/src/ynab/budget.rs
index b802072..e9e7218 100644
--- a/src/ynab/budget.rs
+++ b/src/ynab/budget.rs
@@ -67,7 +67,9 @@ impl Budget {
txns.iter()
.map(|t| {
let mut ut = t.to_update_transaction();
- ut.flag_color = Some("green".to_string());
+ ut.flag_color = Some(
+ ynab_api::models::update_transaction::FlagColor::Green
+ );
ut
})
.collect(),
diff --git a/src/ynab/client.rs b/src/ynab/client.rs
index 19b456b..8b5a0f7 100644
--- a/src/ynab/client.rs
+++ b/src/ynab/client.rs
@@ -51,7 +51,7 @@ impl Client {
Ok(self
.api
.budgets_api()
- .get_budget_by_id(&budget_id, 0)
+ .get_budget_by_id(&budget_id, None)
.map_err(|e| Error::GetBudgetById {
id: budget_id.clone(),
source_msg: format!("{:?}", e),
diff --git a/src/ynab/transaction.rs b/src/ynab/transaction.rs
index 287b574..d9ce6bd 100644
--- a/src/ynab/transaction.rs
+++ b/src/ynab/transaction.rs
@@ -1,12 +1,12 @@
-#[derive(Clone, Debug)]
+#[derive(Debug)]
pub struct Transaction {
pub id: String,
pub date: String,
pub amount: i64,
pub memo: Option<String>,
- pub cleared: String,
+ pub cleared: ynab_api::models::transaction_summary::Cleared,
pub approved: bool,
- pub flag_color: Option<String>,
+ pub flag_color: Option<ynab_api::models::transaction_summary::FlagColor>,
pub account_id: String,
pub payee_id: Option<String>,
pub category_id: Option<String>,
@@ -24,7 +24,7 @@ impl Transaction {
t: &ynab_api::models::TransactionSummary,
) -> Self {
let reimbursed = if let Some(color) = &t.flag_color {
- color == "green"
+ color == &ynab_api::models::transaction_summary::FlagColor::Green
} else {
false
};
@@ -33,9 +33,9 @@ impl Transaction {
date: t.date.clone(),
amount: t.amount,
memo: t.memo.clone(),
- cleared: t.cleared.clone(),
+ cleared: clone_cleared(&t.cleared),
approved: t.approved,
- flag_color: t.flag_color.clone(),
+ flag_color: t.flag_color.as_ref().map(clone_flag_color),
account_id: t.account_id.clone(),
payee_id: t.payee_id.clone(),
category_id: t.category_id.clone(),
@@ -54,7 +54,7 @@ impl Transaction {
st: &ynab_api::models::SubTransaction,
) -> Self {
let reimbursed = if let Some(color) = &t.flag_color {
- color == "green"
+ color == &ynab_api::models::transaction_summary::FlagColor::Green
} else {
false
};
@@ -63,9 +63,9 @@ impl Transaction {
date: t.date.clone(),
amount: st.amount,
memo: t.memo.clone(),
- cleared: t.cleared.clone(),
+ cleared: clone_cleared(&t.cleared),
approved: t.approved,
- flag_color: t.flag_color.clone(),
+ flag_color: t.flag_color.as_ref().map(clone_flag_color),
account_id: t.account_id.clone(),
payee_id: t.payee_id.clone(),
category_id: t.category_id.clone(),
@@ -91,11 +91,91 @@ impl Transaction {
ut.payee_id = self.payee_id.clone();
ut.category_id = self.category_id.clone();
ut.memo = self.memo.clone();
- ut.cleared = Some(self.cleared.clone());
+ ut.cleared = Some(cleared_to_cleared(&self.cleared));
ut.approved = Some(self.approved);
- ut.flag_color = self.flag_color.clone();
+ ut.flag_color =
+ self.flag_color.as_ref().map(flag_color_to_flag_color);
ut.import_id = self.import_id.clone();
ut
}
}
+
+impl Clone for Transaction {
+ fn clone(&self) -> Self {
+ Self {
+ id: self.id.clone(),
+ date: self.date.clone(),
+ amount: self.amount,
+ memo: self.memo.clone(),
+ cleared: clone_cleared(&self.cleared),
+ approved: self.approved,
+ flag_color: self.flag_color.as_ref().map(clone_flag_color),
+ account_id: self.account_id.clone(),
+ payee_id: self.payee_id.clone(),
+ category_id: self.category_id.clone(),
+ import_id: self.import_id.clone(),
+ account: self.account.clone(),
+ payee: self.payee.clone(),
+ total_amount: self.total_amount,
+ reimbursed: self.reimbursed,
+ selected: self.selected,
+ }
+ }
+}
+
+fn cleared_to_cleared(
+ cleared: &ynab_api::models::transaction_summary::Cleared,
+) -> ynab_api::models::update_transaction::Cleared {
+ use ynab_api::models::transaction_summary::Cleared as TSCleared;
+ use ynab_api::models::update_transaction::Cleared as UTCleared;
+
+ match cleared {
+ TSCleared::Cleared => UTCleared::Cleared,
+ TSCleared::Uncleared => UTCleared::Uncleared,
+ TSCleared::Reconciled => UTCleared::Reconciled,
+ }
+}
+
+fn flag_color_to_flag_color(
+ flag_color: &ynab_api::models::transaction_summary::FlagColor,
+) -> ynab_api::models::update_transaction::FlagColor {
+ use ynab_api::models::transaction_summary::FlagColor as TSFlagColor;
+ use ynab_api::models::update_transaction::FlagColor as UTFlagColor;
+
+ match flag_color {
+ TSFlagColor::Red => UTFlagColor::Red,
+ TSFlagColor::Orange => UTFlagColor::Orange,
+ TSFlagColor::Yellow => UTFlagColor::Yellow,
+ TSFlagColor::Green => UTFlagColor::Green,
+ TSFlagColor::Blue => UTFlagColor::Blue,
+ TSFlagColor::Purple => UTFlagColor::Purple,
+ }
+}
+
+fn clone_cleared(
+ cleared: &ynab_api::models::transaction_summary::Cleared,
+) -> ynab_api::models::transaction_summary::Cleared {
+ use ynab_api::models::transaction_summary::Cleared as TSCleared;
+
+ match cleared {
+ TSCleared::Cleared => TSCleared::Cleared,
+ TSCleared::Uncleared => TSCleared::Uncleared,
+ TSCleared::Reconciled => TSCleared::Reconciled,
+ }
+}
+
+fn clone_flag_color(
+ flag_color: &ynab_api::models::transaction_summary::FlagColor,
+) -> ynab_api::models::transaction_summary::FlagColor {
+ use ynab_api::models::transaction_summary::FlagColor as TSFlagColor;
+
+ match flag_color {
+ TSFlagColor::Red => TSFlagColor::Red,
+ TSFlagColor::Orange => TSFlagColor::Orange,
+ TSFlagColor::Yellow => TSFlagColor::Yellow,
+ TSFlagColor::Green => TSFlagColor::Green,
+ TSFlagColor::Blue => TSFlagColor::Blue,
+ TSFlagColor::Purple => TSFlagColor::Purple,
+ }
+}