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
2 changes: 1 addition & 1 deletion .spec-sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1acbf02fb5996004ee72495da2440677842bc7d8a705b9a4a0741565f353df4e
1c648bd5dd3dab534723d1cb26e19fdbfcc7359cd8a33a1f8d99e5688e4ba54f
67 changes: 56 additions & 11 deletions src/controlresell/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
update_item,
)
from .generated.api.me import get_me
from .generated.api.orders import get_order, list_order_labels, list_orders
from .generated.api.orders import get_order, list_labels_to_ship, list_order_labels, list_orders
from .generated.client import AuthenticatedClient
from .generated.models import (
Account,
Expand All @@ -50,6 +50,7 @@
Message,
MessagePage,
Order,
OrderLabel,
OrderLabelPage,
OrderPage,
PriceDropRequest,
Expand Down Expand Up @@ -250,20 +251,39 @@ def list(
cursor: str | None = None,
unread: bool | None = None,
account_id: UUID | str | None = None,
from_: datetime.datetime | None = None,
to: datetime.datetime | None = None,
) -> ConversationPage:
"""One page of the conversations with buyers."""
"""One page of the conversations with buyers.

``from_`` (inclusive) and ``to`` (exclusive) bound the last message (a naive datetime is read as UTC).
"""
account = UUID(str(account_id)) if account_id is not None else None
return self._sdk._call( # noqa: SLF001
list_conversations, **_query(limit=limit, cursor=cursor, unread=unread, account_id=account)
list_conversations,
**_query(limit=limit, cursor=cursor, unread=unread, account_id=account, from_=_utc(from_), to=_utc(to)),
)

def get(self, id: UUID | str) -> Conversation:
return self._sdk._call(get_conversation, id=UUID(str(id))) # noqa: SLF001

def messages(self, id: UUID | str, *, limit: int | None = None, cursor: str | None = None) -> MessagePage:
"""One page of the messages of a conversation, oldest first."""
def messages(
self,
id: UUID | str,
*,
limit: int | None = None,
cursor: str | None = None,
from_: datetime.datetime | None = None,
to: datetime.datetime | None = None,
) -> MessagePage:
"""One page of the messages of a conversation, oldest first.

``from_`` (inclusive) and ``to`` (exclusive) bound the period (a naive datetime is read as UTC).
"""
return self._sdk._call( # noqa: SLF001
list_conversation_messages, id=UUID(str(id)), **_query(limit=limit, cursor=cursor)
list_conversation_messages,
id=UUID(str(id)),
**_query(limit=limit, cursor=cursor, from_=_utc(from_), to=_utc(to)),
)

def send_message(self, id: UUID | str, body: SendMessageRequest, *, idempotency_key: str | None = None) -> Message:
Expand All @@ -279,14 +299,31 @@ def send_offer(self, id: UUID | str, body: SendOfferRequest, *, idempotency_key:
)

def iter(
self, *, limit: int | None = None, unread: bool | None = None, account_id: UUID | str | None = None
self,
*,
limit: int | None = None,
unread: bool | None = None,
account_id: UUID | str | None = None,
from_: datetime.datetime | None = None,
to: datetime.datetime | None = None,
) -> Iterator[Conversation]:
"""Every conversation, page after page, with the same filters."""
return paginate(lambda cursor: self.list(limit=limit, cursor=cursor, unread=unread, account_id=account_id))
return paginate(
lambda cursor: self.list(
limit=limit, cursor=cursor, unread=unread, account_id=account_id, from_=from_, to=to
)
)

def iter_messages(self, id: UUID | str, *, limit: int | None = None) -> Iterator[Any]:
"""Every message of a conversation, page after page."""
return paginate(lambda cursor: self.messages(id, limit=limit, cursor=cursor))
def iter_messages(
self,
id: UUID | str,
*,
limit: int | None = None,
from_: datetime.datetime | None = None,
to: datetime.datetime | None = None,
) -> Iterator[Any]:
"""Every message of a conversation, page after page, with the same period."""
return paginate(lambda cursor: self.messages(id, limit=limit, cursor=cursor, from_=from_, to=to))


class _Orders:
Expand Down Expand Up @@ -325,6 +362,14 @@ def labels(self, id: UUID | str) -> OrderLabelPage:
"""The shipping labels of an order."""
return self._sdk._call(list_order_labels, id=UUID(str(id))) # noqa: SLF001

def labels_to_ship(self, *, limit: int | None = None, cursor: str | None = None) -> OrderLabelPage:
"""One page of the labels still to ship over all the orders, the oldest order first (each names its order)."""
return self._sdk._call(list_labels_to_ship, **_query(limit=limit, cursor=cursor)) # noqa: SLF001

def iter_labels_to_ship(self, *, limit: int | None = None) -> Iterator[OrderLabel]:
"""Every label still to ship, page after page."""
return paginate(lambda cursor: self.labels_to_ship(limit=limit, cursor=cursor))

def iter(
self,
*,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime
from http import HTTPStatus
from typing import Any
from urllib.parse import quote
Expand All @@ -16,6 +17,8 @@ def _get_kwargs(
*,
limit: int | Unset = 50,
cursor: str | Unset = UNSET,
from_: datetime.datetime | Unset = UNSET,
to: datetime.datetime | Unset = UNSET,
) -> dict[str, Any]:

params: dict[str, Any] = {}
Expand All @@ -24,6 +27,16 @@ def _get_kwargs(

params["cursor"] = cursor

json_from_: str | Unset = UNSET
if not isinstance(from_, Unset):
json_from_ = from_.isoformat()
params["from"] = json_from_

json_to: str | Unset = UNSET
if not isinstance(to, Unset):
json_to = to.isoformat()
params["to"] = json_to

params = {k: v for k, v in params.items() if v is not UNSET and v is not None}

_kwargs: dict[str, Any] = {
Expand Down Expand Up @@ -102,16 +115,22 @@ def sync_detailed(
client: AuthenticatedClient | Client,
limit: int | Unset = 50,
cursor: str | Unset = UNSET,
from_: datetime.datetime | Unset = UNSET,
to: datetime.datetime | Unset = UNSET,
) -> Response[ErrorResponse | MessagePage]:
"""List the messages of a conversation

The messages of one conversation, oldest first, one page at a time: at most its 1 000 most recent
messages. Requires `conversations:read`.
messages (of the period, with `from` or `to`). Pass the `nextCursor` of a page as `cursor` with the
same `from` and `to` (a cursor reused with others is an `invalid_cursor`). `from` and `to` go
straight to a period: `from` is inclusive, `to` exclusive. Requires `conversations:read`.

Args:
id (UUID):
limit (int | Unset): Default: 50.
cursor (str | Unset):
from_ (datetime.datetime | Unset):
to (datetime.datetime | Unset):

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
Expand All @@ -125,6 +144,8 @@ def sync_detailed(
id=id,
limit=limit,
cursor=cursor,
from_=from_,
to=to,
)

response = client.get_httpx_client().request(
Expand All @@ -140,16 +161,22 @@ def sync(
client: AuthenticatedClient | Client,
limit: int | Unset = 50,
cursor: str | Unset = UNSET,
from_: datetime.datetime | Unset = UNSET,
to: datetime.datetime | Unset = UNSET,
) -> ErrorResponse | MessagePage | None:
"""List the messages of a conversation

The messages of one conversation, oldest first, one page at a time: at most its 1 000 most recent
messages. Requires `conversations:read`.
messages (of the period, with `from` or `to`). Pass the `nextCursor` of a page as `cursor` with the
same `from` and `to` (a cursor reused with others is an `invalid_cursor`). `from` and `to` go
straight to a period: `from` is inclusive, `to` exclusive. Requires `conversations:read`.

Args:
id (UUID):
limit (int | Unset): Default: 50.
cursor (str | Unset):
from_ (datetime.datetime | Unset):
to (datetime.datetime | Unset):

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
Expand All @@ -164,6 +191,8 @@ def sync(
client=client,
limit=limit,
cursor=cursor,
from_=from_,
to=to,
).parsed


Expand All @@ -173,16 +202,22 @@ async def asyncio_detailed(
client: AuthenticatedClient | Client,
limit: int | Unset = 50,
cursor: str | Unset = UNSET,
from_: datetime.datetime | Unset = UNSET,
to: datetime.datetime | Unset = UNSET,
) -> Response[ErrorResponse | MessagePage]:
"""List the messages of a conversation

The messages of one conversation, oldest first, one page at a time: at most its 1 000 most recent
messages. Requires `conversations:read`.
messages (of the period, with `from` or `to`). Pass the `nextCursor` of a page as `cursor` with the
same `from` and `to` (a cursor reused with others is an `invalid_cursor`). `from` and `to` go
straight to a period: `from` is inclusive, `to` exclusive. Requires `conversations:read`.

Args:
id (UUID):
limit (int | Unset): Default: 50.
cursor (str | Unset):
from_ (datetime.datetime | Unset):
to (datetime.datetime | Unset):

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
Expand All @@ -196,6 +231,8 @@ async def asyncio_detailed(
id=id,
limit=limit,
cursor=cursor,
from_=from_,
to=to,
)

response = await client.get_async_httpx_client().request(**kwargs)
Expand All @@ -209,16 +246,22 @@ async def asyncio(
client: AuthenticatedClient | Client,
limit: int | Unset = 50,
cursor: str | Unset = UNSET,
from_: datetime.datetime | Unset = UNSET,
to: datetime.datetime | Unset = UNSET,
) -> ErrorResponse | MessagePage | None:
"""List the messages of a conversation

The messages of one conversation, oldest first, one page at a time: at most its 1 000 most recent
messages. Requires `conversations:read`.
messages (of the period, with `from` or `to`). Pass the `nextCursor` of a page as `cursor` with the
same `from` and `to` (a cursor reused with others is an `invalid_cursor`). `from` and `to` go
straight to a period: `from` is inclusive, `to` exclusive. Requires `conversations:read`.

Args:
id (UUID):
limit (int | Unset): Default: 50.
cursor (str | Unset):
from_ (datetime.datetime | Unset):
to (datetime.datetime | Unset):

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
Expand All @@ -234,5 +277,7 @@ async def asyncio(
client=client,
limit=limit,
cursor=cursor,
from_=from_,
to=to,
)
).parsed
Loading
Loading