|
5 | 5 | import posixpath |
6 | 6 | import time |
7 | 7 | from abc import abstractmethod |
8 | | -from collections.abc import Mapping |
9 | | -from posixpath import dirname |
10 | 8 |
|
11 | 9 | from typing_extensions import ( |
12 | 10 | TYPE_CHECKING, |
13 | 11 | Any, |
| 12 | + Hashable, |
14 | 13 | List, |
15 | 14 | Literal, |
16 | 15 | NotRequired, |
|
29 | 28 | from .errors import ClientError |
30 | 29 | from .oauth.associations import ContentItemAssociations |
31 | 30 | from .permissions import Permissions |
32 | | -from .resources import ( |
33 | | - Active, |
34 | | - Resource, |
35 | | - Resources, |
36 | | - _Resource, |
37 | | - _ResourceSequence, |
38 | | - _ResourceUpdatePatchMixin, |
39 | | -) |
| 31 | +from .resources import Active, Resource, Resources, _Resource, _ResourceSequence |
40 | 32 | from .tags import ContentItemTags |
41 | 33 | from .vanities import VanityMixin |
42 | 34 | from .variants import Variants |
|
48 | 40 | from .tasks import Task |
49 | 41 |
|
50 | 42 |
|
| 43 | +# TODO-barret: Replace with Resource class from https://github.com/posit-dev/posit-sdk-py/pull/364/files#diff-94b7dc3c7d7d7c7b1a5f25e06c37df5fc53e1921cb10d41d4f04b18a715fae55R72 |
| 44 | +class ResourceP(Protocol): |
| 45 | + def __getitem__(self, key: Hashable, /) -> Any: ... |
| 46 | + |
| 47 | + |
51 | 48 | def _assert_guid(guid: str): |
52 | 49 | assert isinstance(guid, str), "Expected 'guid' to be a string" |
53 | 50 | assert len(guid) > 0, "Expected 'guid' to be non-empty" |
54 | 51 |
|
55 | 52 |
|
56 | 53 | # ContentItem Repository uses a PATCH method, not a PUT for updating. |
57 | | -class _ContentItemRepositoryResource(_ResourceUpdatePatchMixin, _Resource): ... |
| 54 | +class _ContentItemRepository(_Resource): |
| 55 | + def update(self, **attributes): # type: ignore[reportIncompatibleMethodOverride] |
| 56 | + response = self._ctx.client.patch(self._path, json=attributes) |
| 57 | + result = response.json() |
| 58 | + super().update(**result) |
58 | 59 |
|
59 | 60 |
|
60 | | -class ContentItemRepository(Mapping[str, Any]): |
| 61 | +class ContentItemRepository(ResourceP): |
61 | 62 | """ |
62 | 63 | Content items GitHub repository information. |
63 | 64 |
|
@@ -216,7 +217,7 @@ def oauth(self) -> ContentItemOAuth: |
216 | 217 | @property |
217 | 218 | def repository(self) -> ContentItemRepository | None: |
218 | 219 | try: |
219 | | - return _Resource( |
| 220 | + return _ContentItemRepository( |
220 | 221 | self._ctx, |
221 | 222 | f"v1/content/{self['guid']}/repository", |
222 | 223 | ) |
@@ -256,10 +257,10 @@ def create_repository(self, /, **attributes) -> ContentItemRepository: |
256 | 257 | ContentItemRepository |
257 | 258 | """ |
258 | 259 | path = f"v1/content/{self['guid']}/repository" |
259 | | - response = self._ctx.session.put(path, json=attributes) |
| 260 | + response = self._ctx.client.session.put(path, json=attributes) |
260 | 261 | result = response.json() |
261 | 262 |
|
262 | | - return _ContentItemRepositoryResource( |
| 263 | + return _ContentItemRepository( |
263 | 264 | self._ctx, |
264 | 265 | path, |
265 | 266 | **result, |
|
0 commit comments