openmeter 1.0.0b53__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.

Files changed (132) hide show
  1. openmeter/__init__.py +89 -15
  2. openmeter/_base_client.py +2041 -0
  3. openmeter/_client.py +518 -70
  4. openmeter/_compat.py +221 -0
  5. openmeter/_constants.py +14 -0
  6. openmeter/_exceptions.py +108 -0
  7. openmeter/_files.py +127 -0
  8. openmeter/_models.py +777 -0
  9. openmeter/_qs.py +150 -0
  10. openmeter/_resource.py +43 -0
  11. openmeter/_response.py +820 -0
  12. openmeter/_streaming.py +333 -0
  13. openmeter/_types.py +222 -0
  14. openmeter/_utils/__init__.py +56 -0
  15. openmeter/_utils/_logs.py +25 -0
  16. openmeter/_utils/_proxy.py +63 -0
  17. openmeter/_utils/_reflection.py +42 -0
  18. openmeter/_utils/_streams.py +12 -0
  19. openmeter/_utils/_sync.py +81 -0
  20. openmeter/_utils/_transform.py +387 -0
  21. openmeter/_utils/_typing.py +120 -0
  22. openmeter/_utils/_utils.py +419 -0
  23. openmeter/_version.py +4 -0
  24. openmeter/lib/.keep +4 -0
  25. openmeter/py.typed +0 -1
  26. openmeter/resources/__init__.py +103 -0
  27. openmeter/resources/debug/__init__.py +33 -0
  28. openmeter/resources/debug/debug.py +102 -0
  29. openmeter/resources/debug/metrics.py +146 -0
  30. openmeter/resources/entitlements/__init__.py +47 -0
  31. openmeter/resources/entitlements/entitlements.py +450 -0
  32. openmeter/resources/entitlements/features.py +578 -0
  33. openmeter/resources/entitlements/grants.py +389 -0
  34. openmeter/resources/events.py +442 -0
  35. openmeter/resources/meters/__init__.py +33 -0
  36. openmeter/resources/meters/meters.py +666 -0
  37. openmeter/resources/meters/subjects.py +163 -0
  38. openmeter/resources/notifications/__init__.py +75 -0
  39. openmeter/resources/notifications/channels.py +686 -0
  40. openmeter/resources/notifications/events.py +365 -0
  41. openmeter/resources/notifications/notifications.py +198 -0
  42. openmeter/resources/notifications/rules.py +781 -0
  43. openmeter/resources/notifications/webhook.py +208 -0
  44. openmeter/resources/portal/__init__.py +47 -0
  45. openmeter/resources/portal/meters.py +230 -0
  46. openmeter/resources/portal/portal.py +112 -0
  47. openmeter/resources/portal/tokens.py +359 -0
  48. openmeter/resources/subjects/entitlements/__init__.py +33 -0
  49. openmeter/resources/subjects/entitlements/entitlements.py +1881 -0
  50. openmeter/resources/subjects/entitlements/grants.py +453 -0
  51. openmeter/resources/subjects.py +419 -0
  52. openmeter/types/__init__.py +21 -0
  53. openmeter/types/debug/__init__.py +5 -0
  54. openmeter/types/debug/metric_list_response.py +7 -0
  55. openmeter/types/entitlement.py +238 -0
  56. openmeter/types/entitlements/__init__.py +11 -0
  57. openmeter/types/entitlements/feature.py +61 -0
  58. openmeter/types/entitlements/feature_create_params.py +43 -0
  59. openmeter/types/entitlements/feature_list_params.py +23 -0
  60. openmeter/types/entitlements/grant_list_params.py +57 -0
  61. openmeter/types/entitlements/grant_list_response.py +11 -0
  62. openmeter/types/entitlements/grant_paginated_response.py +24 -0
  63. openmeter/types/entitlements/list_features_result.py +28 -0
  64. openmeter/types/event_ingest_params.py +46 -0
  65. openmeter/types/event_ingest_response.py +43 -0
  66. openmeter/types/event_list_params.py +22 -0
  67. openmeter/types/event_list_response.py +9 -0
  68. openmeter/types/ingested_event.py +59 -0
  69. openmeter/types/list_entitlements_result.py +28 -0
  70. openmeter/types/meter.py +53 -0
  71. openmeter/types/meter_create_params.py +50 -0
  72. openmeter/types/meter_list_response.py +9 -0
  73. openmeter/types/meter_query_params.py +50 -0
  74. openmeter/types/meter_query_result.py +35 -0
  75. openmeter/types/meters/__init__.py +5 -0
  76. openmeter/types/meters/subject_list_response.py +8 -0
  77. openmeter/types/notifications/__init__.py +18 -0
  78. openmeter/types/notifications/channel_create_params.py +34 -0
  79. openmeter/types/notifications/channel_list_params.py +41 -0
  80. openmeter/types/notifications/channel_list_response.py +24 -0
  81. openmeter/types/notifications/channel_update_params.py +34 -0
  82. openmeter/types/notifications/event_list_params.py +61 -0
  83. openmeter/types/notifications/event_list_response.py +24 -0
  84. openmeter/types/notifications/notification_channel.py +47 -0
  85. openmeter/types/notifications/notification_event.py +215 -0
  86. openmeter/types/notifications/notification_rule.py +70 -0
  87. openmeter/types/notifications/rule_create_params.py +39 -0
  88. openmeter/types/notifications/rule_list_params.py +54 -0
  89. openmeter/types/notifications/rule_list_response.py +24 -0
  90. openmeter/types/notifications/rule_update_params.py +39 -0
  91. openmeter/types/notifications/webhook_svix_params.py +26 -0
  92. openmeter/types/portal/__init__.py +10 -0
  93. openmeter/types/portal/meter_query_params.py +44 -0
  94. openmeter/types/portal/portal_token.py +28 -0
  95. openmeter/types/portal/token_create_params.py +17 -0
  96. openmeter/types/portal/token_invalidate_params.py +15 -0
  97. openmeter/types/portal/token_list_params.py +12 -0
  98. openmeter/types/portal/token_list_response.py +9 -0
  99. openmeter/types/shared/__init__.py +3 -0
  100. openmeter/types/subject.py +37 -0
  101. openmeter/types/subject_list_response.py +9 -0
  102. openmeter/types/subject_param.py +27 -0
  103. openmeter/types/subject_upsert_params.py +39 -0
  104. openmeter/types/subject_upsert_response.py +10 -0
  105. openmeter/types/subjects/__init__.py +13 -0
  106. openmeter/types/subjects/entitlement_history_params.py +35 -0
  107. openmeter/types/subjects/entitlement_history_response.py +98 -0
  108. openmeter/types/subjects/entitlement_list_response.py +10 -0
  109. openmeter/types/subjects/entitlements/__init__.py +8 -0
  110. openmeter/types/subjects/entitlements/entitlement_grant.py +103 -0
  111. openmeter/types/subjects/entitlements/grant_list_response.py +10 -0
  112. openmeter-2.0.0.dist-info/METADATA +396 -0
  113. openmeter-2.0.0.dist-info/RECORD +115 -0
  114. {openmeter-1.0.0b53.dist-info → openmeter-2.0.0.dist-info}/WHEEL +1 -1
  115. openmeter-2.0.0.dist-info/licenses/LICENSE +201 -0
  116. openmeter/_configuration.py +0 -36
  117. openmeter/_operations/__init__.py +0 -17
  118. openmeter/_operations/_operations.py +0 -2098
  119. openmeter/_operations/_patch.py +0 -20
  120. openmeter/_patch.py +0 -20
  121. openmeter/_serialization.py +0 -2008
  122. openmeter/_vendor.py +0 -24
  123. openmeter/aio/__init__.py +0 -21
  124. openmeter/aio/_client.py +0 -83
  125. openmeter/aio/_configuration.py +0 -36
  126. openmeter/aio/_operations/__init__.py +0 -17
  127. openmeter/aio/_operations/_operations.py +0 -1771
  128. openmeter/aio/_operations/_patch.py +0 -20
  129. openmeter/aio/_patch.py +0 -20
  130. openmeter/aio/_vendor.py +0 -24
  131. openmeter-1.0.0b53.dist-info/METADATA +0 -92
  132. openmeter-1.0.0b53.dist-info/RECORD +0 -21
