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 @@
1c648bd5dd3dab534723d1cb26e19fdbfcc7359cd8a33a1f8d99e5688e4ba54f
8c6a3b8bfecad67daa21d1361057c24f2e063b17c13afdcc93e7f71806011003
44 changes: 44 additions & 0 deletions src/controlresell/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
republish_item,
update_item,
)
from .generated.api.customers import get_customer, list_customers
from .generated.api.me import get_me
from .generated.api.orders import get_order, list_labels_to_ship, list_order_labels, list_orders
from .generated.client import AuthenticatedClient
Expand All @@ -41,6 +42,8 @@
AccountPage,
Conversation,
ConversationPage,
Customer,
CustomerPage,
Item,
ItemCreateRequest,
ItemPage,
Expand Down Expand Up @@ -109,6 +112,7 @@ def __init__(
self.items = _Items(self)
self.conversations = _Conversations(self)
self.orders = _Orders(self)
self.customers = _Customers(self)

@property
def http(self) -> httpx.Client:
Expand Down Expand Up @@ -386,3 +390,43 @@ def iter(
limit=limit, cursor=cursor, bucket=bucket, platform=platform, account_id=account_id, from_=from_, to=to
)
)


class _Customers:
"""The other parties of the seller's sales and purchases (needs the ``customers:read`` scope)."""

def __init__(self, sdk: ControlResell) -> None:
self._sdk = sdk

def list(
self,
*,
limit: int | None = None,
cursor: str | None = None,
account_id: UUID | str | None = None,
from_: datetime.datetime | None = None,
to: datetime.datetime | None = None,
) -> CustomerPage:
"""One page of customers, the most recently created first.

``from_`` is inclusive and ``to`` exclusive, on the creation date (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_customers, **_query(limit=limit, cursor=cursor, account_id=account, from_=_utc(from_), to=_utc(to))
)

def get(self, id: UUID | str) -> Customer:
"""One customer by its identifier."""
return self._sdk._call(get_customer, id=UUID(str(id))) # noqa: SLF001

def iter(
self,
*,
limit: int | None = None,
account_id: UUID | str | None = None,
from_: datetime.datetime | None = None,
to: datetime.datetime | None = None,
) -> Iterator[Customer]:
"""Every customer, page after page, with the same filters."""
return paginate(lambda cursor: self.list(limit=limit, cursor=cursor, account_id=account_id, from_=from_, to=to))
1 change: 1 addition & 0 deletions src/controlresell/generated/api/customers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Contains endpoint functions for accessing the API"""
202 changes: 202 additions & 0 deletions src/controlresell/generated/api/customers/get_customer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
from http import HTTPStatus
from typing import Any
from urllib.parse import quote
from uuid import UUID

import httpx

from ...client import AuthenticatedClient, Client
from ...models.customer import Customer
from ...models.error_response import ErrorResponse
from ...types import Response


def _get_kwargs(
id: UUID,
) -> dict[str, Any]:

_kwargs: dict[str, Any] = {
"method": "get",
"url": "/api/public/v1/customers/{id}".format(
id=quote(str(id), safe=""),
),
}

return _kwargs


def _parse_response(
*, client: AuthenticatedClient | Client, response: httpx.Response
) -> Customer | ErrorResponse:
if response.status_code == 200:
response_200 = Customer.from_dict(response.json())

return response_200

if response.status_code == 400:
response_400 = ErrorResponse.from_dict(response.json())

return response_400

if response.status_code == 401:
response_401 = ErrorResponse.from_dict(response.json())

return response_401

if response.status_code == 402:
response_402 = ErrorResponse.from_dict(response.json())

return response_402

if response.status_code == 403:
response_403 = ErrorResponse.from_dict(response.json())

return response_403

if response.status_code == 404:
response_404 = ErrorResponse.from_dict(response.json())

return response_404

if response.status_code == 429:
response_429 = ErrorResponse.from_dict(response.json())

return response_429

if response.status_code == 500:
response_500 = ErrorResponse.from_dict(response.json())

return response_500

response_default = ErrorResponse.from_dict(response.json())

return response_default


def _build_response(
*, client: AuthenticatedClient | Client, response: httpx.Response
) -> Response[Customer | ErrorResponse]:
return Response(
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=_parse_response(client=client, response=response),
)


def sync_detailed(
id: UUID,
*,
client: AuthenticatedClient | Client,
) -> Response[Customer | ErrorResponse]:
"""Read one customer

One customer of the seller, by its identifier (`GET /customers` lists them). Requires
`customers:read`.

Args:
id (UUID):

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Response[Customer | ErrorResponse]
"""

kwargs = _get_kwargs(
id=id,
)

response = client.get_httpx_client().request(
**kwargs,
)

return _build_response(client=client, response=response)


def sync(
id: UUID,
*,
client: AuthenticatedClient | Client,
) -> Customer | ErrorResponse | None:
"""Read one customer

One customer of the seller, by its identifier (`GET /customers` lists them). Requires
`customers:read`.

Args:
id (UUID):

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Customer | ErrorResponse
"""

return sync_detailed(
id=id,
client=client,
).parsed


async def asyncio_detailed(
id: UUID,
*,
client: AuthenticatedClient | Client,
) -> Response[Customer | ErrorResponse]:
"""Read one customer

One customer of the seller, by its identifier (`GET /customers` lists them). Requires
`customers:read`.

Args:
id (UUID):

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Response[Customer | ErrorResponse]
"""

kwargs = _get_kwargs(
id=id,
)

response = await client.get_async_httpx_client().request(**kwargs)

return _build_response(client=client, response=response)


async def asyncio(
id: UUID,
*,
client: AuthenticatedClient | Client,
) -> Customer | ErrorResponse | None:
"""Read one customer

One customer of the seller, by its identifier (`GET /customers` lists them). Requires
`customers:read`.

Args:
id (UUID):

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Customer | ErrorResponse
"""

return (
await asyncio_detailed(
id=id,
client=client,
)
).parsed
Loading
Loading