Refactor API client methods to return specific model types instead of generic dictionaries
This commit is contained in:
parent
aa4c067ea8
commit
acdadad4b3
3 changed files with 58 additions and 32 deletions
|
|
@ -1,8 +1,13 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Any
|
|
||||||
|
|
||||||
from ebay_client.core.http.transport import ApiTransport
|
from ebay_client.core.http.transport import ApiTransport
|
||||||
|
from ebay_client.generated.account.models import (
|
||||||
|
FulfillmentPolicyResponse,
|
||||||
|
PaymentPolicyResponse,
|
||||||
|
Programs,
|
||||||
|
ReturnPolicyResponse,
|
||||||
|
SellingPrivileges,
|
||||||
|
)
|
||||||
|
|
||||||
ACCOUNT_SCOPE = "https://api.ebay.com/oauth/api_scope/sell.account"
|
ACCOUNT_SCOPE = "https://api.ebay.com/oauth/api_scope/sell.account"
|
||||||
ACCOUNT_READ_SCOPE = "https://api.ebay.com/oauth/api_scope/sell.account.readonly"
|
ACCOUNT_READ_SCOPE = "https://api.ebay.com/oauth/api_scope/sell.account.readonly"
|
||||||
|
|
@ -12,39 +17,44 @@ class AccountClient:
|
||||||
def __init__(self, transport: ApiTransport) -> None:
|
def __init__(self, transport: ApiTransport) -> None:
|
||||||
self.transport = transport
|
self.transport = transport
|
||||||
|
|
||||||
def get_fulfillment_policies(self, *, marketplace_id: str) -> dict[str, Any]:
|
def get_fulfillment_policies(self, *, marketplace_id: str) -> FulfillmentPolicyResponse:
|
||||||
return self.transport.request_json(
|
return self.transport.request_model(
|
||||||
|
FulfillmentPolicyResponse,
|
||||||
"GET",
|
"GET",
|
||||||
"/sell/account/v1/fulfillment_policy",
|
"/sell/account/v1/fulfillment_policy",
|
||||||
scopes=[ACCOUNT_READ_SCOPE],
|
scopes=[ACCOUNT_READ_SCOPE],
|
||||||
params={"marketplace_id": marketplace_id},
|
params={"marketplace_id": marketplace_id},
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_payment_policies(self, *, marketplace_id: str) -> dict[str, Any]:
|
def get_payment_policies(self, *, marketplace_id: str) -> PaymentPolicyResponse:
|
||||||
return self.transport.request_json(
|
return self.transport.request_model(
|
||||||
|
PaymentPolicyResponse,
|
||||||
"GET",
|
"GET",
|
||||||
"/sell/account/v1/payment_policy",
|
"/sell/account/v1/payment_policy",
|
||||||
scopes=[ACCOUNT_READ_SCOPE],
|
scopes=[ACCOUNT_READ_SCOPE],
|
||||||
params={"marketplace_id": marketplace_id},
|
params={"marketplace_id": marketplace_id},
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_return_policies(self, *, marketplace_id: str) -> dict[str, Any]:
|
def get_return_policies(self, *, marketplace_id: str) -> ReturnPolicyResponse:
|
||||||
return self.transport.request_json(
|
return self.transport.request_model(
|
||||||
|
ReturnPolicyResponse,
|
||||||
"GET",
|
"GET",
|
||||||
"/sell/account/v1/return_policy",
|
"/sell/account/v1/return_policy",
|
||||||
scopes=[ACCOUNT_READ_SCOPE],
|
scopes=[ACCOUNT_READ_SCOPE],
|
||||||
params={"marketplace_id": marketplace_id},
|
params={"marketplace_id": marketplace_id},
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_privileges(self) -> dict[str, Any]:
|
def get_privileges(self) -> SellingPrivileges:
|
||||||
return self.transport.request_json(
|
return self.transport.request_model(
|
||||||
|
SellingPrivileges,
|
||||||
"GET",
|
"GET",
|
||||||
"/sell/account/v1/privilege",
|
"/sell/account/v1/privilege",
|
||||||
scopes=[ACCOUNT_SCOPE],
|
scopes=[ACCOUNT_SCOPE],
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_opted_in_programs(self) -> dict[str, Any]:
|
def get_opted_in_programs(self) -> Programs:
|
||||||
return self.transport.request_json(
|
return self.transport.request_model(
|
||||||
|
Programs,
|
||||||
"GET",
|
"GET",
|
||||||
"/sell/account/v1/program/get_opted_in_programs",
|
"/sell/account/v1/program/get_opted_in_programs",
|
||||||
scopes=[ACCOUNT_READ_SCOPE],
|
scopes=[ACCOUNT_READ_SCOPE],
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,12 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Any
|
|
||||||
|
|
||||||
from ebay_client.core.http.transport import ApiTransport
|
from ebay_client.core.http.transport import ApiTransport
|
||||||
|
from ebay_client.generated.feed.models import (
|
||||||
|
ScheduleTemplateCollection,
|
||||||
|
Task,
|
||||||
|
TaskCollection,
|
||||||
|
UserScheduleCollection,
|
||||||
|
)
|
||||||
|
|
||||||
FEED_INVENTORY_SCOPE = "https://api.ebay.com/oauth/api_scope/sell.inventory"
|
FEED_INVENTORY_SCOPE = "https://api.ebay.com/oauth/api_scope/sell.inventory"
|
||||||
FEED_FULFILLMENT_SCOPE = "https://api.ebay.com/oauth/api_scope/sell.fulfillment"
|
FEED_FULFILLMENT_SCOPE = "https://api.ebay.com/oauth/api_scope/sell.fulfillment"
|
||||||
|
|
@ -12,30 +16,34 @@ class FeedClient:
|
||||||
def __init__(self, transport: ApiTransport) -> None:
|
def __init__(self, transport: ApiTransport) -> None:
|
||||||
self.transport = transport
|
self.transport = transport
|
||||||
|
|
||||||
def get_tasks(self, *, feed_type: str | None = None) -> dict[str, Any]:
|
def get_tasks(self, *, feed_type: str | None = None) -> TaskCollection:
|
||||||
return self.transport.request_json(
|
return self.transport.request_model(
|
||||||
|
TaskCollection,
|
||||||
"GET",
|
"GET",
|
||||||
"/sell/feed/v1/task",
|
"/sell/feed/v1/task",
|
||||||
scopes=[FEED_INVENTORY_SCOPE, FEED_FULFILLMENT_SCOPE],
|
scopes=[FEED_INVENTORY_SCOPE, FEED_FULFILLMENT_SCOPE],
|
||||||
params={"feed_type": feed_type},
|
params={"feed_type": feed_type},
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_task(self, task_id: str) -> dict[str, Any]:
|
def get_task(self, task_id: str) -> Task:
|
||||||
return self.transport.request_json(
|
return self.transport.request_model(
|
||||||
|
Task,
|
||||||
"GET",
|
"GET",
|
||||||
f"/sell/feed/v1/task/{task_id}",
|
f"/sell/feed/v1/task/{task_id}",
|
||||||
scopes=[FEED_INVENTORY_SCOPE, FEED_FULFILLMENT_SCOPE],
|
scopes=[FEED_INVENTORY_SCOPE, FEED_FULFILLMENT_SCOPE],
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_schedule_templates(self) -> dict[str, Any]:
|
def get_schedule_templates(self) -> ScheduleTemplateCollection:
|
||||||
return self.transport.request_json(
|
return self.transport.request_model(
|
||||||
|
ScheduleTemplateCollection,
|
||||||
"GET",
|
"GET",
|
||||||
"/sell/feed/v1/schedule_template",
|
"/sell/feed/v1/schedule_template",
|
||||||
scopes=[FEED_INVENTORY_SCOPE, FEED_FULFILLMENT_SCOPE],
|
scopes=[FEED_INVENTORY_SCOPE, FEED_FULFILLMENT_SCOPE],
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_schedules(self) -> dict[str, Any]:
|
def get_schedules(self) -> UserScheduleCollection:
|
||||||
return self.transport.request_json(
|
return self.transport.request_model(
|
||||||
|
UserScheduleCollection,
|
||||||
"GET",
|
"GET",
|
||||||
"/sell/feed/v1/schedule",
|
"/sell/feed/v1/schedule",
|
||||||
scopes=[FEED_INVENTORY_SCOPE, FEED_FULFILLMENT_SCOPE],
|
scopes=[FEED_INVENTORY_SCOPE, FEED_FULFILLMENT_SCOPE],
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,12 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Any
|
|
||||||
|
|
||||||
from ebay_client.core.http.transport import ApiTransport
|
from ebay_client.core.http.transport import ApiTransport
|
||||||
|
from ebay_client.generated.fulfillment.models import (
|
||||||
|
Order,
|
||||||
|
OrderSearchPagedCollection,
|
||||||
|
ShippingFulfillment,
|
||||||
|
ShippingFulfillmentPagedCollection,
|
||||||
|
)
|
||||||
|
|
||||||
FULFILLMENT_READ_SCOPE = "https://api.ebay.com/oauth/api_scope/sell.fulfillment.readonly"
|
FULFILLMENT_READ_SCOPE = "https://api.ebay.com/oauth/api_scope/sell.fulfillment.readonly"
|
||||||
|
|
||||||
|
|
@ -11,30 +15,34 @@ class FulfillmentClient:
|
||||||
def __init__(self, transport: ApiTransport) -> None:
|
def __init__(self, transport: ApiTransport) -> None:
|
||||||
self.transport = transport
|
self.transport = transport
|
||||||
|
|
||||||
def get_order(self, order_id: str) -> dict[str, Any]:
|
def get_order(self, order_id: str) -> Order:
|
||||||
return self.transport.request_json(
|
return self.transport.request_model(
|
||||||
|
Order,
|
||||||
"GET",
|
"GET",
|
||||||
f"/sell/fulfillment/v1/order/{order_id}",
|
f"/sell/fulfillment/v1/order/{order_id}",
|
||||||
scopes=[FULFILLMENT_READ_SCOPE],
|
scopes=[FULFILLMENT_READ_SCOPE],
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_orders(self, *, limit: int | None = None, offset: int | None = None) -> dict[str, Any]:
|
def get_orders(self, *, limit: int | None = None, offset: int | None = None) -> OrderSearchPagedCollection:
|
||||||
return self.transport.request_json(
|
return self.transport.request_model(
|
||||||
|
OrderSearchPagedCollection,
|
||||||
"GET",
|
"GET",
|
||||||
"/sell/fulfillment/v1/order",
|
"/sell/fulfillment/v1/order",
|
||||||
scopes=[FULFILLMENT_READ_SCOPE],
|
scopes=[FULFILLMENT_READ_SCOPE],
|
||||||
params={"limit": limit, "offset": offset},
|
params={"limit": limit, "offset": offset},
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_shipping_fulfillments(self, order_id: str) -> dict[str, Any]:
|
def get_shipping_fulfillments(self, order_id: str) -> ShippingFulfillmentPagedCollection:
|
||||||
return self.transport.request_json(
|
return self.transport.request_model(
|
||||||
|
ShippingFulfillmentPagedCollection,
|
||||||
"GET",
|
"GET",
|
||||||
f"/sell/fulfillment/v1/order/{order_id}/shipping_fulfillment",
|
f"/sell/fulfillment/v1/order/{order_id}/shipping_fulfillment",
|
||||||
scopes=[FULFILLMENT_READ_SCOPE],
|
scopes=[FULFILLMENT_READ_SCOPE],
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_shipping_fulfillment(self, order_id: str, fulfillment_id: str) -> dict[str, Any]:
|
def get_shipping_fulfillment(self, order_id: str, fulfillment_id: str) -> ShippingFulfillment:
|
||||||
return self.transport.request_json(
|
return self.transport.request_model(
|
||||||
|
ShippingFulfillment,
|
||||||
"GET",
|
"GET",
|
||||||
f"/sell/fulfillment/v1/order/{order_id}/shipping_fulfillment/{fulfillment_id}",
|
f"/sell/fulfillment/v1/order/{order_id}/shipping_fulfillment/{fulfillment_id}",
|
||||||
scopes=[FULFILLMENT_READ_SCOPE],
|
scopes=[FULFILLMENT_READ_SCOPE],
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue