Skip to content

Commit 208048d

Browse files
committed
Followup to using *path for endpoint calls
1 parent 0de7d4f commit 208048d

File tree

3 files changed

+30
-23
lines changed

3 files changed

+30
-23
lines changed

src/posit/connect/_api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ class ApiDictEndpoint(ApiCallMixin, ReadOnlyDict):
9999
_path: str
100100
"""The HTTP path component for the resource endpoint."""
101101

102-
def _get_api(self, *, extra_endpoint: str = "") -> JsonifiableDict | None:
103-
super()._get_api(extra_endpoint=extra_endpoint)
102+
def _get_api(self, *path) -> JsonifiableDict | None:
103+
super()._get_api(*path)
104104

105105
def __init__(
106106
self,
@@ -246,7 +246,7 @@ def find(self, uid: str) -> T | None:
246246
:
247247
Single instance of T if found, else None
248248
"""
249-
result: Jsonifiable = self._get_api(extra_endpoint=uid)
249+
result: Jsonifiable = self._get_api(uid)
250250
result_obj = cast(JsonifiableDict, result)
251251

252252
return self._to_instance(result_obj)

src/posit/connect/_api_call.py

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import posixpath
34
from typing import TYPE_CHECKING, Protocol
45

56
if TYPE_CHECKING:
@@ -11,55 +12,61 @@ class ApiCallProtocol(Protocol):
1112
_ctx: Context
1213
_path: str
1314

14-
def _endpoint(self, extra_endpoint: str = "") -> str: ...
15-
def _get_api(self, *, extra_endpoint: str = "") -> Jsonifiable: ...
16-
def _delete_api(self, *, extra_endpoint: str = "") -> Jsonifiable | None: ...
17-
def _patch_api(self, json: Jsonifiable | None, *, extra_endpoint: str = "") -> Jsonifiable: ...
18-
def _put_api(self, json: Jsonifiable | None, *, extra_endpoint: str = "") -> Jsonifiable: ...
15+
def _endpoint(self, *path) -> str: ...
16+
def _get_api(self, *path) -> Jsonifiable: ...
17+
def _delete_api(self, *path) -> Jsonifiable | None: ...
18+
def _patch_api(self, *path, json: Jsonifiable | None) -> Jsonifiable: ...
19+
def _put_api(self, *path, json: Jsonifiable | None) -> Jsonifiable: ...
1920

2021

2122
def endpoint(ctx: Context, *path) -> str:
2223
return ctx.url + posixpath.join(*path)
2324

2425

2526
# Helper methods for API interactions
26-
def get_api(ctx: Context, path: str, *, extra_endpoint: str = "") -> Jsonifiable:
27-
response = ctx.session.get(endpoint(ctx, path, extra_endpoint=extra_endpoint))
27+
def get_api(ctx: Context, *path) -> Jsonifiable:
28+
response = ctx.session.get(endpoint(ctx, *path))
2829
return response.json()
2930

3031

3132
def put_api(
32-
ctx: Context, path: str, json: Jsonifiable | None, *, extra_endpoint: str = ""
33+
ctx: Context,
34+
*path,
35+
json: Jsonifiable | None,
3336
) -> Jsonifiable:
34-
response = ctx.session.put(endpoint(ctx, path, extra_endpoint=extra_endpoint), json=json)
37+
response = ctx.session.put(endpoint(ctx, *path), json=json)
3538
return response.json()
3639

3740

3841
# Mixin class for API interactions
3942

4043

4144
class ApiCallMixin:
42-
def _endpoint(self: ApiCallProtocol, extra_endpoint: str = "") -> str:
43-
return endpoint(self._ctx, self._path, extra_endpoint=extra_endpoint)
45+
def _endpoint(self: ApiCallProtocol, *path) -> str:
46+
return endpoint(self._ctx, self._path, *path)
4447

45-
def _get_api(self: ApiCallProtocol, *, extra_endpoint: str = "") -> Jsonifiable:
46-
response = self._ctx.session.get(self._endpoint(extra_endpoint))
48+
def _get_api(self: ApiCallProtocol, *path) -> Jsonifiable:
49+
response = self._ctx.session.get(self._endpoint(*path))
4750
return response.json()
4851

49-
def _delete_api(self: ApiCallProtocol, *, extra_endpoint: str = "") -> Jsonifiable | None:
50-
response = self._ctx.session.delete(self._endpoint(extra_endpoint))
52+
def _delete_api(self: ApiCallProtocol, *path) -> Jsonifiable | None:
53+
response = self._ctx.session.delete(self._endpoint(*path))
5154
if len(response.content) == 0:
5255
return None
5356
return response.json()
5457

5558
def _patch_api(
56-
self: ApiCallProtocol, json: Jsonifiable | None, *, extra_endpoint: str = ""
59+
self: ApiCallProtocol,
60+
*path,
61+
json: Jsonifiable | None,
5762
) -> Jsonifiable:
58-
response = self._ctx.session.patch(self._endpoint(extra_endpoint), json=json)
63+
response = self._ctx.session.patch(self._endpoint(*path), json=json)
5964
return response.json()
6065

6166
def _put_api(
62-
self: ApiCallProtocol, json: Jsonifiable | None, *, extra_endpoint: str = ""
67+
self: ApiCallProtocol,
68+
*path,
69+
json: Jsonifiable | None,
6370
) -> Jsonifiable:
64-
response = self._ctx.session.put(self._endpoint(extra_endpoint), json=json)
71+
response = self._ctx.session.put(self._endpoint(*path), json=json)
6572
return response.json()

src/posit/connect/content.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def update(
151151
--------
152152
* https://docs.posit.co/connect/api/#patch-/v1/content/-guid-/repository
153153
"""
154-
result = self._patch_api(cast(JsonifiableDict, dict(attrs)))
154+
result = self._patch_api(json=cast(JsonifiableDict, dict(attrs)))
155155
return ContentItemRepository(
156156
self._ctx,
157157
content_guid=self["content_guid"],

0 commit comments

Comments
 (0)