Skip to content
Closed
Show file tree
Hide file tree
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
30 changes: 30 additions & 0 deletions src/triggerdev/_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@
from typing import TYPE_CHECKING

from triggerdev._base_client import AsyncBaseClient
from triggerdev.resources.batches import AsyncBatches
from triggerdev.resources.bulk_actions import AsyncBulkActions
from triggerdev.resources.errors import AsyncErrors
from triggerdev.resources.runs import AsyncRuns
from triggerdev.resources.schedules import AsyncSchedules
from triggerdev.resources.sessions import AsyncSessions
from triggerdev.resources.tasks import AsyncTasks
from triggerdev.resources.waitpoints import AsyncWaitpoints
from triggerdev.resources.webhooks import AsyncWebhooks

if TYPE_CHECKING:
import httpx2
Expand Down Expand Up @@ -48,6 +54,30 @@ def runs(self) -> AsyncRuns:
def schedules(self) -> AsyncSchedules:
return AsyncSchedules(self)

@cached_property
def sessions(self) -> AsyncSessions:
return AsyncSessions(self)

@cached_property
def batches(self) -> AsyncBatches:
return AsyncBatches(self)

@cached_property
def waitpoints(self) -> AsyncWaitpoints:
return AsyncWaitpoints(self)

@cached_property
def webhooks(self) -> AsyncWebhooks:
return AsyncWebhooks(self)

@cached_property
def bulk_actions(self) -> AsyncBulkActions:
return AsyncBulkActions(self)

@cached_property
def errors(self) -> AsyncErrors:
return AsyncErrors(self)

async def __aenter__(self) -> AsyncClient:
return self

Expand Down
10 changes: 10 additions & 0 deletions src/triggerdev/_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ def _request(
cast_to: type[_ModelT],
body: dict[str, Any] | None = ...,
params: dict[str, Any] | None = ...,
auth_required: bool = ...,
) -> _ModelT: ...

@overload
Expand All @@ -471,6 +472,7 @@ def _request(
cast_to: None,
body: dict[str, Any] | None = ...,
params: dict[str, Any] | None = ...,
auth_required: bool = ...,
) -> None: ...

@overload
Expand All @@ -482,6 +484,7 @@ def _request(
cast_to: _SentinelType,
body: dict[str, Any] | None = ...,
params: dict[str, Any] | None = ...,
auth_required: bool = ...,
) -> dict[str, Any]: ...

