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
37 changes: 29 additions & 8 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ A list method returns its first page, such as a `AddOnsListPage`: a subclass of
model (`AddOnListResponse`) with the paging members `items`, `has_next_page()`, `get_next_page()`,
`iter_pages()` and `body`, which iterates every item. The page classes are in `meteroid.api`.

[Add ons](#add-ons) · [Batch jobs](#batch-jobs) · [Checkout sessions](#checkout-sessions) · [Connect](#connect) · [Coupons](#coupons) · [Credit notes](#credit-notes) · [Custom properties](#custom-properties) · [Customers](#customers) · [Entitlements](#entitlements) · [Events](#events) · [Features](#features) · [Invoices](#invoices) · [Metrics](#metrics) · [Oauth](#oauth) · [Oauth apps](#oauth-apps) · [Plans](#plans) · [Product families](#product-families) · [Products](#products) · [Subscriptions](#subscriptions) · [Usage](#usage)
[Add ons](#add-ons) · [Add ons entitlements](#add-ons-entitlements) · [Batch jobs](#batch-jobs) · [Checkout sessions](#checkout-sessions) · [Connect](#connect) · [Coupons](#coupons) · [Credit notes](#credit-notes) · [Custom properties](#custom-properties) · [Customers](#customers) · [Entitlements](#entitlements) · [Events](#events) · [Features](#features) · [Invoices](#invoices) · [Metrics](#metrics) · [Oauth](#oauth) · [Oauth apps](#oauth-apps) · [Plans](#plans) · [Plans versions](#plans-versions) · [Product families](#product-families) · [Products](#products) · [Products entitlements](#products-entitlements) · [Subscriptions](#subscriptions) · [Usage](#usage)

## Add ons

Expand All @@ -23,10 +23,17 @@ model (`AddOnListResponse`) with the paging members `items`, `has_next_page()`,
| `client.add_ons.retrieve(addon_id: str) -> AddOn` | `GET /api/v1/addons/{addon_id}` | [`AddOn`](meteroid/models/add_on.py) |
| `client.add_ons.update(addon_id: str, *, description=..., max_instances_per_subscription=..., name=..., price_id=..., self_serviceable=...) -> AddOn` | `PATCH /api/v1/addons/{addon_id}` | [`AddOn`](meteroid/models/add_on.py) |
| `client.add_ons.archive(addon_id: str) -> None` | `POST /api/v1/addons/{addon_id}/archive` | nothing |
| `client.add_ons.list_entitlements(addon_id: str) -> ResolvedEntitlementListResponse` | `GET /api/v1/addons/{addon_id}/entitlements` | [`ResolvedEntitlementListResponse`](meteroid/models/resolved_entitlement_list_response.py) |
| `client.add_ons.create_entitlement(addon_id: str, *, entitlements: list[EntitlementSpecRequest]) -> EntitlementListResponse` | `POST /api/v1/addons/{addon_id}/entitlements` | [`EntitlementListResponse`](meteroid/models/entitlement_list_response.py) |
| `client.add_ons.unarchive(addon_id: str) -> None` | `POST /api/v1/addons/{addon_id}/unarchive` | nothing |

### Add ons entitlements

[`client.add_ons.entitlements`](meteroid/api/add_ons_entitlements.py)

| Method | Request | Returns |
| --- | --- | --- |
| `client.add_ons.entitlements.list(addon_id: str) -> ResolvedEntitlementListResponse` | `GET /api/v1/addons/{addon_id}/entitlements` | [`ResolvedEntitlementListResponse`](meteroid/models/resolved_entitlement_list_response.py) |
| `client.add_ons.entitlements.create(addon_id: str, *, entitlements: list[EntitlementSpecRequest]) -> EntitlementListResponse` | `POST /api/v1/addons/{addon_id}/entitlements` | [`EntitlementListResponse`](meteroid/models/entitlement_list_response.py) |

## Batch jobs

[`client.batch_jobs`](meteroid/api/batch_jobs.py)
Expand Down Expand Up @@ -204,15 +211,22 @@ model (`AddOnListResponse`) with the paging members `items`, `has_next_page()`,
| `client.plans.create_plan_version_entitlement(plan_version_id: str, *, entitlements: list[EntitlementSpecRequest]) -> EntitlementListResponse` | `POST /api/v1/plan-versions/{plan_version_id}/entitlements` | [`EntitlementListResponse`](meteroid/models/entitlement_list_response.py) |
| `client.plans.list(*, product_family_id=..., search=..., status=..., plan_type=..., order_by=..., page=..., per_page=...) -> PlansListPage` | `GET /api/v1/plans` | [`PlanListResponse`](meteroid/models/plan_list_response.py) pages of [`Plan`](meteroid/models/plan.py) |
| `client.plans.create(*, components: list[PriceComponentInput], currency: str, name: str, plan_type: PlanTypeEnum, product_family_id: ProductFamilyId, status: PlanStatusEnum, add_ons=..., billing=..., description=..., entitlements=..., self_service_rank=..., tax_inclusive=..., trial=...) -> Plan` | `POST /api/v1/plans` | [`Plan`](meteroid/models/plan.py) |
| `client.plans.update_version_minimum(plan_version_id: str, *, amount: str, scope: MinimumCommitmentScope) -> MinimumCommitment` | `PUT /api/v1/plans/versions/{plan_version_id}/minimum` | [`MinimumCommitment`](meteroid/models/minimum_commitment.py) |
| `client.plans.delete_version_minimum(plan_version_id: str) -> None` | `DELETE /api/v1/plans/versions/{plan_version_id}/minimum` | nothing |
| `client.plans.retrieve(plan_id: str, *, version=...) -> Plan` | `GET /api/v1/plans/{plan_id}` | [`Plan`](meteroid/models/plan.py) |
| `client.plans.replace(plan_id: str, *, components: list[PriceComponentInput], currency: str, name: str, add_ons=..., billing=..., description=..., entitlements=..., minimum_commitment=..., status=..., tax_inclusive=..., trial=...) -> Plan` | `PUT /api/v1/plans/{plan_id}` | [`Plan`](meteroid/models/plan.py) |
| `client.plans.update(plan_id: str, *, description=..., name=..., self_service_rank=...) -> Plan` | `PATCH /api/v1/plans/{plan_id}` | [`Plan`](meteroid/models/plan.py) |
| `client.plans.archive(plan_id: str) -> None` | `POST /api/v1/plans/{plan_id}/archive` | nothing |
| `client.plans.publish(plan_id: str) -> Plan` | `POST /api/v1/plans/{plan_id}/publish` | [`Plan`](meteroid/models/plan.py) |
| `client.plans.unarchive(plan_id: str) -> None` | `POST /api/v1/plans/{plan_id}/unarchive` | nothing |
| `client.plans.list_versions(plan_id: str, *, page=..., per_page=...) -> PlansListVersionsPage` | `GET /api/v1/plans/{plan_id}/versions` | [`PlanVersionListResponse`](meteroid/models/plan_version_list_response.py) pages of [`PlanVersionSummary`](meteroid/models/plan_version_summary.py) |

### Plans versions

[`client.plans.versions`](meteroid/api/plans_versions.py)

| Method | Request | Returns |
| --- | --- | --- |
| `client.plans.versions.update_minimum(plan_version_id: str, *, amount: str, scope: MinimumCommitmentScope) -> MinimumCommitment` | `PUT /api/v1/plans/versions/{plan_version_id}/minimum` | [`MinimumCommitment`](meteroid/models/minimum_commitment.py) |
| `client.plans.versions.delete_minimum(plan_version_id: str) -> None` | `DELETE /api/v1/plans/versions/{plan_version_id}/minimum` | nothing |
| `client.plans.versions.list(plan_id: str, *, page=..., per_page=...) -> PlansVersionsListPage` | `GET /api/v1/plans/{plan_id}/versions` | [`PlanVersionListResponse`](meteroid/models/plan_version_list_response.py) pages of [`PlanVersionSummary`](meteroid/models/plan_version_summary.py) |

## Product families

Expand All @@ -235,10 +249,17 @@ model (`AddOnListResponse`) with the paging members `items`, `has_next_page()`,
| `client.products.retrieve(product_id: str) -> Product` | `GET /api/v1/products/{product_id}` | [`Product`](meteroid/models/product.py) |
| `client.products.update(product_id: str, *, description=..., fee_structure=..., name=...) -> Product` | `PATCH /api/v1/products/{product_id}` | [`Product`](meteroid/models/product.py) |
| `client.products.archive(product_id: str) -> None` | `POST /api/v1/products/{product_id}/archive` | nothing |
| `client.products.list_entitlements(product_id: str) -> ResolvedEntitlementListResponse` | `GET /api/v1/products/{product_id}/entitlements` | [`ResolvedEntitlementListResponse`](meteroid/models/resolved_entitlement_list_response.py) |
| `client.products.create_entitlement(product_id: str, *, entitlements: list[EntitlementSpecRequest]) -> EntitlementListResponse` | `POST /api/v1/products/{product_id}/entitlements` | [`EntitlementListResponse`](meteroid/models/entitlement_list_response.py) |
| `client.products.unarchive(product_id: str) -> None` | `POST /api/v1/products/{product_id}/unarchive` | nothing |

### Products entitlements

[`client.products.entitlements`](meteroid/api/products_entitlements.py)

| Method | Request | Returns |
| --- | --- | --- |
| `client.products.entitlements.list(product_id: str) -> ResolvedEntitlementListResponse` | `GET /api/v1/products/{product_id}/entitlements` | [`ResolvedEntitlementListResponse`](meteroid/models/resolved_entitlement_list_response.py) |
| `client.products.entitlements.create(product_id: str, *, entitlements: list[EntitlementSpecRequest]) -> EntitlementListResponse` | `POST /api/v1/products/{product_id}/entitlements` | [`EntitlementListResponse`](meteroid/models/entitlement_list_response.py) |

## Subscriptions

[`client.subscriptions`](meteroid/api/subscriptions.py)
Expand Down
27 changes: 21 additions & 6 deletions meteroid/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
AsyncInvoicesListPage,
AsyncMetricsListPage,
AsyncPlansListPage,
AsyncPlansListVersionsPage,
AsyncPlansVersionsListPage,
AsyncProductFamiliesListPage,
AsyncProductsListPage,
AsyncSubscriptionsListPage,
Expand All @@ -65,12 +65,13 @@
InvoicesListPage,
MetricsListPage,
PlansListPage,
PlansListVersionsPage,
PlansVersionsListPage,
ProductFamiliesListPage,
ProductsListPage,
SubscriptionsListPage,
)
from .add_ons import AddOns, AsyncAddOns
from .add_ons_entitlements import AddOnsEntitlements, AsyncAddOnsEntitlements
from .batch_jobs import AsyncBatchJobs, BatchJobs
from .checkout_sessions import AsyncCheckoutSessions, CheckoutSessions
from .connect import AsyncConnect, Connect
Expand All @@ -86,15 +87,19 @@
from .oauth import AsyncOauth, Oauth
from .oauth_apps import AsyncOauthApps, OauthApps
from .plans import AsyncPlans, Plans
from .plans_versions import AsyncPlansVersions, PlansVersions
from .product_families import AsyncProductFamilies, ProductFamilies
from .products import AsyncProducts, Products
from .products_entitlements import AsyncProductsEntitlements, ProductsEntitlements
from .subscriptions import AsyncSubscriptions, Subscriptions
from .usage import AsyncUsage, Usage

# Each resource's module is imported the first time it is used.
_MODULES: dict[str, str] = {
"AsyncAddOns": "add_ons",
"AddOns": "add_ons",
"AsyncAddOnsEntitlements": "add_ons_entitlements",
"AddOnsEntitlements": "add_ons_entitlements",
"AsyncBatchJobs": "batch_jobs",
"BatchJobs": "batch_jobs",
"AsyncCheckoutSessions": "checkout_sessions",
Expand Down Expand Up @@ -125,10 +130,14 @@
"OauthApps": "oauth_apps",
"AsyncPlans": "plans",
"Plans": "plans",
"AsyncPlansVersions": "plans_versions",
"PlansVersions": "plans_versions",
"AsyncProductFamilies": "product_families",
"ProductFamilies": "product_families",
"AsyncProducts": "products",
"Products": "products",
"AsyncProductsEntitlements": "products_entitlements",
"ProductsEntitlements": "products_entitlements",
"AsyncSubscriptions": "subscriptions",
"Subscriptions": "subscriptions",
"AsyncUsage": "usage",
Expand All @@ -155,8 +164,8 @@
"MetricsListPage": "_pages",
"AsyncPlansListPage": "_pages",
"PlansListPage": "_pages",
"AsyncPlansListVersionsPage": "_pages",
"PlansListVersionsPage": "_pages",
"AsyncPlansVersionsListPage": "_pages",
"PlansVersionsListPage": "_pages",
"AsyncProductFamiliesListPage": "_pages",
"ProductFamiliesListPage": "_pages",
"AsyncProductsListPage": "_pages",
Expand Down Expand Up @@ -209,6 +218,8 @@ def __dir__() -> list[str]:
"UnprocessableEntityError",
"AsyncAddOns",
"AddOns",
"AsyncAddOnsEntitlements",
"AddOnsEntitlements",
"AsyncBatchJobs",
"BatchJobs",
"AsyncCheckoutSessions",
Expand Down Expand Up @@ -239,10 +250,14 @@ def __dir__() -> list[str]:
"OauthApps",
"AsyncPlans",
"Plans",
"AsyncPlansVersions",
"PlansVersions",
"AsyncProductFamilies",
"ProductFamilies",
"AsyncProducts",
"Products",
"AsyncProductsEntitlements",
"ProductsEntitlements",
"AsyncSubscriptions",
"Subscriptions",
"AsyncUsage",
Expand All @@ -269,8 +284,8 @@ def __dir__() -> list[str]:
"MetricsListPage",
"AsyncPlansListPage",
"PlansListPage",
"AsyncPlansListVersionsPage",
"PlansListVersionsPage",
"AsyncPlansVersionsListPage",
"PlansVersionsListPage",
"AsyncProductFamiliesListPage",
"ProductFamiliesListPage",
"AsyncProductsListPage",
Expand Down
8 changes: 4 additions & 4 deletions meteroid/api/_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
"MetricsListPage",
"AsyncPlansListPage",
"PlansListPage",
"AsyncPlansListVersionsPage",
"PlansListVersionsPage",
"AsyncPlansVersionsListPage",
"PlansVersionsListPage",
"AsyncProductFamiliesListPage",
"ProductFamiliesListPage",
"AsyncProductsListPage",
Expand Down Expand Up @@ -187,13 +187,13 @@ class AsyncPlansListPage(AsyncPage[Plan, PlanListResponse], PlanListResponse):
"""A page of :class:`Plan`, and the :class:`PlanListResponse` response of its request."""


class PlansListVersionsPage(
class PlansVersionsListPage(
SyncPage[PlanVersionSummary, PlanVersionListResponse], PlanVersionListResponse
):
"""A page of :class:`PlanVersionSummary`, and the :class:`PlanVersionListResponse` response of its request."""


class AsyncPlansListVersionsPage(
class AsyncPlansVersionsListPage(
AsyncPage[PlanVersionSummary, PlanVersionListResponse], PlanVersionListResponse
):
"""A page of :class:`PlanVersionSummary`, and the :class:`PlanVersionListResponse` response of its request."""
Expand Down
6 changes: 4 additions & 2 deletions meteroid/api/_pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,12 @@ def _more(self, body: _Body, items: t.Sequence[_Item]) -> bool:

@dataclasses.dataclass(frozen=True)
class CursorPaging(Paging[_Body, _Item, str]):
"""The next page starts after a cursor: one the page gives, or the last item's."""
"""The next page starts after a cursor: one the page gives, or the last item's. Paging
``backwards``, it ends before the first item's."""

next_cursor: t.Callable[[_Body], str | Unset | None] | None = None
item_cursor: t.Callable[[_Item], str | Unset | None] | None = None
backwards: bool = False

def next(
self, param: str | None, body: _Body, items: t.Sequence[_Item]
Expand All @@ -86,7 +88,7 @@ def next(
if self.next_cursor is not None:
cursor = self.next_cursor(body)
elif self.item_cursor is not None:
cursor = self.item_cursor(items[-1])
cursor = self.item_cursor(items[0] if self.backwards else items[-1])
else:
cursor = None
return (
Expand Down
Loading
Loading