diff options
| author | Danilo M. <danix@danix.xyz> | 2026-07-03 17:36:17 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-07-03 17:36:17 +0200 |
| commit | 9c1c96b70dad9701498e4da7a3a8fa68e180a118 (patch) | |
| tree | 55bda44d65085c8e9600ce569fa08058e3b1452d /firefly_cli/resolver.py | |
| parent | e1fbf7439f50b1367c8e7fbd153e4f5ea61ea48b (diff) | |
| download | firefly-cli-9c1c96b70dad9701498e4da7a3a8fa68e180a118.tar.gz firefly-cli-9c1c96b70dad9701498e4da7a3a8fa68e180a118.zip | |
feat(resolver): budget name/id resolution
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'firefly_cli/resolver.py')
| -rw-r--r-- | firefly_cli/resolver.py | 13 |
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", {})} |