def _request(
Expand All @@ -492,13 +495,15 @@ def _request(
cast_to: type[_ModelT] | _SentinelType | None = None,
body: dict[str, Any] | None = None,
params: dict[str, Any] | None = None,
auth_required: bool = True,
) -> _ModelT | dict[str, Any] | None:
return self._client._request( # pyright: ignore[reportPrivateUsage]
method,
path,
cast_to=cast_to,
body=body,
params=params,
auth_required=auth_required,
)


Expand All @@ -519,6 +524,7 @@ async def _request(
cast_to: type[_ModelT],
body: dict[str, Any] | None = ...,
params: dict[str, Any] | None = ...,
auth_required: bool = ...,
) -> _ModelT: ...

@overload
Expand All @@ -530,6 +536,7 @@ async def _request(
cast_to: None,
body: dict[str, Any] | None = ...,
params: dict[str, Any] | None = ...,
auth_required: bool = ...,
) -> None: ...

@overload
Expand All @@ -541,6 +548,7 @@ async def _request(
cast_to: _SentinelType,
body: dict[str, Any] | None = ...,
params: dict[str, Any] | None = ...,
auth_required: bool = ...,
) -> dict[str, Any]: ...

async def _request(
Expand All @@ -551,11 +559,13 @@ async def _request(
cast_to: type[_ModelT] | _SentinelType | None = None,
body: dict[str, Any] | None = None,
params: dict[str, Any] | None = None,
auth_required: bool = True,
) -> _ModelT | dict[str, Any] | None:
return await self._client._request( # pyright: ignore[reportPrivateUsage]
method,
path,
cast_to=cast_to,
body=body,
params=params,
auth_required=auth_required,
)
30 changes: 30 additions & 0 deletions src/triggerdev/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@
from typing import TYPE_CHECKING

from triggerdev._base_client import BaseClient
from triggerdev.resources.batches import Batches
from triggerdev.resources.bulk_actions import BulkActions
from triggerdev.resources.errors import Errors
from triggerdev.resources.runs import Runs
from triggerdev.resources.schedules import Schedules
from triggerdev.resources.sessions import Sessions
from triggerdev.resources.tasks import Tasks
from triggerdev.resources.waitpoints import Waitpoints
from triggerdev.resources.webhooks import Webhooks

if TYPE_CHECKING:
import httpx2
Expand Down Expand Up @@ -48,6 +54,30 @@ def runs(self) -> Runs:
def schedules(self) -> Schedules:
return Schedules(self)

@cached_property
def sessions(self) -> Sessions:
return Sessions(self)

@cached_property
def batches(self) -> Batches:
return Batches(self)

@cached_property
def waitpoints(self) -> Waitpoints:
return Waitpoints(self)

@cached_property
def webhooks(self) -> Webhooks:
return Webhooks(self)

@cached_property
def bulk_actions(self) -> BulkActions:
return BulkActions(self)

@cached_property
def errors(self) -> Errors:
return Errors(self)

def __enter__(self) -> Client:
return self

Expand Down
18 changes: 18 additions & 0 deletions src/triggerdev/resources/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
"""Trigger.dev API resource clients."""

from triggerdev.resources.batches import AsyncBatches, Batches
from triggerdev.resources.bulk_actions import AsyncBulkActions, BulkActions
from triggerdev.resources.errors import AsyncErrors, Errors
from triggerdev.resources.runs import AsyncRuns, Runs
from triggerdev.resources.schedules import AsyncSchedules, Schedules
from triggerdev.resources.sessions import AsyncSessions, Sessions
from triggerdev.resources.tasks import AsyncTasks, Tasks
from triggerdev.resources.waitpoints import AsyncWaitpoints, Waitpoints
from triggerdev.resources.webhooks import AsyncWebhooks, Webhooks

__all__ = [
"AsyncBatches",
"AsyncBulkActions",
"AsyncErrors",
"AsyncRuns",
"AsyncSchedules",
"AsyncSessions",
"AsyncTasks",
"AsyncWaitpoints",
"AsyncWebhooks",
"Batches",
"BulkActions",
"Errors",
"Runs",
"Schedules",
"Sessions",
"Tasks",
"Waitpoints",
"Webhooks",
]
45 changes: 45 additions & 0 deletions src/triggerdev/resources/batches.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""Batches resource client."""

from __future__ import annotations

from triggerdev._base_client import AsyncAPIResource, SyncAPIResource
from triggerdev.types.batches import (
BatchObject,
BatchResultsResponse,
)


class Batches(SyncAPIResource):
"""Methods for retrieving batch status and results."""

def retrieve(self, batch_id: str) -> BatchObject:
return self._request(
"GET",
f"/api/v1/batches/{batch_id}",
cast_to=BatchObject,
)

def results(self, batch_id: str) -> BatchResultsResponse:
return self._request(
"GET",
f"/api/v1/batches/{batch_id}/results",
cast_to=BatchResultsResponse,
)


class AsyncBatches(AsyncAPIResource):
"""Async methods for retrieving batch status and results."""

async def retrieve(self, batch_id: str) -> BatchObject:
return await self._request(
"GET",
f"/api/v1/batches/{batch_id}",
cast_to=BatchObject,
)

async def results(self, batch_id: str) -> BatchResultsResponse:
return await self._request(
"GET",
f"/api/v1/batches/{batch_id}/results",
cast_to=BatchResultsResponse,
)
119 changes: 119 additions & 0 deletions src/triggerdev/resources/bulk_actions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
"""Bulk actions resource client."""

from __future__ import annotations

from typing import Any

from triggerdev._base_client import AsyncAPIResource, SyncAPIResource
from triggerdev.types.bulk_actions import (
AbortBulkActionResponse,
BulkActionObject,
CancelByFilterBody,
CancelByRunIdsBody,
CreateBulkActionResponse,
ListBulkActionsResult,
ReplayByFilterBody,
ReplayByRunIdsBody,
)

_List = list


class BulkActions(SyncAPIResource):
"""Methods for managing bulk actions."""

def list(
self,
*,
page_size: int | None = None,
cursor_after: str | None = None,
cursor_before: str | None = None,
) -> ListBulkActionsResult:
params: dict[str, Any] = {}
if page_size is not None:
params["page[size]"] = page_size
if cursor_after is not None:
params["page[after]"] = cursor_after
if cursor_before is not None:
params["page[before]"] = cursor_before
return self._request(
"GET",
"/api/v1/bulk-actions",
cast_to=ListBulkActionsResult,
params=params or None,
)

def create(
self,
body: CancelByFilterBody | CancelByRunIdsBody | ReplayByFilterBody | ReplayByRunIdsBody,
) -> CreateBulkActionResponse:
return self._request(
"POST",
"/api/v1/bulk-actions",
cast_to=CreateBulkActionResponse,
body=body.model_dump(by_alias=True, exclude_none=True),
)

def retrieve(self, bulk_action_id: str) -> BulkActionObject:
return self._request(
"GET",
f"/api/v1/bulk-actions/{bulk_action_id}",
cast_to=BulkActionObject,
)

def abort(self, bulk_action_id: str) -> AbortBulkActionResponse:
return self._request(
"POST",
f"/api/v1/bulk-actions/{bulk_action_id}/abort",
cast_to=AbortBulkActionResponse,
)


class AsyncBulkActions(AsyncAPIResource):
"""Async methods for managing bulk actions."""

async def list(
self,
*,
page_size: int | None = None,
cursor_after: str | None = None,
cursor_before: str | None = None,
) -> ListBulkActionsResult:
params: dict[str, Any] = {}
if page_size is not None:
params["page[size]"] = page_size
if cursor_after is not None:
params["page[after]"] = cursor_after
if cursor_before is not None:
params["page[before]"] = cursor_before
return await self._request(
"GET",
"/api/v1/bulk-actions",
cast_to=ListBulkActionsResult,
params=params or None,
)

async def create(
self,
body: CancelByFilterBody | CancelByRunIdsBody | ReplayByFilterBody | ReplayByRunIdsBody,
) -> CreateBulkActionResponse:
return await self._request(
"POST",
"/api/v1/bulk-actions",
cast_to=CreateBulkActionResponse,
body=body.model_dump(by_alias=True, exclude_none=True),
)

async def retrieve(self, bulk_action_id: str) -> BulkActionObject:
return await self._request(
"GET",
f"/api/v1/bulk-actions/{bulk_action_id}",
cast_to=BulkActionObject,
)

async def abort(self, bulk_action_id: str) -> AbortBulkActionResponse:
return await self._request(
"POST",
f"/api/v1/bulk-actions/{bulk_action_id}/abort",
cast_to=AbortBulkActionResponse,
)
Loading