aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-11-07 10:42:15 -0500
committerJesse Luehrs <doy@tozt.net>2019-11-07 10:42:15 -0500
commit90d3b963d7aa92076c5024b04476f9ddffd42214 (patch)
treecd7a5870e9364d4c91cd9440d1d69d94ef268839 /src
parent63ba77b996d0d14a80af2b296bc73726d547df00 (diff)
downloadynab-reimbursements-90d3b963d7aa92076c5024b04476f9ddffd42214.tar.gz
ynab-reimbursements-90d3b963d7aa92076c5024b04476f9ddffd42214.zip
update to the latest ynab-api
Diffstat (limited to 'src')
-rw-r--r--src/ynab/budget.rs4
-rw-r--r--src/ynab/client.rs2
-rw-r--r--src/ynab/transaction.rs102
3 files changed, 95 insertions, 13 deletions
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,
+ }
+}