openmeter 1.0.0b54__py3-none-any.whl → 2.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of openmeter might be problematic. Click here for more details.
- openmeter/__init__.py +89 -15
- openmeter/_base_client.py +2041 -0
- openmeter/_client.py +518 -70
- openmeter/_compat.py +221 -0
- openmeter/_constants.py +14 -0
- openmeter/_exceptions.py +108 -0
- openmeter/_files.py +127 -0
- openmeter/_models.py +777 -0
- openmeter/_qs.py +150 -0
- openmeter/_resource.py +43 -0
- openmeter/_response.py +820 -0
- openmeter/_streaming.py +333 -0
- openmeter/_types.py +222 -0
- openmeter/_utils/__init__.py +56 -0
- openmeter/_utils/_logs.py +25 -0
- openmeter/_utils/_proxy.py +63 -0
- openmeter/_utils/_reflection.py +42 -0
- openmeter/_utils/_streams.py +12 -0
- openmeter/_utils/_sync.py +81 -0
- openmeter/_utils/_transform.py +387 -0
- openmeter/_utils/_typing.py +120 -0
- openmeter/_utils/_utils.py +419 -0
- openmeter/_version.py +4 -0
- openmeter/lib/.keep +4 -0
- openmeter/py.typed +0 -1
- openmeter/resources/__init__.py +103 -0
- openmeter/resources/debug/__init__.py +33 -0
- openmeter/resources/debug/debug.py +102 -0
- openmeter/resources/debug/metrics.py +146 -0
- openmeter/resources/entitlements/__init__.py +47 -0
- openmeter/resources/entitlements/entitlements.py +450 -0
- openmeter/resources/entitlements/features.py +578 -0
- openmeter/resources/entitlements/grants.py +389 -0
- openmeter/resources/events.py +442 -0
- openmeter/resources/meters/__init__.py +33 -0
- openmeter/resources/meters/meters.py +666 -0
- openmeter/resources/meters/subjects.py +163 -0
- openmeter/resources/notifications/__init__.py +75 -0
- openmeter/resources/notifications/channels.py +686 -0
- openmeter/resources/notifications/events.py +365 -0
- openmeter/resources/notifications/notifications.py +198 -0
- openmeter/resources/notifications/rules.py +781 -0
- openmeter/resources/notifications/webhook.py +208 -0
- openmeter/resources/portal/__init__.py +47 -0
- openmeter/resources/portal/meters.py +230 -0
- openmeter/resources/portal/portal.py +112 -0
- openmeter/resources/portal/tokens.py +359 -0
- openmeter/resources/subjects/entitlements/__init__.py +33 -0
- openmeter/resources/subjects/entitlements/entitlements.py +1881 -0
- openmeter/resources/subjects/entitlements/grants.py +453 -0
- openmeter/resources/subjects.py +419 -0
- openmeter/types/__init__.py +21 -0
- openmeter/types/debug/__init__.py +5 -0
- openmeter/types/debug/metric_list_response.py +7 -0
- openmeter/types/entitlement.py +238 -0
- openmeter/types/entitlements/__init__.py +11 -0
- openmeter/types/entitlements/feature.py +61 -0
- openmeter/types/entitlements/feature_create_params.py +43 -0
- openmeter/types/entitlements/feature_list_params.py +23 -0
- openmeter/types/entitlements/grant_list_params.py +57 -0
- openmeter/types/entitlements/grant_list_response.py +11 -0
- openmeter/types/entitlements/grant_paginated_response.py +24 -0
- openmeter/types/entitlements/list_features_result.py +28 -0
- openmeter/types/event_ingest_params.py +46 -0
- openmeter/types/event_ingest_response.py +43 -0
- openmeter/types/event_list_params.py +22 -0
- openmeter/types/event_list_response.py +9 -0
- openmeter/types/ingested_event.py +59 -0
- openmeter/types/list_entitlements_result.py +28 -0
- openmeter/types/meter.py +53 -0
- openmeter/types/meter_create_params.py +50 -0
- openmeter/types/meter_list_response.py +9 -0
- openmeter/types/meter_query_params.py +50 -0
- openmeter/types/meter_query_result.py +35 -0
- openmeter/types/meters/__init__.py +5 -0
- openmeter/types/meters/subject_list_response.py +8 -0
- openmeter/types/notifications/__init__.py +18 -0
- openmeter/types/notifications/channel_create_params.py +34 -0
- openmeter/types/notifications/channel_list_params.py +41 -0
- openmeter/types/notifications/channel_list_response.py +24 -0
- openmeter/types/notifications/channel_update_params.py +34 -0
- openmeter/types/notifications/event_list_params.py +61 -0
- openmeter/types/notifications/event_list_response.py +24 -0
- openmeter/types/notifications/notification_channel.py +47 -0
- openmeter/types/notifications/notification_event.py +215 -0
- openmeter/types/notifications/notification_rule.py +70 -0
- openmeter/types/notifications/rule_create_params.py +39 -0
- openmeter/types/notifications/rule_list_params.py +54 -0
- openmeter/types/notifications/rule_list_response.py +24 -0
- openmeter/types/notifications/rule_update_params.py +39 -0
- openmeter/types/notifications/webhook_svix_params.py +26 -0
- openmeter/types/portal/__init__.py +10 -0
- openmeter/types/portal/meter_query_params.py +44 -0
- openmeter/types/portal/portal_token.py +28 -0
- openmeter/types/portal/token_create_params.py +17 -0
- openmeter/types/portal/token_invalidate_params.py +15 -0
- openmeter/types/portal/token_list_params.py +12 -0
- openmeter/types/portal/token_list_response.py +9 -0
- openmeter/types/shared/__init__.py +3 -0
- openmeter/types/subject.py +37 -0
- openmeter/types/subject_list_response.py +9 -0
- openmeter/types/subject_param.py +27 -0
- openmeter/types/subject_upsert_params.py +39 -0
- openmeter/types/subject_upsert_response.py +10 -0
- openmeter/types/subjects/__init__.py +13 -0
- openmeter/types/subjects/entitlement_history_params.py +35 -0
- openmeter/types/subjects/entitlement_history_response.py +98 -0
- openmeter/types/subjects/entitlement_list_response.py +10 -0
- openmeter/types/subjects/entitlements/__init__.py +8 -0
- openmeter/types/subjects/entitlements/entitlement_grant.py +103 -0
- openmeter/types/subjects/entitlements/grant_list_response.py +10 -0
- openmeter-2.0.0.dist-info/METADATA +396 -0
- openmeter-2.0.0.dist-info/RECORD +115 -0
- {openmeter-1.0.0b54.dist-info → openmeter-2.0.0.dist-info}/WHEEL +1 -1
- openmeter-2.0.0.dist-info/licenses/LICENSE +201 -0
- openmeter/_configuration.py +0 -36
- openmeter/_operations/__init__.py +0 -17
- openmeter/_operations/_operations.py +0 -2105
- openmeter/_operations/_patch.py +0 -20
- openmeter/_patch.py +0 -20
- openmeter/_serialization.py +0 -2008
- openmeter/_vendor.py +0 -24
- openmeter/aio/__init__.py +0 -21
- openmeter/aio/_client.py +0 -83
- openmeter/aio/_configuration.py +0 -36
- openmeter/aio/_operations/__init__.py +0 -17
- openmeter/aio/_operations/_operations.py +0 -1778
- openmeter/aio/_operations/_patch.py +0 -20
- openmeter/aio/_patch.py +0 -20
- openmeter/aio/_vendor.py +0 -24
- openmeter-1.0.0b54.dist-info/METADATA +0 -92
- openmeter-1.0.0b54.dist-info/RECORD +0 -21
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Dict, Union
|
|
6
|
+
from datetime import datetime
|
|
7
|
+
from typing_extensions import Literal
|
|
8
|
+
|
|
9
|
+
import httpx
|
|
10
|
+
|
|
11
|
+
from ...._types import NOT_GIVEN, Body, Query, Headers, NotGiven
|
|
12
|
+
from ...._utils import (
|
|
13
|
+
maybe_transform,
|
|
14
|
+
async_maybe_transform,
|
|
15
|
+
)
|
|
16
|
+
from ...._compat import cached_property
|
|
17
|
+
from ...._resource import SyncAPIResource, AsyncAPIResource
|
|
18
|
+
from ...._response import (
|
|
19
|
+
to_raw_response_wrapper,
|
|
20
|
+
to_streamed_response_wrapper,
|
|
21
|
+
async_to_raw_response_wrapper,
|
|
22
|
+
async_to_streamed_response_wrapper,
|
|
23
|
+
)
|
|
24
|
+
from ...._base_client import make_request_options
|
|
25
|
+
from ....types.subjects.entitlements import grant_list_params, grant_create_params
|
|
26
|
+
from ....types.subjects.entitlements.entitlement_grant import EntitlementGrant
|
|
27
|
+
from ....types.subjects.entitlements.grant_list_response import GrantListResponse
|
|
28
|
+
|
|
29
|
+
__all__ = ["GrantsResource", "AsyncGrantsResource"]
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class GrantsResource(SyncAPIResource):
|
|
33
|
+
@cached_property
|
|
34
|
+
def with_raw_response(self) -> GrantsResourceWithRawResponse:
|
|
35
|
+
"""
|
|
36
|
+
This property can be used as a prefix for any HTTP method call to return the
|
|
37
|
+
the raw response object instead of the parsed content.
|
|
38
|
+
|
|
39
|
+
For more information, see https://www.github.com/openmeterio/openmeter-python#accessing-raw-response-data-eg-headers
|
|
40
|
+
"""
|
|
41
|
+
return GrantsResourceWithRawResponse(self)
|
|
42
|
+
|
|
43
|
+
@cached_property
|
|
44
|
+
def with_streaming_response(self) -> GrantsResourceWithStreamingResponse:
|
|
45
|
+
"""
|
|
46
|
+
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
|
47
|
+
|
|
48
|
+
For more information, see https://www.github.com/openmeterio/openmeter-python#with_streaming_response
|
|
49
|
+
"""
|
|
50
|
+
return GrantsResourceWithStreamingResponse(self)
|
|
51
|
+
|
|
52
|
+
def create(
|
|
53
|
+
self,
|
|
54
|
+
entitlement_id_or_feature_key: str,
|
|
55
|
+
*,
|
|
56
|
+
subject_id_or_key: str,
|
|
57
|
+
amount: float,
|
|
58
|
+
effective_at: Union[str, datetime],
|
|
59
|
+
expiration: grant_create_params.Expiration,
|
|
60
|
+
max_rollover_amount: float | NotGiven = NOT_GIVEN,
|
|
61
|
+
metadata: Dict[str, str] | NotGiven = NOT_GIVEN,
|
|
62
|
+
min_rollover_amount: float | NotGiven = NOT_GIVEN,
|
|
63
|
+
priority: int | NotGiven = NOT_GIVEN,
|
|
64
|
+
recurrence: grant_create_params.Recurrence | NotGiven = NOT_GIVEN,
|
|
65
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
66
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
67
|
+
extra_headers: Headers | None = None,
|
|
68
|
+
extra_query: Query | None = None,
|
|
69
|
+
extra_body: Body | None = None,
|
|
70
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
71
|
+
) -> EntitlementGrant:
|
|
72
|
+
"""Grants define a behavior of granting usage for a metered entitlement.
|
|
73
|
+
|
|
74
|
+
They can
|
|
75
|
+
have complicated recurrence and rollover rules, thanks to which you can define a
|
|
76
|
+
wide range of access patterns with a single grant, in most cases you don't have
|
|
77
|
+
to periodically create new grants. You can only issue grants for active metered
|
|
78
|
+
entitlements.
|
|
79
|
+
|
|
80
|
+
A grant defines a given amount of usage that can be consumed for the
|
|
81
|
+
entitlement. The grant is in effect between its effective date and its
|
|
82
|
+
expiration date. Specifying both is mandatory for new grants.
|
|
83
|
+
|
|
84
|
+
Grants have a priority setting that determines their order of use. Lower numbers
|
|
85
|
+
have higher priority, with 0 being the highest priority.
|
|
86
|
+
|
|
87
|
+
Grants can have a recurrence setting intended to automate the manual reissuing
|
|
88
|
+
of grants. For example, a daily recurrence is equal to reissuing that same grant
|
|
89
|
+
every day (ignoring rollover settings).
|
|
90
|
+
|
|
91
|
+
Rollover settings define what happens to the remaining balance of a grant at a
|
|
92
|
+
reset. Balance_After_Reset = MIN(MaxRolloverAmount, MAX(Balance_Before_Reset,
|
|
93
|
+
MinRolloverAmount))
|
|
94
|
+
|
|
95
|
+
Grants cannot be changed once created, only deleted. This is to ensure that
|
|
96
|
+
balance is deterministic regardless of when it is queried.
|
|
97
|
+
|
|
98
|
+
Args:
|
|
99
|
+
amount: The amount to grant. Should be a positive number.
|
|
100
|
+
|
|
101
|
+
effective_at: Effective date for grants and anchor for recurring grants. Provided value will
|
|
102
|
+
be ceiled to metering windowSize (minute).
|
|
103
|
+
|
|
104
|
+
expiration: The grant expiration definition
|
|
105
|
+
|
|
106
|
+
max_rollover_amount: Grants are rolled over at reset, after which they can have a different balance
|
|
107
|
+
compared to what they had before the reset. Balance after the reset is
|
|
108
|
+
calculated as: Balance_After_Reset = MIN(MaxRolloverAmount,
|
|
109
|
+
MAX(Balance_Before_Reset, MinRolloverAmount))
|
|
110
|
+
|
|
111
|
+
metadata: Set of key-value pairs. Metadata can be used to store additional information
|
|
112
|
+
about a resource.
|
|
113
|
+
|
|
114
|
+
min_rollover_amount: Grants are rolled over at reset, after which they can have a different balance
|
|
115
|
+
compared to what they had before the reset. Balance after the reset is
|
|
116
|
+
calculated as: Balance_After_Reset = MIN(MaxRolloverAmount,
|
|
117
|
+
MAX(Balance_Before_Reset, MinRolloverAmount))
|
|
118
|
+
|
|
119
|
+
priority: The priority of the grant. Grants with higher priority are applied first.
|
|
120
|
+
Priority is a positive decimal numbers. With lower numbers indicating higher
|
|
121
|
+
importance. For example, a priority of 1 is more urgent than a priority of 2.
|
|
122
|
+
When there are several grants available for the same subject, the system selects
|
|
123
|
+
the grant with the highest priority. In cases where grants share the same
|
|
124
|
+
priority level, the grant closest to its expiration will be used first. In the
|
|
125
|
+
case of two grants have identical priorities and expiration dates, the system
|
|
126
|
+
will use the grant that was created first.
|
|
127
|
+
|
|
128
|
+
recurrence: Recurring period with an interval and an anchor.
|
|
129
|
+
|
|
130
|
+
extra_headers: Send extra headers
|
|
131
|
+
|
|
132
|
+
extra_query: Add additional query parameters to the request
|
|
133
|
+
|
|
134
|
+
extra_body: Add additional JSON properties to the request
|
|
135
|
+
|
|
136
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
137
|
+
"""
|
|
138
|
+
if not subject_id_or_key:
|
|
139
|
+
raise ValueError(f"Expected a non-empty value for `subject_id_or_key` but received {subject_id_or_key!r}")
|
|
140
|
+
if not entitlement_id_or_feature_key:
|
|
141
|
+
raise ValueError(
|
|
142
|
+
f"Expected a non-empty value for `entitlement_id_or_feature_key` but received {entitlement_id_or_feature_key!r}"
|
|
143
|
+
)
|
|
144
|
+
return self._post(
|
|
145
|
+
f"/api/v1/subjects/{subject_id_or_key}/entitlements/{entitlement_id_or_feature_key}/grants",
|
|
146
|
+
body=maybe_transform(
|
|
147
|
+
{
|
|
148
|
+
"amount": amount,
|
|
149
|
+
"effective_at": effective_at,
|
|
150
|
+
"expiration": expiration,
|
|
151
|
+
"max_rollover_amount": max_rollover_amount,
|
|
152
|
+
"metadata": metadata,
|
|
153
|
+
"min_rollover_amount": min_rollover_amount,
|
|
154
|
+
"priority": priority,
|
|
155
|
+
"recurrence": recurrence,
|
|
156
|
+
},
|
|
157
|
+
grant_create_params.GrantCreateParams,
|
|
158
|
+
),
|
|
159
|
+
options=make_request_options(
|
|
160
|
+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
161
|
+
),
|
|
162
|
+
cast_to=EntitlementGrant,
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
def list(
|
|
166
|
+
self,
|
|
167
|
+
entitlement_id_or_feature_key: str,
|
|
168
|
+
*,
|
|
169
|
+
subject_id_or_key: str,
|
|
170
|
+
include_deleted: bool | NotGiven = NOT_GIVEN,
|
|
171
|
+
order_by: Literal["id", "createdAt", "updatedAt"] | NotGiven = NOT_GIVEN,
|
|
172
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
173
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
174
|
+
extra_headers: Headers | None = None,
|
|
175
|
+
extra_query: Query | None = None,
|
|
176
|
+
extra_body: Body | None = None,
|
|
177
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
178
|
+
) -> GrantListResponse:
|
|
179
|
+
"""List all grants issued for an entitlement.
|
|
180
|
+
|
|
181
|
+
The entitlement can be defined either
|
|
182
|
+
by its id or featureKey.
|
|
183
|
+
|
|
184
|
+
Args:
|
|
185
|
+
order_by: Order by options for grants.
|
|
186
|
+
|
|
187
|
+
extra_headers: Send extra headers
|
|
188
|
+
|
|
189
|
+
extra_query: Add additional query parameters to the request
|
|
190
|
+
|
|
191
|
+
extra_body: Add additional JSON properties to the request
|
|
192
|
+
|
|
193
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
194
|
+
"""
|
|
195
|
+
if not subject_id_or_key:
|
|
196
|
+
raise ValueError(f"Expected a non-empty value for `subject_id_or_key` but received {subject_id_or_key!r}")
|
|
197
|
+
if not entitlement_id_or_feature_key:
|
|
198
|
+
raise ValueError(
|
|
199
|
+
f"Expected a non-empty value for `entitlement_id_or_feature_key` but received {entitlement_id_or_feature_key!r}"
|
|
200
|
+
)
|
|
201
|
+
return self._get(
|
|
202
|
+
f"/api/v1/subjects/{subject_id_or_key}/entitlements/{entitlement_id_or_feature_key}/grants",
|
|
203
|
+
options=make_request_options(
|
|
204
|
+
extra_headers=extra_headers,
|
|
205
|
+
extra_query=extra_query,
|
|
206
|
+
extra_body=extra_body,
|
|
207
|
+
timeout=timeout,
|
|
208
|
+
query=maybe_transform(
|
|
209
|
+
{
|
|
210
|
+
"include_deleted": include_deleted,
|
|
211
|
+
"order_by": order_by,
|
|
212
|
+
},
|
|
213
|
+
grant_list_params.GrantListParams,
|
|
214
|
+
),
|
|
215
|
+
),
|
|
216
|
+
cast_to=GrantListResponse,
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
class AsyncGrantsResource(AsyncAPIResource):
|
|
221
|
+
@cached_property
|
|
222
|
+
def with_raw_response(self) -> AsyncGrantsResourceWithRawResponse:
|
|
223
|
+
"""
|
|
224
|
+
This property can be used as a prefix for any HTTP method call to return the
|
|
225
|
+
the raw response object instead of the parsed content.
|
|
226
|
+
|
|
227
|
+
For more information, see https://www.github.com/openmeterio/openmeter-python#accessing-raw-response-data-eg-headers
|
|
228
|
+
"""
|
|
229
|
+
return AsyncGrantsResourceWithRawResponse(self)
|
|
230
|
+
|
|
231
|
+
@cached_property
|
|
232
|
+
def with_streaming_response(self) -> AsyncGrantsResourceWithStreamingResponse:
|
|
233
|
+
"""
|
|
234
|
+
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
|
235
|
+
|
|
236
|
+
For more information, see https://www.github.com/openmeterio/openmeter-python#with_streaming_response
|
|
237
|
+
"""
|
|
238
|
+
return AsyncGrantsResourceWithStreamingResponse(self)
|
|
239
|
+
|
|
240
|
+
async def create(
|
|
241
|
+
self,
|
|
242
|
+
entitlement_id_or_feature_key: str,
|
|
243
|
+
*,
|
|
244
|
+
subject_id_or_key: str,
|
|
245
|
+
amount: float,
|
|
246
|
+
effective_at: Union[str, datetime],
|
|
247
|
+
expiration: grant_create_params.Expiration,
|
|
248
|
+
max_rollover_amount: float | NotGiven = NOT_GIVEN,
|
|
249
|
+
metadata: Dict[str, str] | NotGiven = NOT_GIVEN,
|
|
250
|
+
min_rollover_amount: float | NotGiven = NOT_GIVEN,
|
|
251
|
+
priority: int | NotGiven = NOT_GIVEN,
|
|
252
|
+
recurrence: grant_create_params.Recurrence | NotGiven = NOT_GIVEN,
|
|
253
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
254
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
255
|
+
extra_headers: Headers | None = None,
|
|
256
|
+
extra_query: Query | None = None,
|
|
257
|
+
extra_body: Body | None = None,
|
|
258
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
259
|
+
) -> EntitlementGrant:
|
|
260
|
+
"""Grants define a behavior of granting usage for a metered entitlement.
|
|
261
|
+
|
|
262
|
+
They can
|
|
263
|
+
have complicated recurrence and rollover rules, thanks to which you can define a
|
|
264
|
+
wide range of access patterns with a single grant, in most cases you don't have
|
|
265
|
+
to periodically create new grants. You can only issue grants for active metered
|
|
266
|
+
entitlements.
|
|
267
|
+
|
|
268
|
+
A grant defines a given amount of usage that can be consumed for the
|
|
269
|
+
entitlement. The grant is in effect between its effective date and its
|
|
270
|
+
expiration date. Specifying both is mandatory for new grants.
|
|
271
|
+
|
|
272
|
+
Grants have a priority setting that determines their order of use. Lower numbers
|
|
273
|
+
have higher priority, with 0 being the highest priority.
|
|
274
|
+
|
|
275
|
+
Grants can have a recurrence setting intended to automate the manual reissuing
|
|
276
|
+
of grants. For example, a daily recurrence is equal to reissuing that same grant
|
|
277
|
+
every day (ignoring rollover settings).
|
|
278
|
+
|
|
279
|
+
Rollover settings define what happens to the remaining balance of a grant at a
|
|
280
|
+
reset. Balance_After_Reset = MIN(MaxRolloverAmount, MAX(Balance_Before_Reset,
|
|
281
|
+
MinRolloverAmount))
|
|
282
|
+
|
|
283
|
+
Grants cannot be changed once created, only deleted. This is to ensure that
|
|
284
|
+
balance is deterministic regardless of when it is queried.
|
|
285
|
+
|
|
286
|
+
Args:
|
|
287
|
+
amount: The amount to grant. Should be a positive number.
|
|
288
|
+
|
|
289
|
+
effective_at: Effective date for grants and anchor for recurring grants. Provided value will
|
|
290
|
+
be ceiled to metering windowSize (minute).
|
|
291
|
+
|
|
292
|
+
expiration: The grant expiration definition
|
|
293
|
+
|
|
294
|
+
max_rollover_amount: Grants are rolled over at reset, after which they can have a different balance
|
|
295
|
+
compared to what they had before the reset. Balance after the reset is
|
|
296
|
+
calculated as: Balance_After_Reset = MIN(MaxRolloverAmount,
|
|
297
|
+
MAX(Balance_Before_Reset, MinRolloverAmount))
|
|
298
|
+
|
|
299
|
+
metadata: Set of key-value pairs. Metadata can be used to store additional information
|
|
300
|
+
about a resource.
|
|
301
|
+
|
|
302
|
+
min_rollover_amount: Grants are rolled over at reset, after which they can have a different balance
|
|
303
|
+
compared to what they had before the reset. Balance after the reset is
|
|
304
|
+
calculated as: Balance_After_Reset = MIN(MaxRolloverAmount,
|
|
305
|
+
MAX(Balance_Before_Reset, MinRolloverAmount))
|
|
306
|
+
|
|
307
|
+
priority: The priority of the grant. Grants with higher priority are applied first.
|
|
308
|
+
Priority is a positive decimal numbers. With lower numbers indicating higher
|
|
309
|
+
importance. For example, a priority of 1 is more urgent than a priority of 2.
|
|
310
|
+
When there are several grants available for the same subject, the system selects
|
|
311
|
+
the grant with the highest priority. In cases where grants share the same
|
|
312
|
+
priority level, the grant closest to its expiration will be used first. In the
|
|
313
|
+
case of two grants have identical priorities and expiration dates, the system
|
|
314
|
+
will use the grant that was created first.
|
|
315
|
+
|
|
316
|
+
recurrence: Recurring period with an interval and an anchor.
|
|
317
|
+
|
|
318
|
+
extra_headers: Send extra headers
|
|
319
|
+
|
|
320
|
+
extra_query: Add additional query parameters to the request
|
|
321
|
+
|
|
322
|
+
extra_body: Add additional JSON properties to the request
|
|
323
|
+
|
|
324
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
325
|
+
"""
|
|
326
|
+
if not subject_id_or_key:
|
|
327
|
+
raise ValueError(f"Expected a non-empty value for `subject_id_or_key` but received {subject_id_or_key!r}")
|
|
328
|
+
if not entitlement_id_or_feature_key:
|
|
329
|
+
raise ValueError(
|
|
330
|
+
f"Expected a non-empty value for `entitlement_id_or_feature_key` but received {entitlement_id_or_feature_key!r}"
|
|
331
|
+
)
|
|
332
|
+
return await self._post(
|
|
333
|
+
f"/api/v1/subjects/{subject_id_or_key}/entitlements/{entitlement_id_or_feature_key}/grants",
|
|
334
|
+
body=await async_maybe_transform(
|
|
335
|
+
{
|
|
336
|
+
"amount": amount,
|
|
337
|
+
"effective_at": effective_at,
|
|
338
|
+
"expiration": expiration,
|
|
339
|
+
"max_rollover_amount": max_rollover_amount,
|
|
340
|
+
"metadata": metadata,
|
|
341
|
+
"min_rollover_amount": min_rollover_amount,
|
|
342
|
+
"priority": priority,
|
|
343
|
+
"recurrence": recurrence,
|
|
344
|
+
},
|
|
345
|
+
grant_create_params.GrantCreateParams,
|
|
346
|
+
),
|
|
347
|
+
options=make_request_options(
|
|
348
|
+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
349
|
+
),
|
|
350
|
+
cast_to=EntitlementGrant,
|
|
351
|
+
)
|
|
352
|
+
|
|
353
|
+
async def list(
|
|
354
|
+
self,
|
|
355
|
+
entitlement_id_or_feature_key: str,
|
|
356
|
+
*,
|
|
357
|
+
subject_id_or_key: str,
|
|
358
|
+
include_deleted: bool | NotGiven = NOT_GIVEN,
|
|
359
|
+
order_by: Literal["id", "createdAt", "updatedAt"] | NotGiven = NOT_GIVEN,
|
|
360
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
361
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
362
|
+
extra_headers: Headers | None = None,
|
|
363
|
+
extra_query: Query | None = None,
|
|
364
|
+
extra_body: Body | None = None,
|
|
365
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
366
|
+
) -> GrantListResponse:
|
|
367
|
+
"""List all grants issued for an entitlement.
|
|
368
|
+
|
|
369
|
+
The entitlement can be defined either
|
|
370
|
+
by its id or featureKey.
|
|
371
|
+
|
|
372
|
+
Args:
|
|
373
|
+
order_by: Order by options for grants.
|
|
374
|
+
|
|
375
|
+
extra_headers: Send extra headers
|
|
376
|
+
|
|
377
|
+
extra_query: Add additional query parameters to the request
|
|
378
|
+
|
|
379
|
+
extra_body: Add additional JSON properties to the request
|
|
380
|
+
|
|
381
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
382
|
+
"""
|
|
383
|
+
if not subject_id_or_key:
|
|
384
|
+
raise ValueError(f"Expected a non-empty value for `subject_id_or_key` but received {subject_id_or_key!r}")
|
|
385
|
+
if not entitlement_id_or_feature_key:
|
|
386
|
+
raise ValueError(
|
|
387
|
+
f"Expected a non-empty value for `entitlement_id_or_feature_key` but received {entitlement_id_or_feature_key!r}"
|
|
388
|
+
)
|
|
389
|
+
return await self._get(
|
|
390
|
+
f"/api/v1/subjects/{subject_id_or_key}/entitlements/{entitlement_id_or_feature_key}/grants",
|
|
391
|
+
options=make_request_options(
|
|
392
|
+
extra_headers=extra_headers,
|
|
393
|
+
extra_query=extra_query,
|
|
394
|
+
extra_body=extra_body,
|
|
395
|
+
timeout=timeout,
|
|
396
|
+
query=await async_maybe_transform(
|
|
397
|
+
{
|
|
398
|
+
"include_deleted": include_deleted,
|
|
399
|
+
"order_by": order_by,
|
|
400
|
+
},
|
|
401
|
+
grant_list_params.GrantListParams,
|
|
402
|
+
),
|
|
403
|
+
),
|
|
404
|
+
cast_to=GrantListResponse,
|
|
405
|
+
)
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
class GrantsResourceWithRawResponse:
|
|
409
|
+
def __init__(self, grants: GrantsResource) -> None:
|
|
410
|
+
self._grants = grants
|
|
411
|
+
|
|
412
|
+
self.create = to_raw_response_wrapper(
|
|
413
|
+
grants.create,
|
|
414
|
+
)
|
|
415
|
+
self.list = to_raw_response_wrapper(
|
|
416
|
+
grants.list,
|
|
417
|
+
)
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
class AsyncGrantsResourceWithRawResponse:
|
|
421
|
+
def __init__(self, grants: AsyncGrantsResource) -> None:
|
|
422
|
+
self._grants = grants
|
|
423
|
+
|
|
424
|
+
self.create = async_to_raw_response_wrapper(
|
|
425
|
+
grants.create,
|
|
426
|
+
)
|
|
427
|
+
self.list = async_to_raw_response_wrapper(
|
|
428
|
+
grants.list,
|
|
429
|
+
)
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
class GrantsResourceWithStreamingResponse:
|
|
433
|
+
def __init__(self, grants: GrantsResource) -> None:
|
|
434
|
+
self._grants = grants
|
|
435
|
+
|
|
436
|
+
self.create = to_streamed_response_wrapper(
|
|
437
|
+
grants.create,
|
|
438
|
+
)
|
|
439
|
+
self.list = to_streamed_response_wrapper(
|
|
440
|
+
grants.list,
|
|
441
|
+
)
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
class AsyncGrantsResourceWithStreamingResponse:
|
|
445
|
+
def __init__(self, grants: AsyncGrantsResource) -> None:
|
|
446
|
+
self._grants = grants
|
|
447
|
+
|
|
448
|
+
self.create = async_to_streamed_response_wrapper(
|
|
449
|
+
grants.create,
|
|
450
|
+
)
|
|
451
|
+
self.list = async_to_streamed_response_wrapper(
|
|
452
|
+
grants.list,
|
|
453
|
+
)
|