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
2 changes: 1 addition & 1 deletion .spec-sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
41311cb64247613fcc1634a63a1804e344c71873d665fc58af33e053a5f919f1
15321a7caa009c61dd09fb6412b8f44544953a2a90355f1afc081dc79d784900
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ for item in client.items.iter(sold=False):
print(item.name)
for order in client.orders.iter(bucket="to_send"): # needs the orders:read scope; also orders.get(id), orders.labels(id)
print(order.id)
for brand in client.catalogs.iter_brands(q="nik"): # the identifiers an item is written with (items:read): categories, category, category_fields, brands, sizes, colors, conditions, package_sizes, materials
print(brand.id, brand.name)

# Writes (API key with `items:write` / `conversations:write`); `idempotency_key=` chooses the key.
from controlresell.generated.models import ItemCreateRequest, ItemUpdateRequest, PublishRequest, SendMessageRequest
Expand Down
128 changes: 128 additions & 0 deletions src/controlresell/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,33 @@
republish_item,
update_item,
)
from .generated.api.catalogs import (
get_catalog_category,
get_catalog_category_fields,
list_catalog_brands,
list_catalog_categories,
list_catalog_colors,
list_catalog_conditions,
list_catalog_materials,
list_catalog_package_sizes,
list_catalog_sizes,
)
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
from .generated.models import (
Account,
AccountPage,
CatalogBrand,
CatalogBrandPage,
CatalogCategory,
CatalogCategoryFields,
CatalogCategoryPage,
CatalogSize,
CatalogSizePage,
CatalogValue,
CatalogValuePage,
Conversation,
ConversationPage,
Customer,
Expand Down Expand Up @@ -113,6 +133,7 @@ def __init__(
self.conversations = _Conversations(self)
self.orders = _Orders(self)
self.customers = _Customers(self)
self.catalogs = _Catalogs(self)

@property
def http(self) -> httpx.Client:
Expand Down Expand Up @@ -430,3 +451,110 @@ def iter(
) -> 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))


class _Catalogs:
"""The catalog an item is written with: categories, brands, sizes, colors... (needs the ``items:read`` scope).

Every ``category_id`` keeps what applies to one category.
"""

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

def categories(
self,
*,
limit: int | None = None,
cursor: str | None = None,
parent_id: int | None = None,
platform: str | None = None,
) -> CatalogCategoryPage:
"""One page of categories, flat, by identifier; ``parent_id`` keeps the children of one, ``platform`` one marketplace."""
return self._sdk._call( # noqa: SLF001
list_catalog_categories, **_query(limit=limit, cursor=cursor, parent_id=parent_id, platform=platform)
)

def iter_categories(
self, *, limit: int | None = None, parent_id: int | None = None, platform: str | None = None
) -> Iterator[CatalogCategory]:
"""Every category, page after page, with the same filters."""
return paginate(
lambda cursor: self.categories(limit=limit, cursor=cursor, parent_id=parent_id, platform=platform)
)

def category(self, id: int) -> CatalogCategory:
"""One category by its identifier."""
return self._sdk._call(get_catalog_category, id=id) # noqa: SLF001

def category_fields(self, id: int) -> CatalogCategoryFields:
"""What an item of a category is filled with: its size groups, enumerated and text fields, measurements."""
return self._sdk._call(get_catalog_category_fields, id=id) # noqa: SLF001

def brands(self, *, limit: int | None = None, cursor: str | None = None, q: str | None = None) -> CatalogBrandPage:
"""One page of brands, by identifier or, with ``q``, those whose name starts with it."""
return self._sdk._call(list_catalog_brands, **_query(limit=limit, cursor=cursor, q=q)) # noqa: SLF001

def iter_brands(self, *, limit: int | None = None, q: str | None = None) -> Iterator[CatalogBrand]:
"""Every brand, page after page, with the same filters."""
return paginate(lambda cursor: self.brands(limit=limit, cursor=cursor, q=q))

def sizes(
self, *, limit: int | None = None, cursor: str | None = None, category_id: int | None = None
) -> CatalogSizePage:
"""One page of sizes, each with its size group."""
return self._sdk._call( # noqa: SLF001
list_catalog_sizes, **_query(limit=limit, cursor=cursor, category_id=category_id)
)

def iter_sizes(self, *, limit: int | None = None, category_id: int | None = None) -> Iterator[CatalogSize]:
"""Every size, page after page, with the same filters."""
return paginate(lambda cursor: self.sizes(limit=limit, cursor=cursor, category_id=category_id))

