Skip to content

Commit b82ca52

Browse files
committed
Resolve TODOs
1 parent ac39b1d commit b82ca52

File tree

1 file changed

+6
-25
lines changed

1 file changed

+6
-25
lines changed

src/posit/connect/tags.py

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from typing_extensions import NotRequired, TypedDict, Unpack
66

77
from .context import Context, ContextManager
8-
from .resources import Active, ResourceParameters
8+
from .resources import Active
99

1010
if TYPE_CHECKING:
1111
from .content import ContentItem
@@ -34,11 +34,8 @@ def parent_tag(self) -> Tag | None:
3434
if self.get("parent_id", None) is None:
3535
return None
3636

37-
# TODO-barret-future: Replace with `self._ctx.client.tags.get(self["parent_id"])`
38-
path = "v1/tags/" + self["parent_id"]
39-
url = self._ctx.url + path
40-
response = self._ctx.session.get(url)
41-
return Tag(self._ctx, path, **response.json())
37+
parent = self._ctx.client.tags.get(self["parent_id"])
38+
return parent
4239

4340
@property
4441
def children_tags(self) -> ChildrenTags:
@@ -141,8 +138,7 @@ def find(self) -> list[ContentItem]:
141138
url = self._ctx.url + self._path
142139
response = self._ctx.session.get(url)
143140
results = response.json()
144-
params = ResourceParameters(self._ctx.session, self._ctx.url)
145-
return [ContentItem(params, **result) for result in results]
141+
return [ContentItem(self._ctx, **result) for result in results]
146142

147143

148144
class ChildrenTags(ContextManager):
@@ -161,10 +157,7 @@ def find(self) -> list[Tag]:
161157
list[Tag]
162158
List of child tags. (Does not include the parent tag.)
163159
"""
164-
# TODO-future-barret;
165-
# This method could be done with `self._ctx.client.tags.find(parent=self)`
166-
# For now, use DescendantTags and filter the results
167-
descendant_tags = DescendantTags(self._ctx, parent_tag=self._parent_tag).find()
160+
descendant_tags = self._ctx.client.tags.find(parent=self._parent_tag)
168161

169162
# Filter out tags that are not direct children
170163
child_tags: list[Tag] = []
@@ -196,19 +189,7 @@ def find(self) -> list[Tag]:
196189
# By using the `/v1/tags` endpoint, we can get all tags in a single request
197190
# and filter them in Python.
198191

199-
# TODO-barret-future: Replace with `self._ctx.client.tags.find(parent=self._root_id)`
200-
url = self._ctx.url + self._path
201-
response = self._ctx.session.get(url)
202-
results = response.json()
203-
all_tags = []
204-
for result in results:
205-
tag = Tag(
206-
self._ctx,
207-
# TODO-barret-future: Replace with `self._ctx.client.tags._path`?
208-
f"{self._path}/{result['id']}",
209-
**result,
210-
)
211-
all_tags.append(tag)
192+
all_tags = self._ctx.client.tags.find()
212193

213194
# O(n^2) algorithm to find all child tags
214195
# This could be optimized by using a dictionary to store the tags by their parent_id and

0 commit comments

Comments
 (0)