Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 24 additions & 19 deletions lago_python_client/mixins.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Generic, Optional, Type, TypeVar, Union
from typing import Any, Callable, ClassVar, Generic, Optional, Tuple, Type, TypeVar, Union

import httpx

Expand Down Expand Up @@ -36,14 +36,10 @@


class _ClientMixin(Protocol[_PM_co]):
@property
def PARENT_API_RESOURCE(self) -> str: ...
@property
def API_RESOURCE(self) -> str: ...
@property
def RESPONSE_MODEL(self) -> Type[_PM_co]: ...
@property
def ROOT_NAME(self) -> str: ...
API_RESOURCE: ClassVar[str]
RESPONSE_MODEL: ClassVar[Type[_PM_co]] # type: ignore[misc]
ROOT_NAME: ClassVar[str]

@property
def api_key(self) -> str: ...
@property
Expand All @@ -52,6 +48,15 @@ def base_url(self) -> str: ...
def rate_limit_retry_config(self) -> RateLimitRetryConfig: ...


class _ChildClientMixin(_ClientMixin[_PM_co], Protocol[_PM_co]):
PARENT_API_RESOURCE: ClassVar[str]


class _NestedClientMixin(_ClientMixin[_PM_co], Protocol[_PM_co]):
@property
def api_resource(self) -> Callable[..., Tuple[str, ...]]: ...


class CreateCommandMixin(Generic[_M]):
"""Client mixin with `create` command."""

Expand Down Expand Up @@ -154,7 +159,7 @@ class FindAllChildrenCommandMixin(Generic[_M]):
"""Client mixin with `find_all` command scoped to a parent resource."""

def find_all(
self: _ClientMixin[_M],
self: _ChildClientMixin[_M],
resource_id: str,
options: QueryPairs = None,
timetour: Optional[httpx.Timeout] = None,
Expand Down Expand Up @@ -187,7 +192,7 @@ class FindChildCommandMixin(Generic[_M]):
"""Client mixin with `find` command scoped to a parent resource."""

def find(
self: _ClientMixin[_M],
self: _ChildClientMixin[_M],
parent_id: str,
child_id: str,
options: QueryPairs = None,
Expand Down Expand Up @@ -220,7 +225,7 @@ class CreateChildCommandMixin(Generic[_M]):
"""Client mixin with `create` command scoped to a parent resource."""

def create(
self: _ClientMixin[_M],
self: _ChildClientMixin[_M],
parent_id: str,
input_object: BaseModel,
options: QueryPairs = None,
Expand Down Expand Up @@ -253,7 +258,7 @@ class UpdateChildCommandMixin(Generic[_M]):
"""Client mixin with `update` command scoped to a parent resource."""

def update(
self: _ClientMixin[_M],
self: _ChildClientMixin[_M],
parent_id: str,
child_id: str,
input_object: BaseModel,
Expand Down Expand Up @@ -288,7 +293,7 @@ class DestroyChildCommandMixin(Generic[_M]):
"""Client mixin with `destroy` command scoped to a parent resource."""

def destroy(
self: _ClientMixin[_M],
self: _ChildClientMixin[_M],
parent_id: str,
child_id: str,
options: QueryPairs = None,
Expand Down Expand Up @@ -385,7 +390,7 @@ class NestedCreateCommandMixin(Generic[_M]):
"""Client mixin with `create` command."""

def create(
self: _ClientMixin[_M],
self: _NestedClientMixin[_M],
*args: Union[str, BaseModel],
timeout: Optional[httpx.Timeout] = None,
) -> Optional[_M]:
Expand Down Expand Up @@ -420,7 +425,7 @@ class NestedUpdateCommandMixin(Generic[_M]):
"""Client mixin with `update` command."""

def update(
self: _ClientMixin[_M],
self: _NestedClientMixin[_M],
*args: Union[str, BaseModel],
timeout: Optional[httpx.Timeout] = None,
) -> _M:
Expand Down Expand Up @@ -454,7 +459,7 @@ class NestedDestroyCommandMixin(Generic[_M]):
"""Client mixin with `destroy` command."""

def destroy(
self: _ClientMixin[_M],
self: _NestedClientMixin[_M],
*args: str,
timeout: Optional[httpx.Timeout] = None,
) -> BaseModel:
Expand Down Expand Up @@ -483,7 +488,7 @@ class NestedFindCommandMixin(Generic[_M]):
"""Client mixin with `find` command."""

def find(
self: _ClientMixin[_M],
self: _NestedClientMixin[_M],
*args: str,
timeout: Optional[httpx.Timeout] = None,
) -> _M:
Expand Down Expand Up @@ -512,7 +517,7 @@ class NestedFindAllCommandMixin(Generic[_M]):
"""Client mixin with `find_all` command."""

def find_all(
self: _ClientMixin[_M],
self: _NestedClientMixin[_M],
*parent_ids: str,
options: QueryPairs = None,
timeout: Optional[httpx.Timeout] = None,
Expand Down