@@ -1,2098 +0,0 @@
1
- # pylint: disable=too-many-lines
2
- # coding=utf-8
3
- # --------------------------------------------------------------------------
4
- # Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.1, generator: @autorest/python@6.9.4)
5
- # Changes may cause incorrect behavior and will be lost if the code is regenerated.
6
- # --------------------------------------------------------------------------
7
- import datetime
8
- from io import IOBase
9
- import sys
10
- from typing import Any, Callable, Dict, IO, List, Optional, TypeVar, Union, cast, overload
11
-
12
- from azure.core.exceptions import (
13
- ClientAuthenticationError,
14
- HttpResponseError,
15
- ResourceExistsError,
16
- ResourceNotFoundError,
17
- ResourceNotModifiedError,
18
- map_error,
19
- )
20
- from azure.core.pipeline import PipelineResponse
21
- from azure.core.rest import HttpRequest, HttpResponse
22
- from azure.core.tracing.decorator import distributed_trace
23
- from azure.core.utils import case_insensitive_dict
24
-
25
- from .._serialization import Serializer
26
- from .._vendor import ClientMixinABC
27
-
28
- if sys.version_info >= (3, 9):
29
- from collections.abc import MutableMapping
30
- else:
31
- from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports
32
- JSON = MutableMapping[str, Any] # pylint: disable=unsubscriptable-object
33
- T = TypeVar("T")
34
- ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]]
35
-
36
- _SERIALIZER = Serializer()
37
- _SERIALIZER.client_side_validation = False
38
-
39
-
40
- def build_ingest_events_request(**kwargs: Any) -> HttpRequest:
41
- _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
42
-
43
- content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
44
- accept = _headers.pop("Accept", "application/problem+json")
45
-
46
- # Construct URL
47
- _url = "/api/v1/events"
48
-
49
- # Construct headers
50
- if content_type is not None:
51
- _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str")
52
- _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")
53
-
54
- return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs)
55
-
56
-
57
- def build_list_events_request(
58
- *,
59
- from_parameter: Optional[datetime.datetime] = None,
60
- to: Optional[datetime.datetime] = None,
61
- limit: Optional[int] = None,
62
- **kwargs: Any
63
- ) -> HttpRequest:
64
- _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
65
- _params = case_insensitive_dict(kwargs.pop("params", {}) or {})
66
-
67
- accept = _headers.pop("Accept", "application/json, application/problem+json")
68
-
69
- # Construct URL
70
- _url = "/api/v1/events"
71
-
72
- # Construct parameters
73
- if from_parameter is not None:
74
- _params["from"] = _SERIALIZER.query("from_parameter", from_parameter, "iso-8601")
75
- if to is not None:
76
- _params["to"] = _SERIALIZER.query("to", to, "iso-8601")
77
- if limit is not None:
78
- _params["limit"] = _SERIALIZER.query("limit", limit, "int", maximum=100, minimum=1)
79
-
80
- # Construct headers
81
- _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")
82
-
83
- return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs)
84
-
85
-
86
- def build_list_meters_request(**kwargs: Any) -> HttpRequest:
87
- _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
88
-
89
- accept = _headers.pop("Accept", "application/json, application/problem+json")
90
-
91
- # Construct URL
92
- _url = "/api/v1/meters"
93
-
94
- # Construct headers
95
- _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")
96
-
97
- return HttpRequest(method="GET", url=_url, headers=_headers, **kwargs)
98
-
99
-
100
- def build_create_meter_request(**kwargs: Any) -> HttpRequest:
101
- _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
102
-
103
- content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
104
- accept = _headers.pop("Accept", "application/json, application/problem+json")
105
-
106
- # Construct URL
107
- _url = "/api/v1/meters"
108
-
109
- # Construct headers
110
- if content_type is not None:
111
- _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str")
112
- _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")
113
-
114
- return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs)
115
-
116
-
117
- def build_get_meter_request(meter_id_or_slug: str, **kwargs: Any) -> HttpRequest:
118
- _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
119
-
120
- accept = _headers.pop("Accept", "application/json, application/problem+json")
121
-
122
- # Construct URL
123
- _url = "/api/v1/meters/{meterIdOrSlug}"
124
- path_format_arguments = {
125
- "meterIdOrSlug": _SERIALIZER.url("meter_id_or_slug", meter_id_or_slug, "str"),
126
- }
127
-
128
- _url: str = _url.format(**path_format_arguments) # type: ignore
129
-
130
- # Construct headers
131
- _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")
132
-
133
- return HttpRequest(method="GET", url=_url, headers=_headers, **kwargs)
134
-
135
-
136
- def build_delete_meter_request(meter_id_or_slug: str, **kwargs: Any) -> HttpRequest:
137
- _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
138
-
139
- accept = _headers.pop("Accept", "application/problem+json")
140
-
141
- # Construct URL
142
- _url = "/api/v1/meters/{meterIdOrSlug}"
143
- path_format_arguments = {
144
- "meterIdOrSlug": _SERIALIZER.url("meter_id_or_slug", meter_id_or_slug, "str"),
145
- }
146
-
147
- _url: str = _url.format(**path_format_arguments) # type: ignore
148
-
149
- # Construct headers
150
- _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")
151
-
152
- return HttpRequest(method="DELETE", url=_url, headers=_headers, **kwargs)
153
-
154
-
155
- def build_query_meter_request(
156
- meter_id_or_slug: str,
157
- *,
158
- from_parameter: Optional[datetime.datetime] = None,
159
- to: Optional[datetime.datetime] = None,
160
- window_size: Optional[str] = None,
161
- window_time_zone: str = "UTC",
162
- subject: Optional[List[str]] = None,
163
- group_by: Optional[List[str]] = None,
164
- **kwargs: Any
165
- ) -> HttpRequest:
166
- _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
167
- _params = case_insensitive_dict(kwargs.pop("params", {}) or {})
168
-
169
- accept = _headers.pop("Accept", "application/json, text/csv, application/problem+json")
170
-
171
- # Construct URL
172
- _url = "/api/v1/meters/{meterIdOrSlug}/query"
173
- path_format_arguments = {
174
- "meterIdOrSlug": _SERIALIZER.url("meter_id_or_slug", meter_id_or_slug, "str"),
175
- }
176
-
177
- _url: str = _url.format(**path_format_arguments) # type: ignore
178
-
179
- # Construct parameters
180
- if from_parameter is not None:
181
- _params["from"] = _SERIALIZER.query("from_parameter", from_parameter, "iso-8601")
182
- if to is not None:
183
- _params["to"] = _SERIALIZER.query("to", to, "iso-8601")
184
- if window_size is not None:
185
- _params["windowSize"] = _SERIALIZER.query("window_size", window_size, "str")
186
- if window_time_zone is not None:
187
- _params["windowTimeZone"] = _SERIALIZER.query("window_time_zone", window_time_zone, "str")
188
- if subject is not None:
189
- _params["subject"] = _SERIALIZER.query("subject", subject, "[str]")
190
- if group_by is not None:
191
- _params["groupBy"] = _SERIALIZER.query("group_by", group_by, "[str]")
192
-
193
- # Construct headers
194
- _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")
195
-
196
- return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs)
197
-
198
-
199
- def build_list_meter_subjects_request(meter_id_or_slug: str, **kwargs: Any) -> HttpRequest:
200
- _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
201
-
202
- accept = _headers.pop("Accept", "application/json, application/problem+json")
203
-
204
- # Construct URL
205
- _url = "/api/v1/meters/{meterIdOrSlug}/subjects"
206
- path_format_arguments = {
207
- "meterIdOrSlug": _SERIALIZER.url("meter_id_or_slug", meter_id_or_slug, "str"),
208
- }
209
-
210
- _url: str = _url.format(**path_format_arguments) # type: ignore
211
-
212
- # Construct headers
213
- _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")
214
-
215
- return HttpRequest(method="GET", url=_url, headers=_headers, **kwargs)
216
-
217
-
218
- def build_create_portal_token_request(**kwargs: Any) -> HttpRequest:
219
- _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
220
-
221
- content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
222
- accept = _headers.pop("Accept", "application/json, application/problem+json")
223
-
224
- # Construct URL
225
- _url = "/api/v1/portal/tokens"
226
-
227
- # Construct headers
228
- if content_type is not None:
229
- _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str")
230
- _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")
231
-
232
- return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs)
233
-
234
-
235
- def build_list_portal_tokens_request(*, limit: int = 25, **kwargs: Any) -> HttpRequest:
236
- _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
237
- _params = case_insensitive_dict(kwargs.pop("params", {}) or {})
238
-
239
- accept = _headers.pop("Accept", "application/json, application/problem+json")
240
-
241
- # Construct URL
242
- _url = "/api/v1/portal/tokens"
243
-
244
- # Construct parameters
245
- if limit is not None:
246
- _params["limit"] = _SERIALIZER.query("limit", limit, "int", maximum=100, minimum=1)
247
-
248
- # Construct headers
249
- _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")
250
-
251
- return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs)
252
-
253
-
254
- def build_invalidate_portal_tokens_request(**kwargs: Any) -> HttpRequest:
255
- _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
256
-
257
- content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
258
- accept = _headers.pop("Accept", "application/problem+json")
259
-
260
- # Construct URL
261
- _url = "/api/v1/portal/tokens/invalidate"
262
-
263
- # Construct headers
264
- if content_type is not None:
265
- _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str")
266
- _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")
267
-
268
- return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs)
269
-
270
-
271
- def build_list_subjects_request(**kwargs: Any) -> HttpRequest:
272
- _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
273
-
274
- accept = _headers.pop("Accept", "application/json, application/problem+json")
275
-
276
- # Construct URL
277
- _url = "/api/v1/subjects"
278
-
279
- # Construct headers
280
- _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")
281
-
282
- return HttpRequest(method="GET", url=_url, headers=_headers, **kwargs)
283
-
284
-
285
- def build_upsert_subject_request(**kwargs: Any) -> HttpRequest:
286
- _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
287
-
288
- content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
289
- accept = _headers.pop("Accept", "application/json, application/problem+json")
290
-
291
- # Construct URL
292
- _url = "/api/v1/subjects"
293
-
294
- # Construct headers
295
- if content_type is not None:
296
- _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str")
297
- _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")
298
-
299
- return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs)
300
-
301
-
302
- def build_get_subject_request(subject_id_or_key: str, **kwargs: Any) -> HttpRequest:
303
- _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
304
-
305
- accept = _headers.pop("Accept", "application/json, application/problem+json")
306
-
307
- # Construct URL
308
- _url = "/api/v1/subjects/{subjectIdOrKey}"
309
- path_format_arguments = {
310
- "subjectIdOrKey": _SERIALIZER.url("subject_id_or_key", subject_id_or_key, "str"),
311
- }
312
-
313
- _url: str = _url.format(**path_format_arguments) # type: ignore
314
-
315
- # Construct headers
316
- _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")
317
-
318
- return HttpRequest(method="GET", url=_url, headers=_headers, **kwargs)
319
-
320
-
321
- def build_delete_subject_request(subject_id_or_key: str, **kwargs: Any) -> HttpRequest:
322
- _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
323
-
324
- accept = _headers.pop("Accept", "application/problem+json")
325
-
326
- # Construct URL
327
- _url = "/api/v1/subjects/{subjectIdOrKey}"
328
- path_format_arguments = {
329
- "subjectIdOrKey": _SERIALIZER.url("subject_id_or_key", subject_id_or_key, "str"),
330
- }
331
-
332
- _url: str = _url.format(**path_format_arguments) # type: ignore
333
-
334
- # Construct headers
335
- _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")
336
-
337
- return HttpRequest(method="DELETE", url=_url, headers=_headers, **kwargs)
338
-
339
-
340
- def build_query_portal_meter_request(
341
- meter_slug: str,
342
- *,
343
- from_parameter: Optional[datetime.datetime] = None,
344
- to: Optional[datetime.datetime] = None,
345
- window_size: Optional[str] = None,
346
- window_time_zone: str = "UTC",
347
- group_by: Optional[List[str]] = None,
348
- **kwargs: Any
349
- ) -> HttpRequest:
350
- _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
351
- _params = case_insensitive_dict(kwargs.pop("params", {}) or {})
352
-
353
- accept = _headers.pop("Accept", "application/json, text/csv, application/problem+json")
354
-
355
- # Construct URL
356
- _url = "/api/v1/portal/meters/{meterSlug}/query"
357
- path_format_arguments = {
358
- "meterSlug": _SERIALIZER.url("meter_slug", meter_slug, "str"),
359
- }
360
-
361
- _url: str = _url.format(**path_format_arguments) # type: ignore
362
-
363
- # Construct parameters
364
- if from_parameter is not None:
365
- _params["from"] = _SERIALIZER.query("from_parameter", from_parameter, "iso-8601")
366
- if to is not None:
367
- _params["to"] = _SERIALIZER.query("to", to, "iso-8601")
368
- if window_size is not None:
369
- _params["windowSize"] = _SERIALIZER.query("window_size", window_size, "str")
370
- if window_time_zone is not None:
371
- _params["windowTimeZone"] = _SERIALIZER.query("window_time_zone", window_time_zone, "str")
372
- if group_by is not None:
373
- _params["groupBy"] = _SERIALIZER.query("group_by", group_by, "[str]")
374
-
375
- # Construct headers
376
- _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")
377
-
378
- return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs)
379
-
380
-
381
- class ClientOperationsMixin(ClientMixinABC):
382
- @overload
383
- def ingest_events( # pylint: disable=inconsistent-return-statements
384
- self, body: JSON, *, content_type: str = "application/cloudevents+json", **kwargs: Any
385
- ) -> None:
386
- """Ingest events.
387
-
388
- :param body: Required.
389
- :type body: JSON
390
- :keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
391
- Default value is "application/cloudevents+json".
392
- :paramtype content_type: str
393
- :return: None
394
- :rtype: None
395
- :raises ~azure.core.exceptions.HttpResponseError:
396
-
397
- Example:
398
- .. code-block:: python
399
-
400
- # JSON input template you can fill out and use as your body input.
401
- body = {
402
- "id": "str", # Identifies the event. Required.
403
- "source": "str", # Identifies the context in which an event happened.
404
- Required.
405
- "specversion": "str", # The version of the CloudEvents specification which
406
- the event uses. Required.
407
- "subject": "str", # Describes the subject of the event in the context of the
408
- event producer (identified by source). Required.
409
- "type": "str", # Describes the type of event related to the originating
410
- occurrence. Required.
411
- "data": {
412
- "str": {} # Optional. The event payload.
413
- },
414
- "datacontenttype": "str", # Optional. Content type of the data value. Must
415
- adhere to RFC 2046 format. "application/json"
416
- "dataschema": "str", # Optional. Identifies the schema that data adheres to.
417
- "time": "2020-02-20 00:00:00" # Optional. Timestamp of when the occurrence
418
- happened. Must adhere to RFC 3339.
419
- }
420
- """
421
-
422
- @overload
423
- def ingest_events( # pylint: disable=inconsistent-return-statements
424
- self, body: List[JSON], *, content_type: str = "application/cloudevents-batch+json", **kwargs: Any
425
- ) -> None:
426
- """Ingest events.
427
-
428
- :param body: Required.
429
- :type body: list[JSON]
430
- :keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
431
- Default value is "application/cloudevents-batch+json".
432
- :paramtype content_type: str
433
- :return: None
434
- :rtype: None
435
- :raises ~azure.core.exceptions.HttpResponseError:
436
-
437
- Example:
438
- .. code-block:: python
439
-
440
- # JSON input template you can fill out and use as your body input.
441
- body = [
442
- {
443
- "id": "str", # Identifies the event. Required.
444
- "source": "str", # Identifies the context in which an event
445
- happened. Required.
446
- "specversion": "str", # The version of the CloudEvents specification
447
- which the event uses. Required.
448
- "subject": "str", # Describes the subject of the event in the
449
- context of the event producer (identified by source). Required.
450
- "type": "str", # Describes the type of event related to the
451
- originating occurrence. Required.
452
- "data": {
453
- "str": {} # Optional. The event payload.
454
- },
455
- "datacontenttype": "str", # Optional. Content type of the data
456
- value. Must adhere to RFC 2046 format. "application/json"
457
- "dataschema": "str", # Optional. Identifies the schema that data
458
- adheres to.
459
- "time": "2020-02-20 00:00:00" # Optional. Timestamp of when the
460
- occurrence happened. Must adhere to RFC 3339.
461
- }
462
- ]
463
- """
464
-
465
- @distributed_trace
466
- def ingest_events( # pylint: disable=inconsistent-return-statements
467
- self, body: Union[JSON, List[JSON]], **kwargs: Any
468
- ) -> None:
469
- """Ingest events.
470
-
471
- :param body: Is either a JSON type or a [JSON] type. Required.
472
- :type body: JSON or list[JSON]
473
- :keyword content_type: Body Parameter content-type. Known values are:
474
- 'application/cloudevents+json', 'application/cloudevents-batch+json'. Default value is None.
475
- :paramtype content_type: str
476
- :return: None
477
- :rtype: None
478
- :raises ~azure.core.exceptions.HttpResponseError:
479
-
480
- Example:
481
- .. code-block:: python
482
-
483
- # JSON input template you can fill out and use as your body input.
484
- body = {
485
- "id": "str", # Identifies the event. Required.
486
- "source": "str", # Identifies the context in which an event happened.
487
- Required.
488
- "specversion": "str", # The version of the CloudEvents specification which
489
- the event uses. Required.
490
- "subject": "str", # Describes the subject of the event in the context of the
491
- event producer (identified by source). Required.
492
- "type": "str", # Describes the type of event related to the originating
493
- occurrence. Required.
494
- "data": {
495
- "str": {} # Optional. The event payload.
496
- },
497
- "datacontenttype": "str", # Optional. Content type of the data value. Must
498
- adhere to RFC 2046 format. "application/json"
499
- "dataschema": "str", # Optional. Identifies the schema that data adheres to.
500
- "time": "2020-02-20 00:00:00" # Optional. Timestamp of when the occurrence
501
- happened. Must adhere to RFC 3339.
502
- }
503
- """
504
- error_map = {
505
- 401: ClientAuthenticationError,
506
- 404: ResourceNotFoundError,
507
- 409: ResourceExistsError,
508
- 304: ResourceNotModifiedError,
509
- 400: HttpResponseError,
510
- }
511
- error_map.update(kwargs.pop("error_map", {}) or {})
512
-
513
- _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
514
- _params = kwargs.pop("params", {}) or {}
515
-
516
- content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
517
- cls: ClsType[None] = kwargs.pop("cls", None)
518
-
519
- _json = None
520
- if isinstance(body, MutableMapping):
521
- content_type = content_type or "application/cloudevents+json"
522
- _json = body
523
- elif isinstance(body, list):
524
- content_type = content_type or "application/cloudevents-batch+json"
525
- _json = body
526
-
527
- _request = build_ingest_events_request(
528
- content_type=content_type,
529
- json=_json,
530
- headers=_headers,
531
- params=_params,
532
- )
533
- _request.url = self._client.format_url(_request.url)
534
-
535
- _stream = False
536
- pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access
537
- _request, stream=_stream, **kwargs
538
- )
539
-
540
- response = pipeline_response.http_response
541
-
542
- if response.status_code not in [204]:
543
- if _stream:
544
- response.read() # Load the body in memory and close the socket
545
- map_error(status_code=response.status_code, response=response, error_map=error_map)
546
- raise HttpResponseError(response=response)
547
-
548
- if cls:
549
- return cls(pipeline_response, None, {}) # type: ignore
550
-
551
- @distributed_trace
552
- def list_events(
553
- self,
554
- *,
555
- from_parameter: Optional[datetime.datetime] = None,
556
- to: Optional[datetime.datetime] = None,
557
- limit: Optional[int] = None,
558
- **kwargs: Any
559
- ) -> List[JSON]:
560
- """Retrieve latest raw events.
561
-
562
- :keyword from_parameter: Start date-time in RFC 3339 format.
563
- Inclusive. Default value is None.
564
- :paramtype from_parameter: ~datetime.datetime
565
- :keyword to: End date-time in RFC 3339 format.
566
- Inclusive. Default value is None.
567
- :paramtype to: ~datetime.datetime
568
- :keyword limit: Number of events to return. Default value is None.
569
- :paramtype limit: int
570
- :return: list of JSON object
571
- :rtype: list[JSON]
572
- :raises ~azure.core.exceptions.HttpResponseError:
573
-
574
- Example:
575
- .. code-block:: python
576
-
577
- # response body for status code(s): 200
578
- response == [
579
- {
580
- "event": {
581
- "id": "str", # Identifies the event. Required.
582
- "source": "str", # Identifies the context in which an event
583
- happened. Required.
584
- "specversion": "str", # The version of the CloudEvents
585
- specification which the event uses. Required.
586
- "subject": "str", # Describes the subject of the event in
587
- the context of the event producer (identified by source). Required.
588
- "type": "str", # Describes the type of event related to the
589
- originating occurrence. Required.
590
- "data": {
591
- "str": {} # Optional. The event payload.
592
- },
593
- "datacontenttype": "str", # Optional. Content type of the
594
- data value. Must adhere to RFC 2046 format. "application/json"
595
- "dataschema": "str", # Optional. Identifies the schema that
596
- data adheres to.
597
- "time": "2020-02-20 00:00:00" # Optional. Timestamp of when
598
- the occurrence happened. Must adhere to RFC 3339.
599
- },
600
- "validationError": "str" # Optional.
601
- }
602
- ]
603
- """
604
- error_map = {
605
- 401: ClientAuthenticationError,
606
- 404: ResourceNotFoundError,
607
- 409: ResourceExistsError,
608
- 304: ResourceNotModifiedError,
609
- 400: HttpResponseError,
610
- }
611
- error_map.update(kwargs.pop("error_map", {}) or {})
612
-
613
- _headers = kwargs.pop("headers", {}) or {}
614
- _params = kwargs.pop("params", {}) or {}
615
-
616
- cls: ClsType[List[JSON]] = kwargs.pop("cls", None)
617
-
618
- _request = build_list_events_request(
619
- from_parameter=from_parameter,
620
- to=to,
621
- limit=limit,
622
- headers=_headers,
623
- params=_params,
624
- )
625
- _request.url = self._client.format_url(_request.url)
626
-
627
- _stream = False
628
- pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access
629
- _request, stream=_stream, **kwargs
630
- )
631
-
632
- response = pipeline_response.http_response
633
-
634
- if response.status_code not in [200]:
635
- if _stream:
636
- response.read() # Load the body in memory and close the socket
637
- map_error(status_code=response.status_code, response=response, error_map=error_map)
638
- raise HttpResponseError(response=response)
639
-
640
- if response.content:
641
- deserialized = response.json()
642
- else:
643
- deserialized = None
644
-
645
- if cls:
646
- return cls(pipeline_response, cast(List[JSON], deserialized), {}) # type: ignore
647
-
648
- return cast(List[JSON], deserialized) # type: ignore
649
-
650
- @distributed_trace
651
- def list_meters(self, **kwargs: Any) -> List[JSON]:
652
- """List meters.
653
-
654
- :return: list of JSON object
655
- :rtype: list[JSON]
656
- :raises ~azure.core.exceptions.HttpResponseError:
657
-
658
- Example:
659
- .. code-block:: python
660
-
661
- # response body for status code(s): 200
662
- response == [
663
- {
664
- "aggregation": "str", # The aggregation type to use for the meter.
665
- Required. Known values are: "SUM", "COUNT", "AVG", "MIN", and "MAX".
666
- "eventType": "str", # The event type to aggregate. Required.
667
- "slug": "str", # A unique identifier for the meter. Required.
668
- "windowSize": "str", # Aggregation window size. Required. Known
669
- values are: "MINUTE", "HOUR", and "DAY".
670
- "description": "str", # Optional. A description of the meter.
671
- "groupBy": {
672
- "str": "str" # Optional. Named JSONPath expressions to
673
- extract the group by values from the event data.
674
- },
675
- "id": "str", # Optional. A unique identifier for the meter.
676
- "valueProperty": "str" # Optional. JSONPath expression to extract
677
- the value from the event data.
678
- }
679
- ]
680
- """
681
- error_map = {
682
- 401: ClientAuthenticationError,
683
- 404: ResourceNotFoundError,
684
- 409: ResourceExistsError,
685
- 304: ResourceNotModifiedError,
686
- }
687
- error_map.update(kwargs.pop("error_map", {}) or {})
688
-
689
- _headers = kwargs.pop("headers", {}) or {}
690
- _params = kwargs.pop("params", {}) or {}
691
-
692
- cls: ClsType[List[JSON]] = kwargs.pop("cls", None)
693
-
694
- _request = build_list_meters_request(
695
- headers=_headers,
696
- params=_params,
697
- )
698
- _request.url = self._client.format_url(_request.url)
699
-
700
- _stream = False
701
- pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access
702
- _request, stream=_stream, **kwargs
703
- )
704
-
705
- response = pipeline_response.http_response
706
-
707
- if response.status_code not in [200]:
708
- if _stream:
709
- response.read() # Load the body in memory and close the socket
710
- map_error(status_code=response.status_code, response=response, error_map=error_map)
711
- raise HttpResponseError(response=response)
712
-
713
- if response.content:
714
- deserialized = response.json()
715
- else:
716
- deserialized = None
717
-
718
- if cls:
719
- return cls(pipeline_response, cast(List[JSON], deserialized), {}) # type: ignore
720
-
721
- return cast(List[JSON], deserialized) # type: ignore
722
-
723
- @overload
724
- def create_meter(self, body: JSON, *, content_type: str = "application/json", **kwargs: Any) -> JSON:
725
- """Create meter.
726
-
727
- :param body: Required.
728
- :type body: JSON
729
- :keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
730
- Default value is "application/json".
731
- :paramtype content_type: str
732
- :return: JSON object
733
- :rtype: JSON
734
- :raises ~azure.core.exceptions.HttpResponseError:
735
-
736
- Example:
737
- .. code-block:: python
738
-
739
- # JSON input template you can fill out and use as your body input.
740
- body = {
741
- "aggregation": "str", # The aggregation type to use for the meter. Required.
742
- Known values are: "SUM", "COUNT", "AVG", "MIN", and "MAX".
743
- "eventType": "str", # The event type to aggregate. Required.
744
- "slug": "str", # A unique identifier for the meter. Required.
745
- "windowSize": "str", # Aggregation window size. Required. Known values are:
746
- "MINUTE", "HOUR", and "DAY".
747
- "description": "str", # Optional. A description of the meter.
748
- "groupBy": {
749
- "str": "str" # Optional. Named JSONPath expressions to extract the
750
- group by values from the event data.
751
- },
752
- "id": "str", # Optional. A unique identifier for the meter.
753
- "valueProperty": "str" # Optional. JSONPath expression to extract the value
754
- from the event data.
755
- }
756
-
757
- # response body for status code(s): 201
758
- response == {
759
- "aggregation": "str", # The aggregation type to use for the meter. Required.
760
- Known values are: "SUM", "COUNT", "AVG", "MIN", and "MAX".
761
- "eventType": "str", # The event type to aggregate. Required.
762
- "slug": "str", # A unique identifier for the meter. Required.
763
- "windowSize": "str", # Aggregation window size. Required. Known values are:
764
- "MINUTE", "HOUR", and "DAY".
765
- "description": "str", # Optional. A description of the meter.
766
- "groupBy": {
767
- "str": "str" # Optional. Named JSONPath expressions to extract the
768
- group by values from the event data.
769
- },
770
- "id": "str", # Optional. A unique identifier for the meter.
771
- "valueProperty": "str" # Optional. JSONPath expression to extract the value
772
- from the event data.
773
- }
774
- """
775
-
776
- @overload
777
- def create_meter(self, body: IO, *, content_type: str = "application/json", **kwargs: Any) -> JSON:
778
- """Create meter.
779
-
780
- :param body: Required.
781
- :type body: IO
782
- :keyword content_type: Body Parameter content-type. Content type parameter for binary body.
783
- Default value is "application/json".
784
- :paramtype content_type: str
785
- :return: JSON object
786
- :rtype: JSON
787
- :raises ~azure.core.exceptions.HttpResponseError:
788
-
789
- Example:
790
- .. code-block:: python
791
-
792
- # response body for status code(s): 201
793
- response == {
794
- "aggregation": "str", # The aggregation type to use for the meter. Required.
795
- Known values are: "SUM", "COUNT", "AVG", "MIN", and "MAX".
796
- "eventType": "str", # The event type to aggregate. Required.
797
- "slug": "str", # A unique identifier for the meter. Required.
798
- "windowSize": "str", # Aggregation window size. Required. Known values are:
799
- "MINUTE", "HOUR", and "DAY".
800
- "description": "str", # Optional. A description of the meter.
801
- "groupBy": {
802
- "str": "str" # Optional. Named JSONPath expressions to extract the
803
- group by values from the event data.
804
- },
805
- "id": "str", # Optional. A unique identifier for the meter.
806
- "valueProperty": "str" # Optional. JSONPath expression to extract the value
807
- from the event data.
808
- }
809
- """
810
-
811
- @distributed_trace
812
- def create_meter(self, body: Union[JSON, IO], **kwargs: Any) -> JSON:
813
- """Create meter.
814
-
815
- :param body: Is either a JSON type or a IO type. Required.
816
- :type body: JSON or IO
817
- :keyword content_type: Body Parameter content-type. Known values are: 'application/json'.
818
- Default value is None.
819
- :paramtype content_type: str
820
- :return: JSON object
821
- :rtype: JSON
822
- :raises ~azure.core.exceptions.HttpResponseError:
823
-
824
- Example:
825
- .. code-block:: python
826
-
827
- # JSON input template you can fill out and use as your body input.
828
- body = {
829
- "aggregation": "str", # The aggregation type to use for the meter. Required.
830
- Known values are: "SUM", "COUNT", "AVG", "MIN", and "MAX".
831
- "eventType": "str", # The event type to aggregate. Required.
832
- "slug": "str", # A unique identifier for the meter. Required.
833
- "windowSize": "str", # Aggregation window size. Required. Known values are:
834
- "MINUTE", "HOUR", and "DAY".
835
- "description": "str", # Optional. A description of the meter.
836
- "groupBy": {
837
- "str": "str" # Optional. Named JSONPath expressions to extract the
838
- group by values from the event data.
839
- },
840
- "id": "str", # Optional. A unique identifier for the meter.
841
- "valueProperty": "str" # Optional. JSONPath expression to extract the value
842
- from the event data.
843
- }
844
-
845
- # response body for status code(s): 201
846
- response == {
847
- "aggregation": "str", # The aggregation type to use for the meter. Required.
848
- Known values are: "SUM", "COUNT", "AVG", "MIN", and "MAX".
849
- "eventType": "str", # The event type to aggregate. Required.
850
- "slug": "str", # A unique identifier for the meter. Required.
851
- "windowSize": "str", # Aggregation window size. Required. Known values are:
852
- "MINUTE", "HOUR", and "DAY".
853
- "description": "str", # Optional. A description of the meter.
854
- "groupBy": {
855
- "str": "str" # Optional. Named JSONPath expressions to extract the
856
- group by values from the event data.
857
- },
858
- "id": "str", # Optional. A unique identifier for the meter.
859
- "valueProperty": "str" # Optional. JSONPath expression to extract the value
860
- from the event data.
861
- }
862
- """
863
- error_map = {
864
- 401: ClientAuthenticationError,
865
- 404: ResourceNotFoundError,
866
- 409: ResourceExistsError,
867
- 304: ResourceNotModifiedError,
868
- 400: HttpResponseError,
869
- 501: HttpResponseError,
870
- }
871
- error_map.update(kwargs.pop("error_map", {}) or {})
872
-
873
- _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
874
- _params = kwargs.pop("params", {}) or {}
875
-
876
- content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
877
- cls: ClsType[JSON] = kwargs.pop("cls", None)
878
-
879
- content_type = content_type or "application/json"
880
- _json = None
881
- _content = None
882
- if isinstance(body, (IOBase, bytes)):
883
- _content = body
884
- else:
885
- _json = body
886
-
887
- _request = build_create_meter_request(
888
- content_type=content_type,
889
- json=_json,
890
- content=_content,
891
- headers=_headers,
892
- params=_params,
893
- )
894
- _request.url = self._client.format_url(_request.url)
895
-
896
- _stream = False
897
- pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access
898
- _request, stream=_stream, **kwargs
899
- )
900
-
901
- response = pipeline_response.http_response
902
-
903
- if response.status_code not in [201]:
904
- if _stream:
905
- response.read() # Load the body in memory and close the socket
906
- map_error(status_code=response.status_code, response=response, error_map=error_map)
907
- raise HttpResponseError(response=response)
908
-
909
- if response.content:
910
- deserialized = response.json()
911
- else:
912
- deserialized = None
913
-
914
- if cls:
915
- return cls(pipeline_response, cast(JSON, deserialized), {}) # type: ignore
916
-
917
- return cast(JSON, deserialized) # type: ignore
918
-
919
- @distributed_trace
920
- def get_meter(self, meter_id_or_slug: str, **kwargs: Any) -> JSON:
921
- """Get meter by slugs.
922
-
923
- :param meter_id_or_slug: A unique identifier for the meter. Required.
924
- :type meter_id_or_slug: str
925
- :return: JSON object
926
- :rtype: JSON
927
- :raises ~azure.core.exceptions.HttpResponseError:
928
-
929
- Example:
930
- .. code-block:: python
931
-
932
- # response body for status code(s): 200
933
- response == {
934
- "aggregation": "str", # The aggregation type to use for the meter. Required.
935
- Known values are: "SUM", "COUNT", "AVG", "MIN", and "MAX".
936
- "eventType": "str", # The event type to aggregate. Required.
937
- "slug": "str", # A unique identifier for the meter. Required.
938
- "windowSize": "str", # Aggregation window size. Required. Known values are:
939
- "MINUTE", "HOUR", and "DAY".
940
- "description": "str", # Optional. A description of the meter.
941
- "groupBy": {
942
- "str": "str" # Optional. Named JSONPath expressions to extract the
943
- group by values from the event data.
944
- },
945
- "id": "str", # Optional. A unique identifier for the meter.
946
- "valueProperty": "str" # Optional. JSONPath expression to extract the value
947
- from the event data.
948
- }
949
- """
950
- error_map = {
951
- 401: ClientAuthenticationError,
952
- 409: ResourceExistsError,
953
- 304: ResourceNotModifiedError,
954
- 404: lambda response: ResourceNotFoundError(response=response),
955
- }
956
- error_map.update(kwargs.pop("error_map", {}) or {})
957
-
958
- _headers = kwargs.pop("headers", {}) or {}
959
- _params = kwargs.pop("params", {}) or {}
960
-
961
- cls: ClsType[JSON] = kwargs.pop("cls", None)
962
-
963
- _request = build_get_meter_request(
964
- meter_id_or_slug=meter_id_or_slug,
965
- headers=_headers,
966
- params=_params,
967
- )
968
- _request.url = self._client.format_url(_request.url)
969
-
970
- _stream = False
971
- pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access
972
- _request, stream=_stream, **kwargs
973
- )
974
-
975
- response = pipeline_response.http_response
976
-
977
- if response.status_code not in [200]:
978
- if _stream:
979
- response.read() # Load the body in memory and close the socket
980
- map_error(status_code=response.status_code, response=response, error_map=error_map)
981
- raise HttpResponseError(response=response)
982
-
983
- if response.content:
984
- deserialized = response.json()
985
- else:
986
- deserialized = None
987
-
988
- if cls:
989
- return cls(pipeline_response, cast(JSON, deserialized), {}) # type: ignore
990
-
991
- return cast(JSON, deserialized) # type: ignore
992
-
993
- @distributed_trace
994
- def delete_meter( # pylint: disable=inconsistent-return-statements
995
- self, meter_id_or_slug: str, **kwargs: Any
996
- ) -> None:
997
- """Delete meter by slug.
998
-
999
- :param meter_id_or_slug: A unique identifier for the meter. Required.
1000
- :type meter_id_or_slug: str
1001
- :return: None
1002
- :rtype: None
1003
- :raises ~azure.core.exceptions.HttpResponseError:
1004
- """
1005
- error_map = {
1006
- 401: ClientAuthenticationError,
1007
- 409: ResourceExistsError,
1008
- 304: ResourceNotModifiedError,
1009
- 404: lambda response: ResourceNotFoundError(response=response),
1010
- 501: HttpResponseError,
1011
- }
1012
- error_map.update(kwargs.pop("error_map", {}) or {})
1013
-
1014
- _headers = kwargs.pop("headers", {}) or {}
1015
- _params = kwargs.pop("params", {}) or {}
1016
-
1017
- cls: ClsType[None] = kwargs.pop("cls", None)
1018
-
1019
- _request = build_delete_meter_request(
1020
- meter_id_or_slug=meter_id_or_slug,
1021
- headers=_headers,
1022
- params=_params,
1023
- )
1024
- _request.url = self._client.format_url(_request.url)
1025
-
1026
- _stream = False
1027
- pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access
1028
- _request, stream=_stream, **kwargs
1029
- )
1030
-
1031
- response = pipeline_response.http_response
1032
-
1033
- if response.status_code not in [204]:
1034
- if _stream:
1035
- response.read() # Load the body in memory and close the socket
1036
- map_error(status_code=response.status_code, response=response, error_map=error_map)
1037
- raise HttpResponseError(response=response)
1038
-
1039
- if cls:
1040
- return cls(pipeline_response, None, {}) # type: ignore
1041
-
1042
- @distributed_trace
1043
- def query_meter(
1044
- self,
1045
- meter_id_or_slug: str,
1046
- *,
1047
- from_parameter: Optional[datetime.datetime] = None,
1048
- to: Optional[datetime.datetime] = None,
1049
- window_size: Optional[str] = None,
1050
- window_time_zone: str = "UTC",
1051
- subject: Optional[List[str]] = None,
1052
- group_by: Optional[List[str]] = None,
1053
- **kwargs: Any
1054
- ) -> Union[JSON, str]:
1055
- """Query meter.
1056
-
1057
- :param meter_id_or_slug: A unique identifier for the meter. Required.
1058
- :type meter_id_or_slug: str
1059
- :keyword from_parameter: Start date-time in RFC 3339 format.
1060
- Inclusive. Default value is None.
1061
- :paramtype from_parameter: ~datetime.datetime
1062
- :keyword to: End date-time in RFC 3339 format.
1063
- Inclusive. Default value is None.
1064
- :paramtype to: ~datetime.datetime
1065
- :keyword window_size: If not specified, a single usage aggregate will be returned for the
1066
- entirety of the specified period for each subject and group. Known values are: "MINUTE",
1067
- "HOUR", and "DAY". Default value is None.
1068
- :paramtype window_size: str
1069
- :keyword window_time_zone: The value is the name of the time zone as defined in the IANA Time
1070
- Zone Database (http://www.iana.org/time-zones).
1071
- If not specified, the UTC timezone will be used. Default value is "UTC".
1072
- :paramtype window_time_zone: str
1073
- :keyword subject: Default value is None.
1074
- :paramtype subject: list[str]
1075
- :keyword group_by: If not specified a single aggregate will be returned for each subject and
1076
- time window.
1077
- ``subject`` is a reserved group by value. Default value is None.
1078
- :paramtype group_by: list[str]
1079
- :return: JSON object or str
1080
- :rtype: JSON or str
1081
- :raises ~azure.core.exceptions.HttpResponseError:
1082
-
1083
- Example:
1084
- .. code-block:: python
1085
-
1086
- # response body for status code(s): 200
1087
- response == {
1088
- "data": [
1089
- {
1090
- "value": 0.0, # Required.
1091
- "windowEnd": "2020-02-20 00:00:00", # Required.
1092
- "windowStart": "2020-02-20 00:00:00", # Required.
1093
- "groupBy": {
1094
- "str": "str" # Optional. Dictionary of
1095
- :code:`<string>`.
1096
- },
1097
- "subject": "str" # Optional. The subject of the meter value.
1098
- }
1099
- ],
1100
- "from": "2020-02-20 00:00:00", # Optional.
1101
- "to": "2020-02-20 00:00:00", # Optional.
1102
- "windowSize": "str" # Optional. Aggregation window size. Known values are:
1103
- "MINUTE", "HOUR", and "DAY".
1104
- }
1105
- """
1106
- error_map = {
1107
- 401: ClientAuthenticationError,
1108
- 404: ResourceNotFoundError,
1109
- 409: ResourceExistsError,
1110
- 304: ResourceNotModifiedError,
1111
- 400: HttpResponseError,
1112
- }
1113
- error_map.update(kwargs.pop("error_map", {}) or {})
1114
-
1115
- _headers = kwargs.pop("headers", {}) or {}
1116
- _params = kwargs.pop("params", {}) or {}
1117
-
1118
- cls: ClsType[Union[JSON, str]] = kwargs.pop("cls", None)
1119
-
1120
- _request = build_query_meter_request(
1121
- meter_id_or_slug=meter_id_or_slug,
1122
- from_parameter=from_parameter,
1123
- to=to,
1124
- window_size=window_size,
1125
- window_time_zone=window_time_zone,
1126
- subject=subject,
1127
- group_by=group_by,
1128
- headers=_headers,
1129
- params=_params,
1130
- )
1131
- _request.url = self._client.format_url(_request.url)
1132
-
1133
- _stream = False
1134
- pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access
1135
- _request, stream=_stream, **kwargs
1136
- )
1137
-
1138
- response = pipeline_response.http_response
1139
-
1140
- if response.status_code not in [200, 200]:
1141
- if _stream:
1142
- response.read() # Load the body in memory and close the socket
1143
- map_error(status_code=response.status_code, response=response, error_map=error_map)
1144
- raise HttpResponseError(response=response)
1145
-
1146
- if response.status_code == 200:
1147
- if response.content:
1148
- deserialized = response.json()
1149
- else:
1150
- deserialized = None
1151
-
1152
- if response.status_code == 200:
1153
- if response.content:
1154
- deserialized = response.json()
1155
- else:
1156
- deserialized = None
1157
-
1158
- if cls:
1159
- return cls(pipeline_response, cast(Union[JSON, str], deserialized), {}) # type: ignore
1160
-
1161
- return cast(Union[JSON, str], deserialized) # type: ignore
1162
-
1163
- @distributed_trace
1164
- def list_meter_subjects(self, meter_id_or_slug: str, **kwargs: Any) -> List[str]:
1165
- """List meter subjects.
1166
-
1167
- :param meter_id_or_slug: A unique identifier for the meter. Required.
1168
- :type meter_id_or_slug: str
1169
- :return: list of str
1170
- :rtype: list[str]
1171
- :raises ~azure.core.exceptions.HttpResponseError:
1172
-
1173
- Example:
1174
- .. code-block:: python
1175
-
1176
- # response body for status code(s): 200
1177
- response == [
1178
- "str" # Optional.
1179
- ]
1180
- """
1181
- error_map = {
1182
- 401: ClientAuthenticationError,
1183
- 404: ResourceNotFoundError,
1184
- 409: ResourceExistsError,
1185
- 304: ResourceNotModifiedError,
1186
- 400: HttpResponseError,
1187
- }
1188
- error_map.update(kwargs.pop("error_map", {}) or {})
1189
-
1190
- _headers = kwargs.pop("headers", {}) or {}
1191
- _params = kwargs.pop("params", {}) or {}
1192
-
1193
- cls: ClsType[List[str]] = kwargs.pop("cls", None)
1194
-
1195
- _request = build_list_meter_subjects_request(
1196
- meter_id_or_slug=meter_id_or_slug,
1197
- headers=_headers,
1198
- params=_params,
1199
- )
1200
- _request.url = self._client.format_url(_request.url)
1201
-
1202
- _stream = False
1203
- pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access
1204
- _request, stream=_stream, **kwargs
1205
- )
1206
-
1207
- response = pipeline_response.http_response
1208
-
1209
- if response.status_code not in [200]:
1210
- if _stream:
1211
- response.read() # Load the body in memory and close the socket
1212
- map_error(status_code=response.status_code, response=response, error_map=error_map)
1213
- raise HttpResponseError(response=response)
1214
-
1215
- if response.content:
1216
- deserialized = response.json()
1217
- else:
1218
- deserialized = None
1219
-
1220
- if cls:
1221
- return cls(pipeline_response, cast(List[str], deserialized), {}) # type: ignore
1222
-
1223
- return cast(List[str], deserialized) # type: ignore
1224
-
1225
- @overload
1226
- def create_portal_token(
1227
- self, body: Optional[JSON] = None, *, content_type: str = "application/json", **kwargs: Any
1228
- ) -> JSON:
1229
- """create_portal_token.
1230
-
1231
- :param body: Default value is None.
1232
- :type body: JSON
1233
- :keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
1234
- Default value is "application/json".
1235
- :paramtype content_type: str
1236
- :return: JSON object
1237
- :rtype: JSON
1238
- :raises ~azure.core.exceptions.HttpResponseError:
1239
-
1240
- Example:
1241
- .. code-block:: python
1242
-
1243
- # JSON input template you can fill out and use as your body input.
1244
- body = {
1245
- "createdAt": "2020-02-20 00:00:00", # Required.
1246
- "expiresAt": "2020-02-20 00:00:00", # Required.
1247
- "id": "str", # Required.
1248
- "subject": "str", # Required.
1249
- "allowedMeterSlugs": [
1250
- "str" # Optional. Optional, if defined only the specified meters
1251
- will be allowed.
1252
- ],
1253
- "expired": bool, # Optional.
1254
- "token": "str" # Optional. The token is only returned at creation.
1255
- }
1256
-
1257
- # response body for status code(s): 200
1258
- response == {
1259
- "createdAt": "2020-02-20 00:00:00", # Required.
1260
- "expiresAt": "2020-02-20 00:00:00", # Required.
1261
- "id": "str", # Required.
1262
- "subject": "str", # Required.
1263
- "allowedMeterSlugs": [
1264
- "str" # Optional. Optional, if defined only the specified meters
1265
- will be allowed.
1266
- ],
1267
- "expired": bool, # Optional.
1268
- "token": "str" # Optional. The token is only returned at creation.
1269
- }
1270
- """
1271
-
1272
- @overload
1273
- def create_portal_token(
1274
- self, body: Optional[IO] = None, *, content_type: str = "application/json", **kwargs: Any
1275
- ) -> JSON:
1276
- """create_portal_token.
1277
-
1278
- :param body: Default value is None.
1279
- :type body: IO
1280
- :keyword content_type: Body Parameter content-type. Content type parameter for binary body.
1281
- Default value is "application/json".
1282
- :paramtype content_type: str
1283
- :return: JSON object
1284
- :rtype: JSON
1285
- :raises ~azure.core.exceptions.HttpResponseError:
1286
-
1287
- Example:
1288
- .. code-block:: python
1289
-
1290
- # response body for status code(s): 200
1291
- response == {
1292
- "createdAt": "2020-02-20 00:00:00", # Required.
1293
- "expiresAt": "2020-02-20 00:00:00", # Required.
1294
- "id": "str", # Required.
1295
- "subject": "str", # Required.
1296
- "allowedMeterSlugs": [
1297
- "str" # Optional. Optional, if defined only the specified meters
1298
- will be allowed.
1299
- ],
1300
- "expired": bool, # Optional.
1301
- "token": "str" # Optional. The token is only returned at creation.
1302
- }
1303
- """
1304
-
1305
- @distributed_trace
1306
- def create_portal_token(self, body: Optional[Union[JSON, IO]] = None, **kwargs: Any) -> JSON:
1307
- """create_portal_token.
1308
-
1309
- :param body: Is either a JSON type or a IO type. Default value is None.
1310
- :type body: JSON or IO
1311
- :keyword content_type: Body Parameter content-type. Known values are: 'application/json'.
1312
- Default value is None.
1313
- :paramtype content_type: str
1314
- :return: JSON object
1315
- :rtype: JSON
1316
- :raises ~azure.core.exceptions.HttpResponseError:
1317
-
1318
- Example:
1319
- .. code-block:: python
1320
-
1321
- # JSON input template you can fill out and use as your body input.
1322
- body = {
1323
- "createdAt": "2020-02-20 00:00:00", # Required.
1324
- "expiresAt": "2020-02-20 00:00:00", # Required.
1325
- "id": "str", # Required.
1326
- "subject": "str", # Required.
1327
- "allowedMeterSlugs": [
1328
- "str" # Optional. Optional, if defined only the specified meters
1329
- will be allowed.
1330
- ],
1331
- "expired": bool, # Optional.
1332
- "token": "str" # Optional. The token is only returned at creation.
1333
- }
1334
-
1335
- # response body for status code(s): 200
1336
- response == {
1337
- "createdAt": "2020-02-20 00:00:00", # Required.
1338
- "expiresAt": "2020-02-20 00:00:00", # Required.
1339
- "id": "str", # Required.
1340
- "subject": "str", # Required.
1341
- "allowedMeterSlugs": [
1342
- "str" # Optional. Optional, if defined only the specified meters
1343
- will be allowed.
1344
- ],
1345
- "expired": bool, # Optional.
1346
- "token": "str" # Optional. The token is only returned at creation.
1347
- }
1348
- """
1349
- error_map = {
1350
- 401: ClientAuthenticationError,
1351
- 404: ResourceNotFoundError,
1352
- 409: ResourceExistsError,
1353
- 304: ResourceNotModifiedError,
1354
- 400: HttpResponseError,
1355
- }
1356
- error_map.update(kwargs.pop("error_map", {}) or {})
1357
-
1358
- _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
1359
- _params = kwargs.pop("params", {}) or {}
1360
-
1361
- content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
1362
- cls: ClsType[JSON] = kwargs.pop("cls", None)
1363
-
1364
- content_type = content_type or "application/json"
1365
- _json = None
1366
- _content = None
1367
- if isinstance(body, (IOBase, bytes)):
1368
- _content = body
1369
- else:
1370
- if body is not None:
1371
- _json = body
1372
- else:
1373
- _json = None
1374
-
1375
- _request = build_create_portal_token_request(
1376
- content_type=content_type,
1377
- json=_json,
1378
- content=_content,
1379
- headers=_headers,
1380
- params=_params,
1381
- )
1382
- _request.url = self._client.format_url(_request.url)
1383
-
1384
- _stream = False
1385
- pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access
1386
- _request, stream=_stream, **kwargs
1387
- )
1388
-
1389
- response = pipeline_response.http_response
1390
-
1391
- if response.status_code not in [200]:
1392
- if _stream:
1393
- response.read() # Load the body in memory and close the socket
1394
- map_error(status_code=response.status_code, response=response, error_map=error_map)
1395
- raise HttpResponseError(response=response)
1396
-
1397
- if response.content:
1398
- deserialized = response.json()
1399
- else:
1400
- deserialized = None
1401
-
1402
- if cls:
1403
- return cls(pipeline_response, cast(JSON, deserialized), {}) # type: ignore
1404
-
1405
- return cast(JSON, deserialized) # type: ignore
1406
-
1407
- @distributed_trace
1408
- def list_portal_tokens(self, *, limit: int = 25, **kwargs: Any) -> List[JSON]:
1409
- """list_portal_tokens.
1410
-
1411
- :keyword limit: Number of portal tokens to return. Default is 25. Default value is 25.
1412
- :paramtype limit: int
1413
- :return: list of JSON object
1414
- :rtype: list[JSON]
1415
- :raises ~azure.core.exceptions.HttpResponseError:
1416
-
1417
- Example:
1418
- .. code-block:: python
1419
-
1420
- # response body for status code(s): 200
1421
- response == [
1422
- {
1423
- "createdAt": "2020-02-20 00:00:00", # Required.
1424
- "expiresAt": "2020-02-20 00:00:00", # Required.
1425
- "id": "str", # Required.
1426
- "subject": "str", # Required.
1427
- "allowedMeterSlugs": [
1428
- "str" # Optional. Optional, if defined only the specified
1429
- meters will be allowed.
1430
- ],
1431
- "expired": bool, # Optional.
1432
- "token": "str" # Optional. The token is only returned at creation.
1433
- }
1434
- ]
1435
- """
1436
- error_map = {
1437
- 401: ClientAuthenticationError,
1438
- 404: ResourceNotFoundError,
1439
- 409: ResourceExistsError,
1440
- 304: ResourceNotModifiedError,
1441
- 400: HttpResponseError,
1442
- }
1443
- error_map.update(kwargs.pop("error_map", {}) or {})
1444
-
1445
- _headers = kwargs.pop("headers", {}) or {}
1446
- _params = kwargs.pop("params", {}) or {}
1447
-
1448
- cls: ClsType[List[JSON]] = kwargs.pop("cls", None)
1449
-
1450
- _request = build_list_portal_tokens_request(
1451
- limit=limit,
1452
- headers=_headers,
1453
- params=_params,
1454
- )
1455
- _request.url = self._client.format_url(_request.url)
1456
-
1457
- _stream = False
1458
- pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access
1459
- _request, stream=_stream, **kwargs
1460
- )
1461
-
1462
- response = pipeline_response.http_response
1463
-
1464
- if response.status_code not in [200]:
1465
- if _stream:
1466
- response.read() # Load the body in memory and close the socket
1467
- map_error(status_code=response.status_code, response=response, error_map=error_map)
1468
- raise HttpResponseError(response=response)
1469
-
1470
- if response.content:
1471
- deserialized = response.json()
1472
- else:
1473
- deserialized = None
1474
-
1475
- if cls:
1476
- return cls(pipeline_response, cast(List[JSON], deserialized), {}) # type: ignore
1477
-
1478
- return cast(List[JSON], deserialized) # type: ignore
1479
-
1480
- @overload
1481
- def invalidate_portal_tokens( # pylint: disable=inconsistent-return-statements
1482
- self, body: Optional[JSON] = None, *, content_type: str = "application/json", **kwargs: Any
1483
- ) -> None:
1484
- """invalidate_portal_tokens.
1485
-
1486
- :param body: Default value is None.
1487
- :type body: JSON
1488
- :keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
1489
- Default value is "application/json".
1490
- :paramtype content_type: str
1491
- :return: None
1492
- :rtype: None
1493
- :raises ~azure.core.exceptions.HttpResponseError:
1494
-
1495
- Example:
1496
- .. code-block:: python
1497
-
1498
- # JSON input template you can fill out and use as your body input.
1499
- body = {
1500
- "id": "str", # Optional. Optional portal token ID to invalidate one token
1501
- by.
1502
- "subject": "str" # Optional. Optional subject to invalidate all tokens for
1503
- subject.
1504
- }
1505
- """
1506
-
1507
- @overload
1508
- def invalidate_portal_tokens( # pylint: disable=inconsistent-return-statements
1509
- self, body: Optional[IO] = None, *, content_type: str = "application/json", **kwargs: Any
1510
- ) -> None:
1511
- """invalidate_portal_tokens.
1512
-
1513
- :param body: Default value is None.
1514
- :type body: IO
1515
- :keyword content_type: Body Parameter content-type. Content type parameter for binary body.
1516
- Default value is "application/json".
1517
- :paramtype content_type: str
1518
- :return: None
1519
- :rtype: None
1520
- :raises ~azure.core.exceptions.HttpResponseError:
1521
- """
1522
-
1523
- @distributed_trace
1524
- def invalidate_portal_tokens( # pylint: disable=inconsistent-return-statements
1525
- self, body: Optional[Union[JSON, IO]] = None, **kwargs: Any
1526
- ) -> None:
1527
- """invalidate_portal_tokens.
1528
-
1529
- :param body: Is either a JSON type or a IO type. Default value is None.
1530
- :type body: JSON or IO
1531
- :keyword content_type: Body Parameter content-type. Known values are: 'application/json'.
1532
- Default value is None.
1533
- :paramtype content_type: str
1534
- :return: None
1535
- :rtype: None
1536
- :raises ~azure.core.exceptions.HttpResponseError:
1537
-
1538
- Example:
1539
- .. code-block:: python
1540
-
1541
- # JSON input template you can fill out and use as your body input.
1542
- body = {
1543
- "id": "str", # Optional. Optional portal token ID to invalidate one token
1544
- by.
1545
- "subject": "str" # Optional. Optional subject to invalidate all tokens for
1546
- subject.
1547
- }
1548
- """
1549
- error_map = {
1550
- 401: ClientAuthenticationError,
1551
- 404: ResourceNotFoundError,
1552
- 409: ResourceExistsError,
1553
- 304: ResourceNotModifiedError,
1554
- 400: HttpResponseError,
1555
- }
1556
- error_map.update(kwargs.pop("error_map", {}) or {})
1557
-
1558
- _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
1559
- _params = kwargs.pop("params", {}) or {}
1560
-
1561
- content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
1562
- cls: ClsType[None] = kwargs.pop("cls", None)
1563
-
1564
- content_type = content_type or "application/json"
1565
- _json = None
1566
- _content = None
1567
- if isinstance(body, (IOBase, bytes)):
1568
- _content = body
1569
- else:
1570
- if body is not None:
1571
- _json = body
1572
- else:
1573
- _json = None
1574
-
1575
- _request = build_invalidate_portal_tokens_request(
1576
- content_type=content_type,
1577
- json=_json,
1578
- content=_content,
1579
- headers=_headers,
1580
- params=_params,
1581
- )
1582
- _request.url = self._client.format_url(_request.url)
1583
-
1584
- _stream = False
1585
- pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access
1586
- _request, stream=_stream, **kwargs
1587
- )
1588
-
1589
- response = pipeline_response.http_response
1590
-
1591
- if response.status_code not in [204]:
1592
- if _stream:
1593
- response.read() # Load the body in memory and close the socket
1594
- map_error(status_code=response.status_code, response=response, error_map=error_map)
1595
- raise HttpResponseError(response=response)
1596
-
1597
- if cls:
1598
- return cls(pipeline_response, None, {}) # type: ignore
1599
-
1600
- @distributed_trace
1601
- def list_subjects(self, **kwargs: Any) -> List[JSON]:
1602
- """list_subjects.
1603
-
1604
- :return: list of JSON object
1605
- :rtype: list[JSON]
1606
- :raises ~azure.core.exceptions.HttpResponseError:
1607
-
1608
- Example:
1609
- .. code-block:: python
1610
-
1611
- # response body for status code(s): 200
1612
- response == [
1613
- {
1614
- "id": "str", # Required.
1615
- "key": "str", # Required.
1616
- "currentPeriodEnd": "2020-02-20 00:00:00", # Optional.
1617
- "currentPeriodStart": "2020-02-20 00:00:00", # Optional.
1618
- "displayName": "str", # Optional.
1619
- "metadata": {
1620
- "str": {} # Optional. Dictionary of :code:`<any>`.
1621
- },
1622
- "stripeCustomerId": "str" # Optional.
1623
- }
1624
- ]
1625
- """
1626
- error_map = {
1627
- 401: ClientAuthenticationError,
1628
- 404: ResourceNotFoundError,
1629
- 409: ResourceExistsError,
1630
- 304: ResourceNotModifiedError,
1631
- }
1632
- error_map.update(kwargs.pop("error_map", {}) or {})
1633
-
1634
- _headers = kwargs.pop("headers", {}) or {}
1635
- _params = kwargs.pop("params", {}) or {}
1636
-
1637
- cls: ClsType[List[JSON]] = kwargs.pop("cls", None)
1638
-
1639
- _request = build_list_subjects_request(
1640
- headers=_headers,
1641
- params=_params,
1642
- )
1643
- _request.url = self._client.format_url(_request.url)
1644
-
1645
- _stream = False
1646
- pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access
1647
- _request, stream=_stream, **kwargs
1648
- )
1649
-
1650
- response = pipeline_response.http_response
1651
-
1652
- if response.status_code not in [200]:
1653
- if _stream:
1654
- response.read() # Load the body in memory and close the socket
1655
- map_error(status_code=response.status_code, response=response, error_map=error_map)
1656
- raise HttpResponseError(response=response)
1657
-
1658
- if response.content:
1659
- deserialized = response.json()
1660
- else:
1661
- deserialized = None
1662
-
1663
- if cls:
1664
- return cls(pipeline_response, cast(List[JSON], deserialized), {}) # type: ignore
1665
-
1666
- return cast(List[JSON], deserialized) # type: ignore
1667
-
1668
- @overload
1669
- def upsert_subject(
1670
- self, body: Optional[List[JSON]] = None, *, content_type: str = "application/json", **kwargs: Any
1671
- ) -> List[JSON]:
1672
- """Upserts a subject. Creates or updates subject.
1673
- If the subject doesn't exist, it will be created.
1674
- If the subject exists, it will be partially updated with the provided fields.
1675
-
1676
- :param body: Default value is None.
1677
- :type body: list[JSON]
1678
- :keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
1679
- Default value is "application/json".
1680
- :paramtype content_type: str
1681
- :return: list of JSON object
1682
- :rtype: list[JSON]
1683
- :raises ~azure.core.exceptions.HttpResponseError:
1684
-
1685
- Example:
1686
- .. code-block:: python
1687
-
1688
- # JSON input template you can fill out and use as your body input.
1689
- body = [
1690
- {
1691
- "id": "str", # Required.
1692
- "key": "str", # Required.
1693
- "currentPeriodEnd": "2020-02-20 00:00:00", # Optional.
1694
- "currentPeriodStart": "2020-02-20 00:00:00", # Optional.
1695
- "displayName": "str", # Optional.
1696
- "metadata": {
1697
- "str": {} # Optional. Dictionary of :code:`<any>`.
1698
- },
1699
- "stripeCustomerId": "str" # Optional.
1700
- }
1701
- ]
1702
-
1703
- # response body for status code(s): 200
1704
- response == [
1705
- {
1706
- "id": "str", # Required.
1707
- "key": "str", # Required.
1708
- "currentPeriodEnd": "2020-02-20 00:00:00", # Optional.
1709
- "currentPeriodStart": "2020-02-20 00:00:00", # Optional.
1710
- "displayName": "str", # Optional.
1711
- "metadata": {
1712
- "str": {} # Optional. Dictionary of :code:`<any>`.
1713
- },
1714
- "stripeCustomerId": "str" # Optional.
1715
- }
1716
- ]
1717
- """
1718
-
1719
- @overload
1720
- def upsert_subject(
1721
- self, body: Optional[IO] = None, *, content_type: str = "application/json", **kwargs: Any
1722
- ) -> List[JSON]:
1723
- """Upserts a subject. Creates or updates subject.
1724
- If the subject doesn't exist, it will be created.
1725
- If the subject exists, it will be partially updated with the provided fields.
1726
-
1727
- :param body: Default value is None.
1728
- :type body: IO
1729
- :keyword content_type: Body Parameter content-type. Content type parameter for binary body.
1730
- Default value is "application/json".
1731
- :paramtype content_type: str
1732
- :return: list of JSON object
1733
- :rtype: list[JSON]
1734
- :raises ~azure.core.exceptions.HttpResponseError:
1735
-
1736
- Example:
1737
- .. code-block:: python
1738
-
1739
- # response body for status code(s): 200
1740
- response == [
1741
- {
1742
- "id": "str", # Required.
1743
- "key": "str", # Required.
1744
- "currentPeriodEnd": "2020-02-20 00:00:00", # Optional.
1745
- "currentPeriodStart": "2020-02-20 00:00:00", # Optional.
1746
- "displayName": "str", # Optional.
1747
- "metadata": {
1748
- "str": {} # Optional. Dictionary of :code:`<any>`.
1749
- },
1750
- "stripeCustomerId": "str" # Optional.
1751
- }
1752
- ]
1753
- """
1754
-
1755
- @distributed_trace
1756
- def upsert_subject(self, body: Optional[Union[List[JSON], IO]] = None, **kwargs: Any) -> List[JSON]:
1757
- """Upserts a subject. Creates or updates subject.
1758
- If the subject doesn't exist, it will be created.
1759
- If the subject exists, it will be partially updated with the provided fields.
1760
-
1761
- :param body: Is either a [JSON] type or a IO type. Default value is None.
1762
- :type body: list[JSON] or IO
1763
- :keyword content_type: Body Parameter content-type. Known values are: 'application/json'.
1764
- Default value is None.
1765
- :paramtype content_type: str
1766
- :return: list of JSON object
1767
- :rtype: list[JSON]
1768
- :raises ~azure.core.exceptions.HttpResponseError:
1769
-
1770
- Example:
1771
- .. code-block:: python
1772
-
1773
- # response body for status code(s): 200
1774
- response == [
1775
- {
1776
- "id": "str", # Required.
1777
- "key": "str", # Required.
1778
- "currentPeriodEnd": "2020-02-20 00:00:00", # Optional.
1779
- "currentPeriodStart": "2020-02-20 00:00:00", # Optional.
1780
- "displayName": "str", # Optional.
1781
- "metadata": {
1782
- "str": {} # Optional. Dictionary of :code:`<any>`.
1783
- },
1784
- "stripeCustomerId": "str" # Optional.
1785
- }
1786
- ]
1787
- """
1788
- error_map = {
1789
- 401: ClientAuthenticationError,
1790
- 404: ResourceNotFoundError,
1791
- 409: ResourceExistsError,
1792
- 304: ResourceNotModifiedError,
1793
- 400: HttpResponseError,
1794
- }
1795
- error_map.update(kwargs.pop("error_map", {}) or {})
1796
-
1797
- _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
1798
- _params = kwargs.pop("params", {}) or {}
1799
-
1800
- content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
1801
- cls: ClsType[List[JSON]] = kwargs.pop("cls", None)
1802
-
1803
- content_type = content_type or "application/json"
1804
- _json = None
1805
- _content = None
1806
- if isinstance(body, (IOBase, bytes)):
1807
- _content = body
1808
- else:
1809
- if body is not None:
1810
- _json = body
1811
- else:
1812
- _json = None
1813
-
1814
- _request = build_upsert_subject_request(
1815
- content_type=content_type,
1816
- json=_json,
1817
- content=_content,
1818
- headers=_headers,
1819
- params=_params,
1820
- )
1821
- _request.url = self._client.format_url(_request.url)
1822
-
1823
- _stream = False
1824
- pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access
1825
- _request, stream=_stream, **kwargs
1826
- )
1827
-
1828
- response = pipeline_response.http_response
1829
-
1830
- if response.status_code not in [200]:
1831
- if _stream:
1832
- response.read() # Load the body in memory and close the socket
1833
- map_error(status_code=response.status_code, response=response, error_map=error_map)
1834
- raise HttpResponseError(response=response)
1835
-
1836
- if response.content:
1837
- deserialized = response.json()
1838
- else:
1839
- deserialized = None
1840
-
1841
- if cls:
1842
- return cls(pipeline_response, cast(List[JSON], deserialized), {}) # type: ignore
1843
-
1844
- return cast(List[JSON], deserialized) # type: ignore
1845
-
1846
- @distributed_trace
1847
- def get_subject(self, subject_id_or_key: str, **kwargs: Any) -> JSON:
1848
- """get_subject.
1849
-
1850
- :param subject_id_or_key: A unique identifier for a subject. Required.
1851
- :type subject_id_or_key: str
1852
- :return: JSON object
1853
- :rtype: JSON
1854
- :raises ~azure.core.exceptions.HttpResponseError:
1855
-
1856
- Example:
1857
- .. code-block:: python
1858
-
1859
- # response body for status code(s): 200
1860
- response == {
1861
- "id": "str", # Required.
1862
- "key": "str", # Required.
1863
- "currentPeriodEnd": "2020-02-20 00:00:00", # Optional.
1864
- "currentPeriodStart": "2020-02-20 00:00:00", # Optional.
1865
- "displayName": "str", # Optional.
1866
- "metadata": {
1867
- "str": {} # Optional. Dictionary of :code:`<any>`.
1868
- },
1869
- "stripeCustomerId": "str" # Optional.
1870
- }
1871
- """
1872
- error_map = {
1873
- 401: ClientAuthenticationError,
1874
- 404: ResourceNotFoundError,
1875
- 409: ResourceExistsError,
1876
- 304: ResourceNotModifiedError,
1877
- }
1878
- error_map.update(kwargs.pop("error_map", {}) or {})
1879
-
1880
- _headers = kwargs.pop("headers", {}) or {}
1881
- _params = kwargs.pop("params", {}) or {}
1882
-
1883
- cls: ClsType[JSON] = kwargs.pop("cls", None)
1884
-
1885
- _request = build_get_subject_request(
1886
- subject_id_or_key=subject_id_or_key,
1887
- headers=_headers,
1888
- params=_params,
1889
- )
1890
- _request.url = self._client.format_url(_request.url)
1891
-
1892
- _stream = False
1893
- pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access
1894
- _request, stream=_stream, **kwargs
1895
- )
1896
-
1897
- response = pipeline_response.http_response
1898
-
1899
- if response.status_code not in [200]:
1900
- if _stream:
1901
- response.read() # Load the body in memory and close the socket
1902
- map_error(status_code=response.status_code, response=response, error_map=error_map)
1903
- raise HttpResponseError(response=response)
1904
-
1905
- if response.content:
1906
- deserialized = response.json()
1907
- else:
1908
- deserialized = None
1909
-
1910
- if cls:
1911
- return cls(pipeline_response, cast(JSON, deserialized), {}) # type: ignore
1912
-
1913
- return cast(JSON, deserialized) # type: ignore
1914
-
1915
- @distributed_trace
1916
- def delete_subject( # pylint: disable=inconsistent-return-statements
1917
- self, subject_id_or_key: str, **kwargs: Any
1918
- ) -> None:
1919
- """delete_subject.
1920
-
1921
- :param subject_id_or_key: A unique identifier for a subject. Required.
1922
- :type subject_id_or_key: str
1923
- :return: None
1924
- :rtype: None
1925
- :raises ~azure.core.exceptions.HttpResponseError:
1926
- """
1927
- error_map = {
1928
- 401: ClientAuthenticationError,
1929
- 404: ResourceNotFoundError,
1930
- 409: ResourceExistsError,
1931
- 304: ResourceNotModifiedError,
1932
- 400: HttpResponseError,
1933
- }
1934
- error_map.update(kwargs.pop("error_map", {}) or {})
1935
-
1936
- _headers = kwargs.pop("headers", {}) or {}
1937
- _params = kwargs.pop("params", {}) or {}
1938
-
1939
- cls: ClsType[None] = kwargs.pop("cls", None)
1940
-
1941
- _request = build_delete_subject_request(
1942
- subject_id_or_key=subject_id_or_key,
1943
- headers=_headers,
1944
- params=_params,
1945
- )
1946
- _request.url = self._client.format_url(_request.url)
1947
-
1948
- _stream = False
1949
- pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access
1950
- _request, stream=_stream, **kwargs
1951
- )
1952
-
1953
- response = pipeline_response.http_response
1954
-
1955
- if response.status_code not in [204]:
1956
- if _stream:
1957
- response.read() # Load the body in memory and close the socket
1958
- map_error(status_code=response.status_code, response=response, error_map=error_map)
1959
- raise HttpResponseError(response=response)
1960
-
1961
- if cls:
1962
- return cls(pipeline_response, None, {}) # type: ignore
1963
-
1964
- @distributed_trace
1965
- def query_portal_meter(
1966
- self,
1967
- meter_slug: str,
1968
- *,
1969
- from_parameter: Optional[datetime.datetime] = None,
1970
- to: Optional[datetime.datetime] = None,
1971
- window_size: Optional[str] = None,
1972
- window_time_zone: str = "UTC",
1973
- group_by: Optional[List[str]] = None,
1974
- **kwargs: Any
1975
- ) -> Union[JSON, str]:
1976
- """query_portal_meter.
1977
-
1978
- :param meter_slug: Required.
1979
- :type meter_slug: str
1980
- :keyword from_parameter: Start date-time in RFC 3339 format.
1981
- Inclusive. Default value is None.
1982
- :paramtype from_parameter: ~datetime.datetime
1983
- :keyword to: End date-time in RFC 3339 format.
1984
- Inclusive. Default value is None.
1985
- :paramtype to: ~datetime.datetime
1986
- :keyword window_size: If not specified, a single usage aggregate will be returned for the
1987
- entirety of the specified period for each subject and group. Known values are: "MINUTE",
1988
- "HOUR", and "DAY". Default value is None.
1989
- :paramtype window_size: str
1990
- :keyword window_time_zone: The value is the name of the time zone as defined in the IANA Time
1991
- Zone Database (http://www.iana.org/time-zones).
1992
- If not specified, the UTC timezone will be used. Default value is "UTC".
1993
- :paramtype window_time_zone: str
1994
- :keyword group_by: If not specified a single aggregate will be returned for each subject and
1995
- time window.
1996
- ``subject`` is a reserved group by value. Default value is None.
1997
- :paramtype group_by: list[str]
1998
- :return: JSON object or str
1999
- :rtype: JSON or str
2000
- :raises ~azure.core.exceptions.HttpResponseError:
2001
-
2002
- Example:
2003
- .. code-block:: python
2004
-
2005
- # response body for status code(s): 200
2006
- response == {
2007
- "data": [
2008
- {
2009
- "value": 0.0, # Required.
2010
- "windowEnd": "2020-02-20 00:00:00", # Required.
2011
- "windowStart": "2020-02-20 00:00:00", # Required.
2012
- "groupBy": {
2013
- "str": "str" # Optional. Dictionary of
2014
- :code:`<string>`.
2015
- },
2016
- "subject": "str" # Optional. The subject of the meter value.
2017
- }
2018
- ],
2019
- "from": "2020-02-20 00:00:00", # Optional.
2020
- "to": "2020-02-20 00:00:00", # Optional.
2021
- "windowSize": "str" # Optional. Aggregation window size. Known values are:
2022
- "MINUTE", "HOUR", and "DAY".
2023
- }
2024
- # response body for status code(s): 401
2025
- response == {
2026
- "detail": "str", # A human-readable explanation specific to this occurrence
2027
- of the problem. Required.
2028
- "status": 0, # The HTTP status code generated by the origin server for this
2029
- occurrence of the problem. Required.
2030
- "title": "str", # A a short, human-readable summary of the problem type.
2031
- Required.
2032
- "type": "str", # Type contains a URI that identifies the problem type.
2033
- Required.
2034
- "instance": "str" # Optional. A URI reference that identifies the specific
2035
- occurrence of the problem.
2036
- }
2037
- """
2038
- error_map = {
2039
- 401: ClientAuthenticationError,
2040
- 404: ResourceNotFoundError,
2041
- 409: ResourceExistsError,
2042
- 304: ResourceNotModifiedError,
2043
- 400: HttpResponseError,
2044
- }
2045
- error_map.update(kwargs.pop("error_map", {}) or {})
2046
-
2047
- _headers = kwargs.pop("headers", {}) or {}
2048
- _params = kwargs.pop("params", {}) or {}
2049
-
2050
- cls: ClsType[Union[JSON, str]] = kwargs.pop("cls", None)
2051
-
2052
- _request = build_query_portal_meter_request(
2053
- meter_slug=meter_slug,
2054
- from_parameter=from_parameter,
2055
- to=to,
2056
- window_size=window_size,
2057
- window_time_zone=window_time_zone,
2058
- group_by=group_by,
2059
- headers=_headers,
2060
- params=_params,
2061
- )
2062
- _request.url = self._client.format_url(_request.url)
2063
-
2064
- _stream = False
2065
- pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access
2066
- _request, stream=_stream, **kwargs
2067
- )
2068
-
2069
- response = pipeline_response.http_response
2070
-
2071
- if response.status_code not in [200, 200, 401]:
2072
- if _stream:
2073
- response.read() # Load the body in memory and close the socket
2074
- map_error(status_code=response.status_code, response=response, error_map=error_map)
2075
- raise HttpResponseError(response=response)
2076
-
2077
- if response.status_code == 200:
2078
- if response.content:
2079
- deserialized = response.json()
2080
- else:
2081
- deserialized = None
2082
-
2083
- if response.status_code == 200:
2084
- if response.content:
2085
- deserialized = response.json()
2086
- else:
2087
- deserialized = None
2088
-
2089
- if response.status_code == 401:
2090
- if response.content:
2091
- deserialized = response.json()
2092
- else:
2093
- deserialized = None
2094
-
2095
- if cls:
2096
- return cls(pipeline_response, cast(Union[JSON, str], deserialized), {}) # type: ignore
2097
-
2098
- return cast(Union[JSON, str], deserialized) # type: ignore