Skip to content
Merged
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
4 changes: 4 additions & 0 deletions src/lettermint/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def __exit__(self, *args: Any) -> None:
def _handle_response(self, response: httpx.Response) -> Any:
"""Handle the HTTP response and raise appropriate exceptions."""
if response.is_success:
if response.status_code == 204:
return None
return response.json()

try:
Expand Down Expand Up @@ -287,6 +289,8 @@ async def __aexit__(self, *args: Any) -> None:
def _handle_response(self, response: httpx.Response) -> Any:
"""Handle the HTTP response and raise appropriate exceptions."""
if response.is_success:
if response.status_code == 204:
return None
return response.json()

try:
Expand Down
107 changes: 107 additions & 0 deletions src/lettermint/endpoints/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,53 @@ def text(self, message_id: str) -> str:


class ProjectsEndpoint(Endpoint):
def retrieve_report_forwarding(self, project_id: str) -> lm_types.GetReportForwardingResponse:
return cast(
lm_types.GetReportForwardingResponse,
self._client.get(
self._path("/projects/{projectId}/report-forwarding", projectId=project_id)
),
)

def update_report_forwarding(
self, project_id: str, data: lm_types.UpdateReportForwardingRequest
) -> lm_types.UpdateReportForwardingResponse:
return cast(
lm_types.UpdateReportForwardingResponse,
self._client.put(
self._path("/projects/{projectId}/report-forwarding", projectId=project_id),
data=data,
),
)

def delete_report_forwarding(self, project_id: str) -> None:
self._client.delete(
self._path("/projects/{projectId}/report-forwarding", projectId=project_id)
)

def verify_report_forwarding(
self, project_id: str, data: lm_types.VerifyReportForwardingRequest
) -> lm_types.VerifyReportForwardingResponse:
return cast(
lm_types.VerifyReportForwardingResponse,
self._client.post(
self._path("/projects/{projectId}/report-forwarding/verify", projectId=project_id),
data=data,
),
)

def resend_report_forwarding_code(
self, project_id: str
) -> lm_types.ResendReportForwardingCodeResponse:
return cast(
lm_types.ResendReportForwardingCodeResponse,
self._client.post(
self._path(
"/projects/{projectId}/report-forwarding/resend-code", projectId=project_id
)
),
)

def list(self, query: Query | None = None) -> lm_types.ProjectIndexResponse:
return cast(lm_types.ProjectIndexResponse, self._client.get("/projects", params=query))

Expand Down Expand Up @@ -364,6 +411,17 @@ async def retrieve(
),
)

async def reschedule(
self, message_id: str, data: lm_types.RescheduleMessageRequest
) -> lm_types.RescheduleMessageResponse:
return await AsyncMessagesEndpoint(self._client).reschedule(message_id, data)

async def cancel(self, message_id: str) -> lm_types.RescheduleMessageResponse:
return await AsyncMessagesEndpoint(self._client).cancel(message_id)

async def process(self, message_id: str) -> lm_types.ProcessInboundMessageResponse:
return await AsyncMessagesEndpoint(self._client).process(message_id)

async def delete(self, domain_id: str) -> lm_types.DomainDestroyResponse:
return cast(
lm_types.DomainDestroyResponse,
Expand Down Expand Up @@ -473,6 +531,55 @@ async def text(self, message_id: str) -> str:


class AsyncProjectsEndpoint(AsyncEndpoint):
async def retrieve_report_forwarding(
self, project_id: str
) -> lm_types.GetReportForwardingResponse:
return cast(
lm_types.GetReportForwardingResponse,
await self._client.get(
self._path("/projects/{projectId}/report-forwarding", projectId=project_id)
),
)

async def update_report_forwarding(
self, project_id: str, data: lm_types.UpdateReportForwardingRequest
) -> lm_types.UpdateReportForwardingResponse:
return cast(
lm_types.UpdateReportForwardingResponse,
await self._client.put(
self._path("/projects/{projectId}/report-forwarding", projectId=project_id),
data=data,
),
)

async def delete_report_forwarding(self, project_id: str) -> None:
await self._client.delete(
self._path("/projects/{projectId}/report-forwarding", projectId=project_id)
)

async def verify_report_forwarding(
self, project_id: str, data: lm_types.VerifyReportForwardingRequest
) -> lm_types.VerifyReportForwardingResponse:
return cast(
lm_types.VerifyReportForwardingResponse,
await self._client.post(
self._path("/projects/{projectId}/report-forwarding/verify", projectId=project_id),
data=data,
),
)

async def resend_report_forwarding_code(
self, project_id: str
) -> lm_types.ResendReportForwardingCodeResponse:
return cast(
lm_types.ResendReportForwardingCodeResponse,
await self._client.post(
self._path(
"/projects/{projectId}/report-forwarding/resend-code", projectId=project_id
)
),
)

async def list(self, query: Query | None = None) -> lm_types.ProjectIndexResponse:
return cast(
lm_types.ProjectIndexResponse, await self._client.get("/projects", params=query)
Expand Down
6 changes: 6 additions & 0 deletions src/lettermint/lettermint.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ def __get__(


class ApiClient:
def analytics(self, data: lm_types.AnalyticsRequest) -> lm_types.AnalyticsResponse:
return cast(lm_types.AnalyticsResponse, self._client.post("/analytics", data=data))

"""Synchronous client for the full Lettermint API."""

def __init__(
Expand Down Expand Up @@ -96,6 +99,9 @@ def blocked_file_types(self) -> lm_types.BlockedFileTypesResponse:


class AsyncApiClient:
async def analytics(self, data: lm_types.AnalyticsRequest) -> lm_types.AnalyticsResponse:
return cast(lm_types.AnalyticsResponse, await self._client.post("/analytics", data=data))

"""Asynchronous client for the full Lettermint API."""

def __init__(
Expand Down
Loading
Loading