11from __future__ import annotations
22
3+ import posixpath
34from typing import TYPE_CHECKING , Protocol
45
56if 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
2122def 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
3132def 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
4144class 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 ()
0 commit comments