aboutsummaryrefslogtreecommitdiffstats
path: root/firefly_cli
diff options
context:
space:
mode:
Diffstat (limited to 'firefly_cli')
-rw-r--r--firefly_cli/resolver.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/firefly_cli/resolver.py b/firefly_cli/resolver.py
index 7296aad..53144e1 100644
--- a/firefly_cli/resolver.py
+++ b/firefly_cli/resolver.py
@@ -42,3 +42,16 @@ class Resolver:
def category(self, name):
return self._match("category", self._list("/api/v1/categories"), name)
+
+ def budget(self, name_or_id):
+ # Budgets must pre-exist (Firefly does not auto-create them for a
+ # transaction), so we resolve to an id. A numeric-looking ref goes
+ # straight to the show endpoint (lets same-name-safe callers pin an id);
+ # otherwise match by name against the list.
+ if str(name_or_id).isdigit():
+ return self.budget_by_id(name_or_id)
+ return self._match("budget", self._list("/api/v1/budgets"), name_or_id)
+
+ def budget_by_id(self, budget_id):
+ item = self.client.request("GET", f"/api/v1/budgets/{budget_id}")["data"]
+ return {"id": item["id"], **item.get("attributes", {})}