def colors(
self, *, limit: int | None = None, cursor: str | None = None, category_id: int | None = None
) -> CatalogValuePage:
"""One page of colors."""
return self._sdk._call( # noqa: SLF001
list_catalog_colors, **_query(limit=limit, cursor=cursor, category_id=category_id)
)

def iter_colors(self, *, limit: int | None = None, category_id: int | None = None) -> Iterator[CatalogValue]:
"""Every one of the colors, page after page, with the same filters."""
return paginate(lambda cursor: self.colors(limit=limit, cursor=cursor, category_id=category_id))

def conditions(
self, *, limit: int | None = None, cursor: str | None = None, category_id: int | None = None
) -> CatalogValuePage:
"""One page of conditions."""
return self._sdk._call( # noqa: SLF001
list_catalog_conditions, **_query(limit=limit, cursor=cursor, category_id=category_id)
)

def iter_conditions(self, *, limit: int | None = None, category_id: int | None = None) -> Iterator[CatalogValue]:
"""Every one of the conditions, page after page, with the same filters."""
return paginate(lambda cursor: self.conditions(limit=limit, cursor=cursor, category_id=category_id))

def package_sizes(
self, *, limit: int | None = None, cursor: str | None = None, category_id: int | None = None
) -> CatalogValuePage:
"""One page of package sizes."""
return self._sdk._call( # noqa: SLF001
list_catalog_package_sizes, **_query(limit=limit, cursor=cursor, category_id=category_id)
)

def iter_package_sizes(self, *, limit: int | None = None, category_id: int | None = None) -> Iterator[CatalogValue]:
"""Every one of the package sizes, page after page, with the same filters."""
return paginate(lambda cursor: self.package_sizes(limit=limit, cursor=cursor, category_id=category_id))

def materials(
self, *, limit: int | None = None, cursor: str | None = None, category_id: int | None = None
) -> CatalogValuePage:
"""One page of materials."""
return self._sdk._call( # noqa: SLF001
list_catalog_materials, **_query(limit=limit, cursor=cursor, category_id=category_id)
)

def iter_materials(self, *, limit: int | None = None, category_id: int | None = None) -> Iterator[CatalogValue]:
"""Every one of the materials, page after page, with the same filters."""
return paginate(lambda cursor: self.materials(limit=limit, cursor=cursor, category_id=category_id))
1 change: 1 addition & 0 deletions src/controlresell/generated/api/catalogs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Contains endpoint functions for accessing the API"""
197 changes: 197 additions & 0 deletions src/controlresell/generated/api/catalogs/get_catalog_category.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
from http import HTTPStatus
from typing import Any
from urllib.parse import quote

import httpx

from ...client import AuthenticatedClient, Client
from ...models.catalog_category import CatalogCategory
from ...models.error_response import ErrorResponse
from ...types import Response


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

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

return _kwargs


def _parse_response(
*, client: AuthenticatedClient | Client, response: httpx.Response
) -> CatalogCategory | ErrorResponse:
if response.status_code == 200:
response_200 = CatalogCategory.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[CatalogCategory | 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: int,
*,
client: AuthenticatedClient | Client,
) -> Response[CatalogCategory | ErrorResponse]:
"""Read one category

One category of the catalog, by its identifier. Requires `items:read`.

Args:
id (int):

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[CatalogCategory | ErrorResponse]
"""

kwargs = _get_kwargs(
id=id,
)

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

return _build_response(client=client, response=response)


def sync(
id: int,
*,
client: AuthenticatedClient | Client,
) -> CatalogCategory | ErrorResponse | None:
"""Read one category

One category of the catalog, by its identifier. Requires `items:read`.

Args:
id (int):

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:
CatalogCategory | ErrorResponse
"""

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


async def asyncio_detailed(
id: int,
*,
client: AuthenticatedClient | Client,
) -> Response[CatalogCategory | ErrorResponse]:
"""Read one category

One category of the catalog, by its identifier. Requires `items:read`.

Args:
id (int):

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[CatalogCategory | 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: int,
*,
client: AuthenticatedClient | Client,
) -> CatalogCategory | ErrorResponse | None:
"""Read one category

One category of the catalog, by its identifier. Requires `items:read`.

Args:
id (int):

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:
CatalogCategory | ErrorResponse
"""

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