2313 lines
91 KiB
Python
2313 lines
91 KiB
Python
# Copyright 2026 Google LLC
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
#
|
|
# pyformat: disable
|
|
|
|
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
|
|
from . import errors, models, types, utils
|
|
from ._hooks import AfterParseErrorContext, HookContext, ResponseContext
|
|
from .basesdk import AsyncBaseSDK, BaseSDK
|
|
from .types import OptionalNullable, UNSET, interactions, webhooks
|
|
from .types.webhooks import (
|
|
pingwebhookrequest as webhooks_pingwebhookrequest,
|
|
rotatesigningsecretrequest as webhooks_rotatesigningsecretrequest,
|
|
webhook as webhooks_webhook,
|
|
webhookupdate as webhooks_webhookupdate,
|
|
)
|
|
from .utils import get_security_from_env, response_helpers
|
|
from .utils.unmarshal_json_response import unmarshal_json_response
|
|
import httpx
|
|
from typing import Any, Iterable, List, Mapping, Optional, Union, cast
|
|
|
|
|
|
class Webhooks(BaseSDK):
|
|
@property
|
|
def with_raw_response(self):
|
|
return WebhooksWithRawResponse(self)
|
|
|
|
@property
|
|
def with_streaming_response(self):
|
|
return WebhooksWithStreamingResponse(self)
|
|
|
|
def create(
|
|
self,
|
|
*,
|
|
uri: str,
|
|
subscribed_events: Iterable[webhooks_webhook.WebhookSubscribedEvent],
|
|
api_version: Optional[str] = None,
|
|
name: Optional[str] = None,
|
|
extra_headers: Optional[Mapping[str, str]] = None,
|
|
extra_query: Optional[Mapping[str, Any]] = None,
|
|
extra_body: Optional[Mapping[str, Any]] = None,
|
|
timeout: Optional[Union[float, httpx.Timeout]] = None,
|
|
) -> webhooks.Webhook:
|
|
r"""Creates a new Webhook.
|
|
|
|
:param uri: Required. The URI to which webhook events will be sent.
|
|
:param subscribed_events: Required. The events that the webhook is subscribed to.
|
|
Available events:
|
|
- batch.succeeded
|
|
- batch.expired
|
|
- batch.failed
|
|
- interaction.requires_action
|
|
- interaction.completed
|
|
- interaction.failed
|
|
- video.generated
|
|
:param api_version: Which version of the API to use.
|
|
:param name: Optional. The user-provided name of the webhook.
|
|
:param extra_headers: Additional headers to set or replace on requests.
|
|
:param extra_query: Additional query parameters to append to requests.
|
|
:param extra_body: Additional JSON object fields to merge into request bodies.
|
|
:param timeout: Override the default request timeout configuration for this method in seconds
|
|
"""
|
|
base_url = None
|
|
url_variables = None
|
|
retries: OptionalNullable[utils.RetryConfig] = UNSET
|
|
server_url = None
|
|
http_headers = extra_headers
|
|
timeout_ms = self._coerce_timeout_ms(timeout)
|
|
if timeout_ms is None:
|
|
timeout_ms = self.sdk_configuration.timeout_ms
|
|
|
|
if server_url is not None:
|
|
base_url = server_url
|
|
else:
|
|
base_url = self._get_url(base_url, url_variables)
|
|
|
|
request = models.CreateWebhookRequest(
|
|
api_version=api_version,
|
|
body=webhooks.WebhookInput(
|
|
name=name,
|
|
uri=uri,
|
|
subscribed_events=utils.unmarshal(
|
|
subscribed_events, List[webhooks.WebhookSubscribedEvent]
|
|
),
|
|
),
|
|
)
|
|
|
|
_speakeasy_response_mode, http_headers = response_helpers.consume_response_mode(
|
|
http_headers
|
|
)
|
|
req = self._build_request(
|
|
method="POST",
|
|
path="/{api_version}/webhooks",
|
|
base_url=base_url,
|
|
url_variables=url_variables,
|
|
request=request,
|
|
request_body_required=True,
|
|
request_has_path_params=True,
|
|
request_has_query_params=True,
|
|
user_agent_header="user-agent",
|
|
accept_header_value="application/json",
|
|
http_headers=http_headers,
|
|
extra_query_params=extra_query,
|
|
_globals=models.CreateWebhookGlobals(
|
|
api_version=self.sdk_configuration.globals.api_version,
|
|
),
|
|
security=self.sdk_configuration.security,
|
|
get_serialized_body=lambda: utils.serialize_request_body(
|
|
request.body,
|
|
False,
|
|
False,
|
|
"json",
|
|
webhooks.WebhookInput,
|
|
extra_body=extra_body,
|
|
),
|
|
allow_empty_value=None,
|
|
timeout_ms=timeout_ms,
|
|
)
|
|
|
|
if retries == UNSET:
|
|
if self.sdk_configuration.retry_config is not UNSET:
|
|
retries = self.sdk_configuration.retry_config
|
|
else:
|
|
retries = utils.RetryConfig(
|
|
"attempt-count-backoff",
|
|
utils.BackoffStrategy(500, 8000, 2, 30000),
|
|
True,
|
|
max_retries=4,
|
|
)
|
|
|
|
retry_config = None
|
|
if isinstance(retries, utils.RetryConfig):
|
|
retry_config = (retries, ["408", "409", "429", "5XX"])
|
|
|
|
def _speakeasy_parse_response(http_res):
|
|
if utils.match_response(http_res, "4XX", "*"):
|
|
http_res_text = utils.stream_to_text(http_res)
|
|
raise errors.GenAiDefaultError(
|
|
"API error occurred", http_res, http_res_text
|
|
)
|
|
if utils.match_response(http_res, "5XX", "*"):
|
|
http_res_text = utils.stream_to_text(http_res)
|
|
raise errors.GenAiDefaultError(
|
|
"API error occurred", http_res, http_res_text
|
|
)
|
|
if utils.match_response(http_res, "default", "application/json"):
|
|
return unmarshal_json_response(
|
|
webhooks.Webhook, http_res, validate=False
|
|
)
|
|
|
|
raise errors.GenAiDefaultError("Unexpected response received", http_res)
|
|
|
|
_speakeasy_hook_ctx = HookContext(
|
|
config=self.sdk_configuration,
|
|
base_url=base_url or "",
|
|
operation_id="CreateWebhook",
|
|
oauth2_scopes=None,
|
|
security_source=get_security_from_env(
|
|
self.sdk_configuration.security, types.Security
|
|
),
|
|
response=ResponseContext(mode=_speakeasy_response_mode, execution="sync"),
|
|
)
|
|
http_res = self.do_request(
|
|
hook_ctx=_speakeasy_hook_ctx,
|
|
request=req,
|
|
is_error_status_code=lambda c: utils.match_status_codes(["4XX", "5XX"], c),
|
|
stream=_speakeasy_response_mode == "streaming",
|
|
retry_config=retry_config,
|
|
)
|
|
if _speakeasy_response_mode != "parsed":
|
|
_speakeasy_response_cls = (
|
|
response_helpers.StreamedAPIResponse
|
|
if _speakeasy_response_mode == "streaming"
|
|
else response_helpers.APIResponse
|
|
)
|
|
return cast(
|
|
Any,
|
|
_speakeasy_response_cls(
|
|
raw=http_res,
|
|
parser=_speakeasy_parse_response,
|
|
mode="buffered",
|
|
client_ref=self,
|
|
hook_ctx=AfterParseErrorContext(_speakeasy_hook_ctx),
|
|
hooks=self.sdk_configuration.__dict__.get("_hooks"),
|
|
),
|
|
)
|
|
try:
|
|
return _speakeasy_parse_response(http_res)
|
|
except Exception as parse_exc_:
|
|
response_helpers.raise_parse_error(
|
|
self.sdk_configuration.__dict__["_hooks"],
|
|
AfterParseErrorContext(_speakeasy_hook_ctx),
|
|
http_res,
|
|
parse_exc_,
|
|
)
|
|
|
|
def list(
|
|
self,
|
|
*,
|
|
api_version: Optional[str] = None,
|
|
page_size: Optional[int] = None,
|
|
page_token: Optional[str] = None,
|
|
extra_headers: Optional[Mapping[str, str]] = None,
|
|
extra_query: Optional[Mapping[str, Any]] = None,
|
|
timeout: Optional[Union[float, httpx.Timeout]] = None,
|
|
) -> webhooks.WebhookListResponse:
|
|
r"""Lists all Webhooks.
|
|
|
|
:param api_version: Which version of the API to use.
|
|
:param page_size: Optional. The maximum number of webhooks to return. The service may return fewer than
|
|
this value. If unspecified, at most 50 webhooks will be returned.
|
|
The maximum value is 1000.
|
|
:param page_token: Optional. A page token, received from a previous `ListWebhooks` call.
|
|
Provide this to retrieve the subsequent page.
|
|
:param extra_headers: Additional headers to set or replace on requests.
|
|
:param extra_query: Additional query parameters to append to requests.
|
|
:param timeout: Override the default request timeout configuration for this method in seconds
|
|
"""
|
|
base_url = None
|
|
url_variables = None
|
|
retries: OptionalNullable[utils.RetryConfig] = UNSET
|
|
server_url = None
|
|
http_headers = extra_headers
|
|
timeout_ms = self._coerce_timeout_ms(timeout)
|
|
if timeout_ms is None:
|
|
timeout_ms = self.sdk_configuration.timeout_ms
|
|
|
|
if server_url is not None:
|
|
base_url = server_url
|
|
else:
|
|
base_url = self._get_url(base_url, url_variables)
|
|
|
|
request = models.ListWebhooksRequest(
|
|
api_version=api_version,
|
|
page_size=page_size,
|
|
page_token=page_token,
|
|
)
|
|
|
|
_speakeasy_response_mode, http_headers = response_helpers.consume_response_mode(
|
|
http_headers
|
|
)
|
|
req = self._build_request(
|
|
method="GET",
|
|
path="/{api_version}/webhooks",
|
|
base_url=base_url,
|
|
url_variables=url_variables,
|
|
request=request,
|
|
request_body_required=False,
|
|
request_has_path_params=True,
|
|
request_has_query_params=True,
|
|
user_agent_header="user-agent",
|
|
accept_header_value="application/json",
|
|
http_headers=http_headers,
|
|
extra_query_params=extra_query,
|
|
_globals=models.ListWebhooksGlobals(
|
|
api_version=self.sdk_configuration.globals.api_version,
|
|
),
|
|
security=self.sdk_configuration.security,
|
|
allow_empty_value=None,
|
|
timeout_ms=timeout_ms,
|
|
)
|
|
|
|
if retries == UNSET:
|
|
if self.sdk_configuration.retry_config is not UNSET:
|
|
retries = self.sdk_configuration.retry_config
|
|
else:
|
|
retries = utils.RetryConfig(
|
|
"attempt-count-backoff",
|
|
utils.BackoffStrategy(500, 8000, 2, 30000),
|
|
True,
|
|
max_retries=4,
|
|
)
|
|
|
|
retry_config = None
|
|
if isinstance(retries, utils.RetryConfig):
|
|
retry_config = (retries, ["408", "409", "429", "5XX"])
|
|
|
|
def _speakeasy_parse_response(http_res):
|
|
if utils.match_response(http_res, "4XX", "*"):
|
|
http_res_text = utils.stream_to_text(http_res)
|
|
raise errors.GenAiDefaultError(
|
|
"API error occurred", http_res, http_res_text
|
|
)
|
|
if utils.match_response(http_res, "5XX", "*"):
|
|
http_res_text = utils.stream_to_text(http_res)
|
|
raise errors.GenAiDefaultError(
|
|
"API error occurred", http_res, http_res_text
|
|
)
|
|
if utils.match_response(http_res, "default", "application/json"):
|
|
return unmarshal_json_response(
|
|
webhooks.WebhookListResponse, http_res, validate=False
|
|
)
|
|
|
|
raise errors.GenAiDefaultError("Unexpected response received", http_res)
|
|
|
|
_speakeasy_hook_ctx = HookContext(
|
|
config=self.sdk_configuration,
|
|
base_url=base_url or "",
|
|
operation_id="ListWebhooks",
|
|
oauth2_scopes=None,
|
|
security_source=get_security_from_env(
|
|
self.sdk_configuration.security, types.Security
|
|
),
|
|
response=ResponseContext(mode=_speakeasy_response_mode, execution="sync"),
|
|
)
|
|
http_res = self.do_request(
|
|
hook_ctx=_speakeasy_hook_ctx,
|
|
request=req,
|
|
is_error_status_code=lambda c: utils.match_status_codes(["4XX", "5XX"], c),
|
|
stream=_speakeasy_response_mode == "streaming",
|
|
retry_config=retry_config,
|
|
)
|
|
if _speakeasy_response_mode != "parsed":
|
|
_speakeasy_response_cls = (
|
|
response_helpers.StreamedAPIResponse
|
|
if _speakeasy_response_mode == "streaming"
|
|
else response_helpers.APIResponse
|
|
)
|
|
return cast(
|
|
Any,
|
|
_speakeasy_response_cls(
|
|
raw=http_res,
|
|
parser=_speakeasy_parse_response,
|
|
mode="buffered",
|
|
client_ref=self,
|
|
hook_ctx=AfterParseErrorContext(_speakeasy_hook_ctx),
|
|
hooks=self.sdk_configuration.__dict__.get("_hooks"),
|
|
),
|
|
)
|
|
try:
|
|
return _speakeasy_parse_response(http_res)
|
|
except Exception as parse_exc_:
|
|
response_helpers.raise_parse_error(
|
|
self.sdk_configuration.__dict__["_hooks"],
|
|
AfterParseErrorContext(_speakeasy_hook_ctx),
|
|
http_res,
|
|
parse_exc_,
|
|
)
|
|
|
|
def get(
|
|
self,
|
|
id: str,
|
|
*,
|
|
api_version: Optional[str] = None,
|
|
extra_headers: Optional[Mapping[str, str]] = None,
|
|
extra_query: Optional[Mapping[str, Any]] = None,
|
|
timeout: Optional[Union[float, httpx.Timeout]] = None,
|
|
) -> webhooks.Webhook:
|
|
r"""Gets a specific Webhook.
|
|
|
|
:param id: Required. The ID of the webhook to retrieve.
|
|
:param api_version: Which version of the API to use.
|
|
:param extra_headers: Additional headers to set or replace on requests.
|
|
:param extra_query: Additional query parameters to append to requests.
|
|
:param timeout: Override the default request timeout configuration for this method in seconds
|
|
"""
|
|
base_url = None
|
|
url_variables = None
|
|
retries: OptionalNullable[utils.RetryConfig] = UNSET
|
|
server_url = None
|
|
http_headers = extra_headers
|
|
timeout_ms = self._coerce_timeout_ms(timeout)
|
|
if timeout_ms is None:
|
|
timeout_ms = self.sdk_configuration.timeout_ms
|
|
|
|
if server_url is not None:
|
|
base_url = server_url
|
|
else:
|
|
base_url = self._get_url(base_url, url_variables)
|
|
|
|
request = models.GetWebhookRequest(
|
|
api_version=api_version,
|
|
id=id,
|
|
)
|
|
|
|
_speakeasy_response_mode, http_headers = response_helpers.consume_response_mode(
|
|
http_headers
|
|
)
|
|
req = self._build_request(
|
|
method="GET",
|
|
path="/{api_version}/webhooks/{id}",
|
|
base_url=base_url,
|
|
url_variables=url_variables,
|
|
request=request,
|
|
request_body_required=False,
|
|
request_has_path_params=True,
|
|
request_has_query_params=True,
|
|
user_agent_header="user-agent",
|
|
accept_header_value="application/json",
|
|
http_headers=http_headers,
|
|
extra_query_params=extra_query,
|
|
_globals=models.GetWebhookGlobals(
|
|
api_version=self.sdk_configuration.globals.api_version,
|
|
),
|
|
security=self.sdk_configuration.security,
|
|
allow_empty_value=None,
|
|
timeout_ms=timeout_ms,
|
|
)
|
|
|
|
if retries == UNSET:
|
|
if self.sdk_configuration.retry_config is not UNSET:
|
|
retries = self.sdk_configuration.retry_config
|
|
else:
|
|
retries = utils.RetryConfig(
|
|
"attempt-count-backoff",
|
|
utils.BackoffStrategy(500, 8000, 2, 30000),
|
|
True,
|
|
max_retries=4,
|
|
)
|
|
|
|
retry_config = None
|
|
if isinstance(retries, utils.RetryConfig):
|
|
retry_config = (retries, ["408", "409", "429", "5XX"])
|
|
|
|
def _speakeasy_parse_response(http_res):
|
|
if utils.match_response(http_res, "4XX", "*"):
|
|
http_res_text = utils.stream_to_text(http_res)
|
|
raise errors.GenAiDefaultError(
|
|
"API error occurred", http_res, http_res_text
|
|
)
|
|
if utils.match_response(http_res, "5XX", "*"):
|
|
http_res_text = utils.stream_to_text(http_res)
|
|
raise errors.GenAiDefaultError(
|
|
"API error occurred", http_res, http_res_text
|
|
)
|
|
if utils.match_response(http_res, "default", "application/json"):
|
|
return unmarshal_json_response(
|
|
webhooks.Webhook, http_res, validate=False
|
|
)
|
|
|
|
raise errors.GenAiDefaultError("Unexpected response received", http_res)
|
|
|
|
_speakeasy_hook_ctx = HookContext(
|
|
config=self.sdk_configuration,
|
|
base_url=base_url or "",
|
|
operation_id="GetWebhook",
|
|
oauth2_scopes=None,
|
|
security_source=get_security_from_env(
|
|
self.sdk_configuration.security, types.Security
|
|
),
|
|
response=ResponseContext(mode=_speakeasy_response_mode, execution="sync"),
|
|
)
|
|
http_res = self.do_request(
|
|
hook_ctx=_speakeasy_hook_ctx,
|
|
request=req,
|
|
is_error_status_code=lambda c: utils.match_status_codes(["4XX", "5XX"], c),
|
|
stream=_speakeasy_response_mode == "streaming",
|
|
retry_config=retry_config,
|
|
)
|
|
if _speakeasy_response_mode != "parsed":
|
|
_speakeasy_response_cls = (
|
|
response_helpers.StreamedAPIResponse
|
|
if _speakeasy_response_mode == "streaming"
|
|
else response_helpers.APIResponse
|
|
)
|
|
return cast(
|
|
Any,
|
|
_speakeasy_response_cls(
|
|
raw=http_res,
|
|
parser=_speakeasy_parse_response,
|
|
mode="buffered",
|
|
client_ref=self,
|
|
hook_ctx=AfterParseErrorContext(_speakeasy_hook_ctx),
|
|
hooks=self.sdk_configuration.__dict__.get("_hooks"),
|
|
),
|
|
)
|
|
try:
|
|
return _speakeasy_parse_response(http_res)
|
|
except Exception as parse_exc_:
|
|
response_helpers.raise_parse_error(
|
|
self.sdk_configuration.__dict__["_hooks"],
|
|
AfterParseErrorContext(_speakeasy_hook_ctx),
|
|
http_res,
|
|
parse_exc_,
|
|
)
|
|
|
|
def update(
|
|
self,
|
|
id: str,
|
|
*,
|
|
api_version: Optional[str] = None,
|
|
update_mask: Optional[str] = None,
|
|
name: Optional[str] = None,
|
|
uri: Optional[str] = None,
|
|
subscribed_events: Optional[
|
|
Iterable[webhooks_webhookupdate.WebhookUpdateSubscribedEvent]
|
|
] = None,
|
|
state: Optional[webhooks_webhookupdate.WebhookUpdateState] = None,
|
|
extra_headers: Optional[Mapping[str, str]] = None,
|
|
extra_query: Optional[Mapping[str, Any]] = None,
|
|
extra_body: Optional[Mapping[str, Any]] = None,
|
|
timeout: Optional[Union[float, httpx.Timeout]] = None,
|
|
) -> webhooks.Webhook:
|
|
r"""Updates an existing Webhook.
|
|
|
|
:param id: Required. The ID of the webhook to update.
|
|
:param api_version: Which version of the API to use.
|
|
:param update_mask: Optional. The list of fields to update.
|
|
:param name: Optional. The user-provided name of the webhook.
|
|
:param uri: Optional. The URI to which webhook events will be sent.
|
|
:param subscribed_events: Optional. The events that the webhook is subscribed to.
|
|
Available events:
|
|
- batch.succeeded
|
|
- batch.expired
|
|
- batch.failed
|
|
- interaction.requires_action
|
|
- interaction.completed
|
|
- interaction.failed
|
|
- video.generated
|
|
:param state: Optional. The state of the webhook.
|
|
:param extra_headers: Additional headers to set or replace on requests.
|
|
:param extra_query: Additional query parameters to append to requests.
|
|
:param extra_body: Additional JSON object fields to merge into request bodies.
|
|
:param timeout: Override the default request timeout configuration for this method in seconds
|
|
"""
|
|
base_url = None
|
|
url_variables = None
|
|
retries: OptionalNullable[utils.RetryConfig] = UNSET
|
|
server_url = None
|
|
http_headers = extra_headers
|
|
timeout_ms = self._coerce_timeout_ms(timeout)
|
|
if timeout_ms is None:
|
|
timeout_ms = self.sdk_configuration.timeout_ms
|
|
|
|
if server_url is not None:
|
|
base_url = server_url
|
|
else:
|
|
base_url = self._get_url(base_url, url_variables)
|
|
|
|
request = models.UpdateWebhookRequest(
|
|
api_version=api_version,
|
|
id=id,
|
|
update_mask=update_mask,
|
|
body=webhooks.WebhookUpdate(
|
|
name=name,
|
|
uri=uri,
|
|
subscribed_events=utils.unmarshal(
|
|
subscribed_events,
|
|
Optional[List[webhooks.WebhookUpdateSubscribedEvent]],
|
|
),
|
|
state=state,
|
|
),
|
|
)
|
|
|
|
_speakeasy_response_mode, http_headers = response_helpers.consume_response_mode(
|
|
http_headers
|
|
)
|
|
req = self._build_request(
|
|
method="PATCH",
|
|
path="/{api_version}/webhooks/{id}",
|
|
base_url=base_url,
|
|
url_variables=url_variables,
|
|
request=request,
|
|
request_body_required=False,
|
|
request_has_path_params=True,
|
|
request_has_query_params=True,
|
|
user_agent_header="user-agent",
|
|
accept_header_value="application/json",
|
|
http_headers=http_headers,
|
|
extra_query_params=extra_query,
|
|
_globals=models.UpdateWebhookGlobals(
|
|
api_version=self.sdk_configuration.globals.api_version,
|
|
),
|
|
security=self.sdk_configuration.security,
|
|
get_serialized_body=lambda: utils.serialize_request_body(
|
|
request.body if request is not None else None,
|
|
False,
|
|
True,
|
|
"json",
|
|
Optional[webhooks.WebhookUpdate],
|
|
extra_body=extra_body,
|
|
),
|
|
allow_empty_value=None,
|
|
timeout_ms=timeout_ms,
|
|
)
|
|
|
|
if retries == UNSET:
|
|
if self.sdk_configuration.retry_config is not UNSET:
|
|
retries = self.sdk_configuration.retry_config
|
|
else:
|
|
retries = utils.RetryConfig(
|
|
"attempt-count-backoff",
|
|
utils.BackoffStrategy(500, 8000, 2, 30000),
|
|
True,
|
|
max_retries=4,
|
|
)
|
|
|
|
retry_config = None
|
|
if isinstance(retries, utils.RetryConfig):
|
|
retry_config = (retries, ["408", "409", "429", "5XX"])
|
|
|
|
def _speakeasy_parse_response(http_res):
|
|
if utils.match_response(http_res, "4XX", "*"):
|
|
http_res_text = utils.stream_to_text(http_res)
|
|
raise errors.GenAiDefaultError(
|
|
"API error occurred", http_res, http_res_text
|
|
)
|
|
if utils.match_response(http_res, "5XX", "*"):
|
|
http_res_text = utils.stream_to_text(http_res)
|
|
raise errors.GenAiDefaultError(
|
|
"API error occurred", http_res, http_res_text
|
|
)
|
|
if utils.match_response(http_res, "default", "application/json"):
|
|
return unmarshal_json_response(
|
|
webhooks.Webhook, http_res, validate=False
|
|
)
|
|
|
|
raise errors.GenAiDefaultError("Unexpected response received", http_res)
|
|
|
|
_speakeasy_hook_ctx = HookContext(
|
|
config=self.sdk_configuration,
|
|
base_url=base_url or "",
|
|
operation_id="UpdateWebhook",
|
|
oauth2_scopes=None,
|
|
security_source=get_security_from_env(
|
|
self.sdk_configuration.security, types.Security
|
|
),
|
|
response=ResponseContext(mode=_speakeasy_response_mode, execution="sync"),
|
|
)
|
|
http_res = self.do_request(
|
|
hook_ctx=_speakeasy_hook_ctx,
|
|
request=req,
|
|
is_error_status_code=lambda c: utils.match_status_codes(["4XX", "5XX"], c),
|
|
stream=_speakeasy_response_mode == "streaming",
|
|
retry_config=retry_config,
|
|
)
|
|
if _speakeasy_response_mode != "parsed":
|
|
_speakeasy_response_cls = (
|
|
response_helpers.StreamedAPIResponse
|
|
if _speakeasy_response_mode == "streaming"
|
|
else response_helpers.APIResponse
|
|
)
|
|
return cast(
|
|
Any,
|
|
_speakeasy_response_cls(
|
|
raw=http_res,
|
|
parser=_speakeasy_parse_response,
|
|
mode="buffered",
|
|
client_ref=self,
|
|
hook_ctx=AfterParseErrorContext(_speakeasy_hook_ctx),
|
|
hooks=self.sdk_configuration.__dict__.get("_hooks"),
|
|
),
|
|
)
|
|
try:
|
|
return _speakeasy_parse_response(http_res)
|
|
except Exception as parse_exc_:
|
|
response_helpers.raise_parse_error(
|
|
self.sdk_configuration.__dict__["_hooks"],
|
|
AfterParseErrorContext(_speakeasy_hook_ctx),
|
|
http_res,
|
|
parse_exc_,
|
|
)
|
|
|
|
def delete(
|
|
self,
|
|
id: str,
|
|
*,
|
|
api_version: Optional[str] = None,
|
|
extra_headers: Optional[Mapping[str, str]] = None,
|
|
extra_query: Optional[Mapping[str, Any]] = None,
|
|
timeout: Optional[Union[float, httpx.Timeout]] = None,
|
|
) -> interactions.Empty:
|
|
r"""Deletes a Webhook.
|
|
|
|
:param id: Required. The ID of the webhook to delete.
|
|
Format: `{webhook_id}`
|
|
:param api_version: Which version of the API to use.
|
|
:param extra_headers: Additional headers to set or replace on requests.
|
|
:param extra_query: Additional query parameters to append to requests.
|
|
:param timeout: Override the default request timeout configuration for this method in seconds
|
|
"""
|
|
base_url = None
|
|
url_variables = None
|
|
retries: OptionalNullable[utils.RetryConfig] = UNSET
|
|
server_url = None
|
|
http_headers = extra_headers
|
|
timeout_ms = self._coerce_timeout_ms(timeout)
|
|
if timeout_ms is None:
|
|
timeout_ms = self.sdk_configuration.timeout_ms
|
|
|
|
if server_url is not None:
|
|
base_url = server_url
|
|
else:
|
|
base_url = self._get_url(base_url, url_variables)
|
|
|
|
request = models.DeleteWebhookRequest(
|
|
api_version=api_version,
|
|
id=id,
|
|
)
|
|
|
|
_speakeasy_response_mode, http_headers = response_helpers.consume_response_mode(
|
|
http_headers
|
|
)
|
|
req = self._build_request(
|
|
method="DELETE",
|
|
path="/{api_version}/webhooks/{id}",
|
|
base_url=base_url,
|
|
url_variables=url_variables,
|
|
request=request,
|
|
request_body_required=False,
|
|
request_has_path_params=True,
|
|
request_has_query_params=True,
|
|
user_agent_header="user-agent",
|
|
accept_header_value="application/json",
|
|
http_headers=http_headers,
|
|
extra_query_params=extra_query,
|
|
_globals=models.DeleteWebhookGlobals(
|
|
api_version=self.sdk_configuration.globals.api_version,
|
|
),
|
|
security=self.sdk_configuration.security,
|
|
allow_empty_value=None,
|
|
timeout_ms=timeout_ms,
|
|
)
|
|
|
|
if retries == UNSET:
|
|
if self.sdk_configuration.retry_config is not UNSET:
|
|
retries = self.sdk_configuration.retry_config
|
|
else:
|
|
retries = utils.RetryConfig(
|
|
"attempt-count-backoff",
|
|
utils.BackoffStrategy(500, 8000, 2, 30000),
|
|
True,
|
|
max_retries=4,
|
|
)
|
|
|
|
retry_config = None
|
|
if isinstance(retries, utils.RetryConfig):
|
|
retry_config = (retries, ["408", "409", "429", "5XX"])
|
|
|
|
def _speakeasy_parse_response(http_res):
|
|
if utils.match_response(http_res, "4XX", "*"):
|
|
http_res_text = utils.stream_to_text(http_res)
|
|
raise errors.GenAiDefaultError(
|
|
"API error occurred", http_res, http_res_text
|
|
)
|
|
if utils.match_response(http_res, "5XX", "*"):
|
|
http_res_text = utils.stream_to_text(http_res)
|
|
raise errors.GenAiDefaultError(
|
|
"API error occurred", http_res, http_res_text
|
|
)
|
|
if utils.match_response(http_res, "default", "application/json"):
|
|
return unmarshal_json_response(
|
|
interactions.Empty, http_res, validate=False
|
|
)
|
|
|
|
raise errors.GenAiDefaultError("Unexpected response received", http_res)
|
|
|
|
_speakeasy_hook_ctx = HookContext(
|
|
config=self.sdk_configuration,
|
|
base_url=base_url or "",
|
|
operation_id="DeleteWebhook",
|
|
oauth2_scopes=None,
|
|
security_source=get_security_from_env(
|
|
self.sdk_configuration.security, types.Security
|
|
),
|
|
response=ResponseContext(mode=_speakeasy_response_mode, execution="sync"),
|
|
)
|
|
http_res = self.do_request(
|
|
hook_ctx=_speakeasy_hook_ctx,
|
|
request=req,
|
|
is_error_status_code=lambda c: utils.match_status_codes(["4XX", "5XX"], c),
|
|
stream=_speakeasy_response_mode == "streaming",
|
|
retry_config=retry_config,
|
|
)
|
|
if _speakeasy_response_mode != "parsed":
|
|
_speakeasy_response_cls = (
|
|
response_helpers.StreamedAPIResponse
|
|
if _speakeasy_response_mode == "streaming"
|
|
else response_helpers.APIResponse
|
|
)
|
|
return cast(
|
|
Any,
|
|
_speakeasy_response_cls(
|
|
raw=http_res,
|
|
parser=_speakeasy_parse_response,
|
|
mode="buffered",
|
|
client_ref=self,
|
|
hook_ctx=AfterParseErrorContext(_speakeasy_hook_ctx),
|
|
hooks=self.sdk_configuration.__dict__.get("_hooks"),
|
|
),
|
|
)
|
|
try:
|
|
return _speakeasy_parse_response(http_res)
|
|
except Exception as parse_exc_:
|
|
response_helpers.raise_parse_error(
|
|
self.sdk_configuration.__dict__["_hooks"],
|
|
AfterParseErrorContext(_speakeasy_hook_ctx),
|
|
http_res,
|
|
parse_exc_,
|
|
)
|
|
|
|
def rotate_signing_secret(
|
|
self,
|
|
id: str,
|
|
*,
|
|
api_version: Optional[str] = None,
|
|
revocation_behavior: Optional[
|
|
webhooks_rotatesigningsecretrequest.RevocationBehavior
|
|
] = None,
|
|
extra_headers: Optional[Mapping[str, str]] = None,
|
|
extra_query: Optional[Mapping[str, Any]] = None,
|
|
extra_body: Optional[Mapping[str, Any]] = None,
|
|
timeout: Optional[Union[float, httpx.Timeout]] = None,
|
|
) -> webhooks.WebhookRotateSigningSecretResponse:
|
|
r"""Generates a new signing secret for a Webhook.
|
|
|
|
:param id: Required. The ID of the webhook for which to generate a signing secret.
|
|
Format: `{webhook_id}`
|
|
:param api_version: Which version of the API to use.
|
|
:param revocation_behavior: Optional. The revocation behavior for previous signing secrets.
|
|
:param extra_headers: Additional headers to set or replace on requests.
|
|
:param extra_query: Additional query parameters to append to requests.
|
|
:param extra_body: Additional JSON object fields to merge into request bodies.
|
|
:param timeout: Override the default request timeout configuration for this method in seconds
|
|
"""
|
|
base_url = None
|
|
url_variables = None
|
|
retries: OptionalNullable[utils.RetryConfig] = UNSET
|
|
server_url = None
|
|
http_headers = extra_headers
|
|
timeout_ms = self._coerce_timeout_ms(timeout)
|
|
if timeout_ms is None:
|
|
timeout_ms = self.sdk_configuration.timeout_ms
|
|
|
|
if server_url is not None:
|
|
base_url = server_url
|
|
else:
|
|
base_url = self._get_url(base_url, url_variables)
|
|
|
|
request = models.RotateSigningSecretRequest(
|
|
api_version=api_version,
|
|
id=id,
|
|
body=webhooks.RotateSigningSecretRequest(
|
|
revocation_behavior=revocation_behavior,
|
|
),
|
|
)
|
|
|
|
_speakeasy_response_mode, http_headers = response_helpers.consume_response_mode(
|
|
http_headers
|
|
)
|
|
req = self._build_request(
|
|
method="POST",
|
|
path="/{api_version}/webhooks/{id}:rotateSigningSecret",
|
|
base_url=base_url,
|
|
url_variables=url_variables,
|
|
request=request,
|
|
request_body_required=False,
|
|
request_has_path_params=True,
|
|
request_has_query_params=True,
|
|
user_agent_header="user-agent",
|
|
accept_header_value="application/json",
|
|
http_headers=http_headers,
|
|
extra_query_params=extra_query,
|
|
_globals=models.RotateSigningSecretGlobals(
|
|
api_version=self.sdk_configuration.globals.api_version,
|
|
),
|
|
security=self.sdk_configuration.security,
|
|
get_serialized_body=lambda: utils.serialize_request_body(
|
|
request.body if request is not None else None,
|
|
False,
|
|
True,
|
|
"json",
|
|
Optional[webhooks.RotateSigningSecretRequest],
|
|
extra_body=extra_body,
|
|
),
|
|
allow_empty_value=None,
|
|
timeout_ms=timeout_ms,
|
|
)
|
|
|
|
if retries == UNSET:
|
|
if self.sdk_configuration.retry_config is not UNSET:
|
|
retries = self.sdk_configuration.retry_config
|
|
else:
|
|
retries = utils.RetryConfig(
|
|
"attempt-count-backoff",
|
|
utils.BackoffStrategy(500, 8000, 2, 30000),
|
|
True,
|
|
max_retries=4,
|
|
)
|
|
|
|
retry_config = None
|
|
if isinstance(retries, utils.RetryConfig):
|
|
retry_config = (retries, ["408", "409", "429", "5XX"])
|
|
|
|
def _speakeasy_parse_response(http_res):
|
|
if utils.match_response(http_res, "4XX", "*"):
|
|
http_res_text = utils.stream_to_text(http_res)
|
|
raise errors.GenAiDefaultError(
|
|
"API error occurred", http_res, http_res_text
|
|
)
|
|
if utils.match_response(http_res, "5XX", "*"):
|
|
http_res_text = utils.stream_to_text(http_res)
|
|
raise errors.GenAiDefaultError(
|
|
"API error occurred", http_res, http_res_text
|
|
)
|
|
if utils.match_response(http_res, "default", "application/json"):
|
|
return unmarshal_json_response(
|
|
webhooks.WebhookRotateSigningSecretResponse,
|
|
http_res,
|
|
validate=False,
|
|
)
|
|
|
|
raise errors.GenAiDefaultError("Unexpected response received", http_res)
|
|
|
|
_speakeasy_hook_ctx = HookContext(
|
|
config=self.sdk_configuration,
|
|
base_url=base_url or "",
|
|
operation_id="RotateSigningSecret",
|
|
oauth2_scopes=None,
|
|
security_source=get_security_from_env(
|
|
self.sdk_configuration.security, types.Security
|
|
),
|
|
response=ResponseContext(mode=_speakeasy_response_mode, execution="sync"),
|
|
)
|
|
http_res = self.do_request(
|
|
hook_ctx=_speakeasy_hook_ctx,
|
|
request=req,
|
|
is_error_status_code=lambda c: utils.match_status_codes(["4XX", "5XX"], c),
|
|
stream=_speakeasy_response_mode == "streaming",
|
|
retry_config=retry_config,
|
|
)
|
|
if _speakeasy_response_mode != "parsed":
|
|
_speakeasy_response_cls = (
|
|
response_helpers.StreamedAPIResponse
|
|
if _speakeasy_response_mode == "streaming"
|
|
else response_helpers.APIResponse
|
|
)
|
|
return cast(
|
|
Any,
|
|
_speakeasy_response_cls(
|
|
raw=http_res,
|
|
parser=_speakeasy_parse_response,
|
|
mode="buffered",
|
|
client_ref=self,
|
|
hook_ctx=AfterParseErrorContext(_speakeasy_hook_ctx),
|
|
hooks=self.sdk_configuration.__dict__.get("_hooks"),
|
|
),
|
|
)
|
|
try:
|
|
return _speakeasy_parse_response(http_res)
|
|
except Exception as parse_exc_:
|
|
response_helpers.raise_parse_error(
|
|
self.sdk_configuration.__dict__["_hooks"],
|
|
AfterParseErrorContext(_speakeasy_hook_ctx),
|
|
http_res,
|
|
parse_exc_,
|
|
)
|
|
|
|
def ping(
|
|
self,
|
|
id: str,
|
|
*,
|
|
api_version: Optional[str] = None,
|
|
body: Optional[
|
|
Union[
|
|
webhooks_pingwebhookrequest.PingWebhookRequest,
|
|
webhooks_pingwebhookrequest.PingWebhookRequestParam,
|
|
]
|
|
] = None,
|
|
extra_headers: Optional[Mapping[str, str]] = None,
|
|
extra_query: Optional[Mapping[str, Any]] = None,
|
|
extra_body: Optional[Mapping[str, Any]] = None,
|
|
timeout: Optional[Union[float, httpx.Timeout]] = None,
|
|
) -> webhooks.WebhookPingResponse:
|
|
r"""Sends a ping event to a Webhook.
|
|
|
|
:param id: Required. The ID of the webhook to ping.
|
|
Format: `{webhook_id}`
|
|
:param api_version: Which version of the API to use.
|
|
:param body: The request body.
|
|
:param extra_headers: Additional headers to set or replace on requests.
|
|
:param extra_query: Additional query parameters to append to requests.
|
|
:param extra_body: Additional JSON object fields to merge into request bodies.
|
|
:param timeout: Override the default request timeout configuration for this method in seconds
|
|
"""
|
|
base_url = None
|
|
url_variables = None
|
|
retries: OptionalNullable[utils.RetryConfig] = UNSET
|
|
server_url = None
|
|
http_headers = extra_headers
|
|
timeout_ms = self._coerce_timeout_ms(timeout)
|
|
if timeout_ms is None:
|
|
timeout_ms = self.sdk_configuration.timeout_ms
|
|
|
|
if server_url is not None:
|
|
base_url = server_url
|
|
else:
|
|
base_url = self._get_url(base_url, url_variables)
|
|
|
|
request = models.PingWebhookRequest(
|
|
api_version=api_version,
|
|
id=id,
|
|
body=utils.get_pydantic_model(body, Optional[webhooks.PingWebhookRequest]),
|
|
)
|
|
|
|
_speakeasy_response_mode, http_headers = response_helpers.consume_response_mode(
|
|
http_headers
|
|
)
|
|
req = self._build_request(
|
|
method="POST",
|
|
path="/{api_version}/webhooks/{id}:ping",
|
|
base_url=base_url,
|
|
url_variables=url_variables,
|
|
request=request,
|
|
request_body_required=False,
|
|
request_has_path_params=True,
|
|
request_has_query_params=True,
|
|
user_agent_header="user-agent",
|
|
accept_header_value="application/json",
|
|
http_headers=http_headers,
|
|
extra_query_params=extra_query,
|
|
_globals=models.PingWebhookGlobals(
|
|
api_version=self.sdk_configuration.globals.api_version,
|
|
),
|
|
security=self.sdk_configuration.security,
|
|
get_serialized_body=lambda: utils.serialize_request_body(
|
|
request.body if request is not None else None,
|
|
False,
|
|
True,
|
|
"json",
|
|
Optional[webhooks.PingWebhookRequest],
|
|
extra_body=extra_body,
|
|
),
|
|
allow_empty_value=None,
|
|
timeout_ms=timeout_ms,
|
|
)
|
|
|
|
if retries == UNSET:
|
|
if self.sdk_configuration.retry_config is not UNSET:
|
|
retries = self.sdk_configuration.retry_config
|
|
else:
|
|
retries = utils.RetryConfig(
|
|
"attempt-count-backoff",
|
|
utils.BackoffStrategy(500, 8000, 2, 30000),
|
|
True,
|
|
max_retries=4,
|
|
)
|
|
|
|
retry_config = None
|
|
if isinstance(retries, utils.RetryConfig):
|
|
retry_config = (retries, ["408", "409", "429", "5XX"])
|
|
|
|
def _speakeasy_parse_response(http_res):
|
|
if utils.match_response(http_res, "4XX", "*"):
|
|
http_res_text = utils.stream_to_text(http_res)
|
|
raise errors.GenAiDefaultError(
|
|
"API error occurred", http_res, http_res_text
|
|
)
|
|
if utils.match_response(http_res, "5XX", "*"):
|
|
http_res_text = utils.stream_to_text(http_res)
|
|
raise errors.GenAiDefaultError(
|
|
"API error occurred", http_res, http_res_text
|
|
)
|
|
if utils.match_response(http_res, "default", "application/json"):
|
|
return unmarshal_json_response(
|
|
webhooks.WebhookPingResponse, http_res, validate=False
|
|
)
|
|
|
|
raise errors.GenAiDefaultError("Unexpected response received", http_res)
|
|
|
|
_speakeasy_hook_ctx = HookContext(
|
|
config=self.sdk_configuration,
|
|
base_url=base_url or "",
|
|
operation_id="PingWebhook",
|
|
oauth2_scopes=None,
|
|
security_source=get_security_from_env(
|
|
self.sdk_configuration.security, types.Security
|
|
),
|
|
response=ResponseContext(mode=_speakeasy_response_mode, execution="sync"),
|
|
)
|
|
http_res = self.do_request(
|
|
hook_ctx=_speakeasy_hook_ctx,
|
|
request=req,
|
|
is_error_status_code=lambda c: utils.match_status_codes(["4XX", "5XX"], c),
|
|
stream=_speakeasy_response_mode == "streaming",
|
|
retry_config=retry_config,
|
|
)
|
|
if _speakeasy_response_mode != "parsed":
|
|
_speakeasy_response_cls = (
|
|
response_helpers.StreamedAPIResponse
|
|
if _speakeasy_response_mode == "streaming"
|
|
else response_helpers.APIResponse
|
|
)
|
|
return cast(
|
|
Any,
|
|
_speakeasy_response_cls(
|
|
raw=http_res,
|
|
parser=_speakeasy_parse_response,
|
|
mode="buffered",
|
|
client_ref=self,
|
|
hook_ctx=AfterParseErrorContext(_speakeasy_hook_ctx),
|
|
hooks=self.sdk_configuration.__dict__.get("_hooks"),
|
|
),
|
|
)
|
|
try:
|
|
return _speakeasy_parse_response(http_res)
|
|
except Exception as parse_exc_:
|
|
response_helpers.raise_parse_error(
|
|
self.sdk_configuration.__dict__["_hooks"],
|
|
AfterParseErrorContext(_speakeasy_hook_ctx),
|
|
http_res,
|
|
parse_exc_,
|
|
)
|
|
|
|
|
|
class WebhooksWithRawResponse:
|
|
def __init__(self, sdk: Webhooks) -> None:
|
|
self._sdk = sdk
|
|
self.create = response_helpers.to_raw_response_wrapper(
|
|
sdk.create, "extra_headers"
|
|
)
|
|
self.list = response_helpers.to_raw_response_wrapper(sdk.list, "extra_headers")
|
|
self.get = response_helpers.to_raw_response_wrapper(sdk.get, "extra_headers")
|
|
self.update = response_helpers.to_raw_response_wrapper(
|
|
sdk.update, "extra_headers"
|
|
)
|
|
self.delete = response_helpers.to_raw_response_wrapper(
|
|
sdk.delete, "extra_headers"
|
|
)
|
|
self.rotate_signing_secret = response_helpers.to_raw_response_wrapper(
|
|
sdk.rotate_signing_secret, "extra_headers"
|
|
)
|
|
self.ping = response_helpers.to_raw_response_wrapper(sdk.ping, "extra_headers")
|
|
|
|
|
|
class WebhooksWithStreamingResponse:
|
|
def __init__(self, sdk: Webhooks) -> None:
|
|
self._sdk = sdk
|
|
self.create = response_helpers.to_streamed_response_wrapper(
|
|
sdk.create, "extra_headers"
|
|
)
|
|
self.list = response_helpers.to_streamed_response_wrapper(
|
|
sdk.list, "extra_headers"
|
|
)
|
|
self.get = response_helpers.to_streamed_response_wrapper(
|
|
sdk.get, "extra_headers"
|
|
)
|
|
self.update = response_helpers.to_streamed_response_wrapper(
|
|
sdk.update, "extra_headers"
|
|
)
|
|
self.delete = response_helpers.to_streamed_response_wrapper(
|
|
sdk.delete, "extra_headers"
|
|
)
|
|
self.rotate_signing_secret = response_helpers.to_streamed_response_wrapper(
|
|
sdk.rotate_signing_secret, "extra_headers"
|
|
)
|
|
self.ping = response_helpers.to_streamed_response_wrapper(
|
|
sdk.ping, "extra_headers"
|
|
)
|
|
|
|
|
|
class AsyncWebhooks(AsyncBaseSDK):
|
|
@property
|
|
def with_raw_response(self):
|
|
return AsyncWebhooksWithRawResponse(self)
|
|
|
|
@property
|
|
def with_streaming_response(self):
|
|
return AsyncWebhooksWithStreamingResponse(self)
|
|
|
|
async def create(
|
|
self,
|
|
*,
|
|
uri: str,
|
|
subscribed_events: Iterable[webhooks_webhook.WebhookSubscribedEvent],
|
|
api_version: Optional[str] = None,
|
|
name: Optional[str] = None,
|
|
extra_headers: Optional[Mapping[str, str]] = None,
|
|
extra_query: Optional[Mapping[str, Any]] = None,
|
|
extra_body: Optional[Mapping[str, Any]] = None,
|
|
timeout: Optional[Union[float, httpx.Timeout]] = None,
|
|
) -> webhooks.Webhook:
|
|
r"""Creates a new Webhook.
|
|
|
|
:param uri: Required. The URI to which webhook events will be sent.
|
|
:param subscribed_events: Required. The events that the webhook is subscribed to.
|
|
Available events:
|
|
- batch.succeeded
|
|
- batch.expired
|
|
- batch.failed
|
|
- interaction.requires_action
|
|
- interaction.completed
|
|
- interaction.failed
|
|
- video.generated
|
|
:param api_version: Which version of the API to use.
|
|
:param name: Optional. The user-provided name of the webhook.
|
|
:param extra_headers: Additional headers to set or replace on requests.
|
|
:param extra_query: Additional query parameters to append to requests.
|
|
:param extra_body: Additional JSON object fields to merge into request bodies.
|
|
:param timeout: Override the default request timeout configuration for this method in seconds
|
|
"""
|
|
base_url = None
|
|
url_variables = None
|
|
retries: OptionalNullable[utils.RetryConfig] = UNSET
|
|
server_url = None
|
|
http_headers = extra_headers
|
|
timeout_ms = self._coerce_timeout_ms(timeout)
|
|
if timeout_ms is None:
|
|
timeout_ms = self.sdk_configuration.timeout_ms
|
|
|
|
if server_url is not None:
|
|
base_url = server_url
|
|
else:
|
|
base_url = self._get_url(base_url, url_variables)
|
|
|
|
request = models.CreateWebhookRequest(
|
|
api_version=api_version,
|
|
body=webhooks.WebhookInput(
|
|
name=name,
|
|
uri=uri,
|
|
subscribed_events=utils.unmarshal(
|
|
subscribed_events, List[webhooks.WebhookSubscribedEvent]
|
|
),
|
|
),
|
|
)
|
|
|
|
_speakeasy_response_mode, http_headers = response_helpers.consume_response_mode(
|
|
http_headers
|
|
)
|
|
req = self._build_request_async(
|
|
method="POST",
|
|
path="/{api_version}/webhooks",
|
|
base_url=base_url,
|
|
url_variables=url_variables,
|
|
request=request,
|
|
request_body_required=True,
|
|
request_has_path_params=True,
|
|
request_has_query_params=True,
|
|
user_agent_header="user-agent",
|
|
accept_header_value="application/json",
|
|
http_headers=http_headers,
|
|
extra_query_params=extra_query,
|
|
_globals=models.CreateWebhookGlobals(
|
|
api_version=self.sdk_configuration.globals.api_version,
|
|
),
|
|
security=self.sdk_configuration.security,
|
|
get_serialized_body=lambda: utils.serialize_request_body(
|
|
request.body,
|
|
False,
|
|
False,
|
|
"json",
|
|
webhooks.WebhookInput,
|
|
extra_body=extra_body,
|
|
),
|
|
allow_empty_value=None,
|
|
timeout_ms=timeout_ms,
|
|
)
|
|
|
|
if retries == UNSET:
|
|
if self.sdk_configuration.retry_config is not UNSET:
|
|
retries = self.sdk_configuration.retry_config
|
|
else:
|
|
retries = utils.RetryConfig(
|
|
"attempt-count-backoff",
|
|
utils.BackoffStrategy(500, 8000, 2, 30000),
|
|
True,
|
|
max_retries=4,
|
|
)
|
|
|
|
retry_config = None
|
|
if isinstance(retries, utils.RetryConfig):
|
|
retry_config = (retries, ["408", "409", "429", "5XX"])
|
|
|
|
async def _speakeasy_parse_response(http_res):
|
|
if utils.match_response(http_res, "4XX", "*"):
|
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
raise errors.GenAiDefaultError(
|
|
"API error occurred", http_res, http_res_text
|
|
)
|
|
if utils.match_response(http_res, "5XX", "*"):
|
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
raise errors.GenAiDefaultError(
|
|
"API error occurred", http_res, http_res_text
|
|
)
|
|
if utils.match_response(http_res, "default", "application/json"):
|
|
return unmarshal_json_response(
|
|
webhooks.Webhook, http_res, validate=False
|
|
)
|
|
|
|
raise errors.GenAiDefaultError("Unexpected response received", http_res)
|
|
|
|
_speakeasy_hook_ctx = HookContext(
|
|
config=self.sdk_configuration,
|
|
base_url=base_url or "",
|
|
operation_id="CreateWebhook",
|
|
oauth2_scopes=None,
|
|
security_source=get_security_from_env(
|
|
self.sdk_configuration.security, types.Security
|
|
),
|
|
response=ResponseContext(mode=_speakeasy_response_mode, execution="async"),
|
|
)
|
|
http_res = await self.do_request_async(
|
|
hook_ctx=_speakeasy_hook_ctx,
|
|
request=req,
|
|
is_error_status_code=lambda c: utils.match_status_codes(["4XX", "5XX"], c),
|
|
stream=_speakeasy_response_mode == "streaming",
|
|
retry_config=retry_config,
|
|
)
|
|
if _speakeasy_response_mode != "parsed":
|
|
_speakeasy_response_cls = (
|
|
response_helpers.AsyncStreamedAPIResponse
|
|
if _speakeasy_response_mode == "streaming"
|
|
else response_helpers.AsyncAPIResponse
|
|
)
|
|
return cast(
|
|
Any,
|
|
_speakeasy_response_cls(
|
|
raw=http_res,
|
|
parser=_speakeasy_parse_response,
|
|
mode="buffered",
|
|
client_ref=self,
|
|
hook_ctx=AfterParseErrorContext(_speakeasy_hook_ctx),
|
|
hooks=self.sdk_configuration.__dict__.get("_hooks"),
|
|
async_hooks=self.sdk_configuration.__dict__.get("_async_hooks"),
|
|
),
|
|
)
|
|
try:
|
|
return await _speakeasy_parse_response(http_res)
|
|
except Exception as parse_exc_:
|
|
await response_helpers.raise_parse_error_async(
|
|
self.sdk_configuration.__dict__.get("_async_hooks"),
|
|
self.sdk_configuration.__dict__.get("_hooks"),
|
|
AfterParseErrorContext(_speakeasy_hook_ctx),
|
|
http_res,
|
|
parse_exc_,
|
|
)
|
|
|
|
async def list(
|
|
self,
|
|
*,
|
|
api_version: Optional[str] = None,
|
|
page_size: Optional[int] = None,
|
|
page_token: Optional[str] = None,
|
|
extra_headers: Optional[Mapping[str, str]] = None,
|
|
extra_query: Optional[Mapping[str, Any]] = None,
|
|
timeout: Optional[Union[float, httpx.Timeout]] = None,
|
|
) -> webhooks.WebhookListResponse:
|
|
r"""Lists all Webhooks.
|
|
|
|
:param api_version: Which version of the API to use.
|
|
:param page_size: Optional. The maximum number of webhooks to return. The service may return fewer than
|
|
this value. If unspecified, at most 50 webhooks will be returned.
|
|
The maximum value is 1000.
|
|
:param page_token: Optional. A page token, received from a previous `ListWebhooks` call.
|
|
Provide this to retrieve the subsequent page.
|
|
:param extra_headers: Additional headers to set or replace on requests.
|
|
:param extra_query: Additional query parameters to append to requests.
|
|
:param timeout: Override the default request timeout configuration for this method in seconds
|
|
"""
|
|
base_url = None
|
|
url_variables = None
|
|
retries: OptionalNullable[utils.RetryConfig] = UNSET
|
|
server_url = None
|
|
http_headers = extra_headers
|
|
timeout_ms = self._coerce_timeout_ms(timeout)
|
|
if timeout_ms is None:
|
|
timeout_ms = self.sdk_configuration.timeout_ms
|
|
|
|
if server_url is not None:
|
|
base_url = server_url
|
|
else:
|
|
base_url = self._get_url(base_url, url_variables)
|
|
|
|
request = models.ListWebhooksRequest(
|
|
api_version=api_version,
|
|
page_size=page_size,
|
|
page_token=page_token,
|
|
)
|
|
|
|
_speakeasy_response_mode, http_headers = response_helpers.consume_response_mode(
|
|
http_headers
|
|
)
|
|
req = self._build_request_async(
|
|
method="GET",
|
|
path="/{api_version}/webhooks",
|
|
base_url=base_url,
|
|
url_variables=url_variables,
|
|
request=request,
|
|
request_body_required=False,
|
|
request_has_path_params=True,
|
|
request_has_query_params=True,
|
|
user_agent_header="user-agent",
|
|
accept_header_value="application/json",
|
|
http_headers=http_headers,
|
|
extra_query_params=extra_query,
|
|
_globals=models.ListWebhooksGlobals(
|
|
api_version=self.sdk_configuration.globals.api_version,
|
|
),
|
|
security=self.sdk_configuration.security,
|
|
allow_empty_value=None,
|
|
timeout_ms=timeout_ms,
|
|
)
|
|
|
|
if retries == UNSET:
|
|
if self.sdk_configuration.retry_config is not UNSET:
|
|
retries = self.sdk_configuration.retry_config
|
|
else:
|
|
retries = utils.RetryConfig(
|
|
"attempt-count-backoff",
|
|
utils.BackoffStrategy(500, 8000, 2, 30000),
|
|
True,
|
|
max_retries=4,
|
|
)
|
|
|
|
retry_config = None
|
|
if isinstance(retries, utils.RetryConfig):
|
|
retry_config = (retries, ["408", "409", "429", "5XX"])
|
|
|
|
async def _speakeasy_parse_response(http_res):
|
|
if utils.match_response(http_res, "4XX", "*"):
|
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
raise errors.GenAiDefaultError(
|
|
"API error occurred", http_res, http_res_text
|
|
)
|
|
if utils.match_response(http_res, "5XX", "*"):
|
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
raise errors.GenAiDefaultError(
|
|
"API error occurred", http_res, http_res_text
|
|
)
|
|
if utils.match_response(http_res, "default", "application/json"):
|
|
return unmarshal_json_response(
|
|
webhooks.WebhookListResponse, http_res, validate=False
|
|
)
|
|
|
|
raise errors.GenAiDefaultError("Unexpected response received", http_res)
|
|
|
|
_speakeasy_hook_ctx = HookContext(
|
|
config=self.sdk_configuration,
|
|
base_url=base_url or "",
|
|
operation_id="ListWebhooks",
|
|
oauth2_scopes=None,
|
|
security_source=get_security_from_env(
|
|
self.sdk_configuration.security, types.Security
|
|
),
|
|
response=ResponseContext(mode=_speakeasy_response_mode, execution="async"),
|
|
)
|
|
http_res = await self.do_request_async(
|
|
hook_ctx=_speakeasy_hook_ctx,
|
|
request=req,
|
|
is_error_status_code=lambda c: utils.match_status_codes(["4XX", "5XX"], c),
|
|
stream=_speakeasy_response_mode == "streaming",
|
|
retry_config=retry_config,
|
|
)
|
|
if _speakeasy_response_mode != "parsed":
|
|
_speakeasy_response_cls = (
|
|
response_helpers.AsyncStreamedAPIResponse
|
|
if _speakeasy_response_mode == "streaming"
|
|
else response_helpers.AsyncAPIResponse
|
|
)
|
|
return cast(
|
|
Any,
|
|
_speakeasy_response_cls(
|
|
raw=http_res,
|
|
parser=_speakeasy_parse_response,
|
|
mode="buffered",
|
|
client_ref=self,
|
|
hook_ctx=AfterParseErrorContext(_speakeasy_hook_ctx),
|
|
hooks=self.sdk_configuration.__dict__.get("_hooks"),
|
|
async_hooks=self.sdk_configuration.__dict__.get("_async_hooks"),
|
|
),
|
|
)
|
|
try:
|
|
return await _speakeasy_parse_response(http_res)
|
|
except Exception as parse_exc_:
|
|
await response_helpers.raise_parse_error_async(
|
|
self.sdk_configuration.__dict__.get("_async_hooks"),
|
|
self.sdk_configuration.__dict__.get("_hooks"),
|
|
AfterParseErrorContext(_speakeasy_hook_ctx),
|
|
http_res,
|
|
parse_exc_,
|
|
)
|
|
|
|
async def get(
|
|
self,
|
|
id: str,
|
|
*,
|
|
api_version: Optional[str] = None,
|
|
extra_headers: Optional[Mapping[str, str]] = None,
|
|
extra_query: Optional[Mapping[str, Any]] = None,
|
|
timeout: Optional[Union[float, httpx.Timeout]] = None,
|
|
) -> webhooks.Webhook:
|
|
r"""Gets a specific Webhook.
|
|
|
|
:param id: Required. The ID of the webhook to retrieve.
|
|
:param api_version: Which version of the API to use.
|
|
:param extra_headers: Additional headers to set or replace on requests.
|
|
:param extra_query: Additional query parameters to append to requests.
|
|
:param timeout: Override the default request timeout configuration for this method in seconds
|
|
"""
|
|
base_url = None
|
|
url_variables = None
|
|
retries: OptionalNullable[utils.RetryConfig] = UNSET
|
|
server_url = None
|
|
http_headers = extra_headers
|
|
timeout_ms = self._coerce_timeout_ms(timeout)
|
|
if timeout_ms is None:
|
|
timeout_ms = self.sdk_configuration.timeout_ms
|
|
|
|
if server_url is not None:
|
|
base_url = server_url
|
|
else:
|
|
base_url = self._get_url(base_url, url_variables)
|
|
|
|
request = models.GetWebhookRequest(
|
|
api_version=api_version,
|
|
id=id,
|
|
)
|
|
|
|
_speakeasy_response_mode, http_headers = response_helpers.consume_response_mode(
|
|
http_headers
|
|
)
|
|
req = self._build_request_async(
|
|
method="GET",
|
|
path="/{api_version}/webhooks/{id}",
|
|
base_url=base_url,
|
|
url_variables=url_variables,
|
|
request=request,
|
|
request_body_required=False,
|
|
request_has_path_params=True,
|
|
request_has_query_params=True,
|
|
user_agent_header="user-agent",
|
|
accept_header_value="application/json",
|
|
http_headers=http_headers,
|
|
extra_query_params=extra_query,
|
|
_globals=models.GetWebhookGlobals(
|
|
api_version=self.sdk_configuration.globals.api_version,
|
|
),
|
|
security=self.sdk_configuration.security,
|
|
allow_empty_value=None,
|
|
timeout_ms=timeout_ms,
|
|
)
|
|
|
|
if retries == UNSET:
|
|
if self.sdk_configuration.retry_config is not UNSET:
|
|
retries = self.sdk_configuration.retry_config
|
|
else:
|
|
retries = utils.RetryConfig(
|
|
"attempt-count-backoff",
|
|
utils.BackoffStrategy(500, 8000, 2, 30000),
|
|
True,
|
|
max_retries=4,
|
|
)
|
|
|
|
retry_config = None
|
|
if isinstance(retries, utils.RetryConfig):
|
|
retry_config = (retries, ["408", "409", "429", "5XX"])
|
|
|
|
async def _speakeasy_parse_response(http_res):
|
|
if utils.match_response(http_res, "4XX", "*"):
|
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
raise errors.GenAiDefaultError(
|
|
"API error occurred", http_res, http_res_text
|
|
)
|
|
if utils.match_response(http_res, "5XX", "*"):
|
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
raise errors.GenAiDefaultError(
|
|
"API error occurred", http_res, http_res_text
|
|
)
|
|
if utils.match_response(http_res, "default", "application/json"):
|
|
return unmarshal_json_response(
|
|
webhooks.Webhook, http_res, validate=False
|
|
)
|
|
|
|
raise errors.GenAiDefaultError("Unexpected response received", http_res)
|
|
|
|
_speakeasy_hook_ctx = HookContext(
|
|
config=self.sdk_configuration,
|
|
base_url=base_url or "",
|
|
operation_id="GetWebhook",
|
|
oauth2_scopes=None,
|
|
security_source=get_security_from_env(
|
|
self.sdk_configuration.security, types.Security
|
|
),
|
|
response=ResponseContext(mode=_speakeasy_response_mode, execution="async"),
|
|
)
|
|
http_res = await self.do_request_async(
|
|
hook_ctx=_speakeasy_hook_ctx,
|
|
request=req,
|
|
is_error_status_code=lambda c: utils.match_status_codes(["4XX", "5XX"], c),
|
|
stream=_speakeasy_response_mode == "streaming",
|
|
retry_config=retry_config,
|
|
)
|
|
if _speakeasy_response_mode != "parsed":
|
|
_speakeasy_response_cls = (
|
|
response_helpers.AsyncStreamedAPIResponse
|
|
if _speakeasy_response_mode == "streaming"
|
|
else response_helpers.AsyncAPIResponse
|
|
)
|
|
return cast(
|
|
Any,
|
|
_speakeasy_response_cls(
|
|
raw=http_res,
|
|
parser=_speakeasy_parse_response,
|
|
mode="buffered",
|
|
client_ref=self,
|
|
hook_ctx=AfterParseErrorContext(_speakeasy_hook_ctx),
|
|
hooks=self.sdk_configuration.__dict__.get("_hooks"),
|
|
async_hooks=self.sdk_configuration.__dict__.get("_async_hooks"),
|
|
),
|
|
)
|
|
try:
|
|
return await _speakeasy_parse_response(http_res)
|
|
except Exception as parse_exc_:
|
|
await response_helpers.raise_parse_error_async(
|
|
self.sdk_configuration.__dict__.get("_async_hooks"),
|
|
self.sdk_configuration.__dict__.get("_hooks"),
|
|
AfterParseErrorContext(_speakeasy_hook_ctx),
|
|
http_res,
|
|
parse_exc_,
|
|
)
|
|
|
|
async def update(
|
|
self,
|
|
id: str,
|
|
*,
|
|
api_version: Optional[str] = None,
|
|
update_mask: Optional[str] = None,
|
|
name: Optional[str] = None,
|
|
uri: Optional[str] = None,
|
|
subscribed_events: Optional[
|
|
Iterable[webhooks_webhookupdate.WebhookUpdateSubscribedEvent]
|
|
] = None,
|
|
state: Optional[webhooks_webhookupdate.WebhookUpdateState] = None,
|
|
extra_headers: Optional[Mapping[str, str]] = None,
|
|
extra_query: Optional[Mapping[str, Any]] = None,
|
|
extra_body: Optional[Mapping[str, Any]] = None,
|
|
timeout: Optional[Union[float, httpx.Timeout]] = None,
|
|
) -> webhooks.Webhook:
|
|
r"""Updates an existing Webhook.
|
|
|
|
:param id: Required. The ID of the webhook to update.
|
|
:param api_version: Which version of the API to use.
|
|
:param update_mask: Optional. The list of fields to update.
|
|
:param name: Optional. The user-provided name of the webhook.
|
|
:param uri: Optional. The URI to which webhook events will be sent.
|
|
:param subscribed_events: Optional. The events that the webhook is subscribed to.
|
|
Available events:
|
|
- batch.succeeded
|
|
- batch.expired
|
|
- batch.failed
|
|
- interaction.requires_action
|
|
- interaction.completed
|
|
- interaction.failed
|
|
- video.generated
|
|
:param state: Optional. The state of the webhook.
|
|
:param extra_headers: Additional headers to set or replace on requests.
|
|
:param extra_query: Additional query parameters to append to requests.
|
|
:param extra_body: Additional JSON object fields to merge into request bodies.
|
|
:param timeout: Override the default request timeout configuration for this method in seconds
|
|
"""
|
|
base_url = None
|
|
url_variables = None
|
|
retries: OptionalNullable[utils.RetryConfig] = UNSET
|
|
server_url = None
|
|
http_headers = extra_headers
|
|
timeout_ms = self._coerce_timeout_ms(timeout)
|
|
if timeout_ms is None:
|
|
timeout_ms = self.sdk_configuration.timeout_ms
|
|
|
|
if server_url is not None:
|
|
base_url = server_url
|
|
else:
|
|
base_url = self._get_url(base_url, url_variables)
|
|
|
|
request = models.UpdateWebhookRequest(
|
|
api_version=api_version,
|
|
id=id,
|
|
update_mask=update_mask,
|
|
body=webhooks.WebhookUpdate(
|
|
name=name,
|
|
uri=uri,
|
|
subscribed_events=utils.unmarshal(
|
|
subscribed_events,
|
|
Optional[List[webhooks.WebhookUpdateSubscribedEvent]],
|
|
),
|
|
state=state,
|
|
),
|
|
)
|
|
|
|
_speakeasy_response_mode, http_headers = response_helpers.consume_response_mode(
|
|
http_headers
|
|
)
|
|
req = self._build_request_async(
|
|
method="PATCH",
|
|
path="/{api_version}/webhooks/{id}",
|
|
base_url=base_url,
|
|
url_variables=url_variables,
|
|
request=request,
|
|
request_body_required=False,
|
|
request_has_path_params=True,
|
|
request_has_query_params=True,
|
|
user_agent_header="user-agent",
|
|
accept_header_value="application/json",
|
|
http_headers=http_headers,
|
|
extra_query_params=extra_query,
|
|
_globals=models.UpdateWebhookGlobals(
|
|
api_version=self.sdk_configuration.globals.api_version,
|
|
),
|
|
security=self.sdk_configuration.security,
|
|
get_serialized_body=lambda: utils.serialize_request_body(
|
|
request.body if request is not None else None,
|
|
False,
|
|
True,
|
|
"json",
|
|
Optional[webhooks.WebhookUpdate],
|
|
extra_body=extra_body,
|
|
),
|
|
allow_empty_value=None,
|
|
timeout_ms=timeout_ms,
|
|
)
|
|
|
|
if retries == UNSET:
|
|
if self.sdk_configuration.retry_config is not UNSET:
|
|
retries = self.sdk_configuration.retry_config
|
|
else:
|
|
retries = utils.RetryConfig(
|
|
"attempt-count-backoff",
|
|
utils.BackoffStrategy(500, 8000, 2, 30000),
|
|
True,
|
|
max_retries=4,
|
|
)
|
|
|
|
retry_config = None
|
|
if isinstance(retries, utils.RetryConfig):
|
|
retry_config = (retries, ["408", "409", "429", "5XX"])
|
|
|
|
async def _speakeasy_parse_response(http_res):
|
|
if utils.match_response(http_res, "4XX", "*"):
|
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
raise errors.GenAiDefaultError(
|
|
"API error occurred", http_res, http_res_text
|
|
)
|
|
if utils.match_response(http_res, "5XX", "*"):
|
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
raise errors.GenAiDefaultError(
|
|
"API error occurred", http_res, http_res_text
|
|
)
|
|
if utils.match_response(http_res, "default", "application/json"):
|
|
return unmarshal_json_response(
|
|
webhooks.Webhook, http_res, validate=False
|
|
)
|
|
|
|
raise errors.GenAiDefaultError("Unexpected response received", http_res)
|
|
|
|
_speakeasy_hook_ctx = HookContext(
|
|
config=self.sdk_configuration,
|
|
base_url=base_url or "",
|
|
operation_id="UpdateWebhook",
|
|
oauth2_scopes=None,
|
|
security_source=get_security_from_env(
|
|
self.sdk_configuration.security, types.Security
|
|
),
|
|
response=ResponseContext(mode=_speakeasy_response_mode, execution="async"),
|
|
)
|
|
http_res = await self.do_request_async(
|
|
hook_ctx=_speakeasy_hook_ctx,
|
|
request=req,
|
|
is_error_status_code=lambda c: utils.match_status_codes(["4XX", "5XX"], c),
|
|
stream=_speakeasy_response_mode == "streaming",
|
|
retry_config=retry_config,
|
|
)
|
|
if _speakeasy_response_mode != "parsed":
|
|
_speakeasy_response_cls = (
|
|
response_helpers.AsyncStreamedAPIResponse
|
|
if _speakeasy_response_mode == "streaming"
|
|
else response_helpers.AsyncAPIResponse
|
|
)
|
|
return cast(
|
|
Any,
|
|
_speakeasy_response_cls(
|
|
raw=http_res,
|
|
parser=_speakeasy_parse_response,
|
|
mode="buffered",
|
|
client_ref=self,
|
|
hook_ctx=AfterParseErrorContext(_speakeasy_hook_ctx),
|
|
hooks=self.sdk_configuration.__dict__.get("_hooks"),
|
|
async_hooks=self.sdk_configuration.__dict__.get("_async_hooks"),
|
|
),
|
|
)
|
|
try:
|
|
return await _speakeasy_parse_response(http_res)
|
|
except Exception as parse_exc_:
|
|
await response_helpers.raise_parse_error_async(
|
|
self.sdk_configuration.__dict__.get("_async_hooks"),
|
|
self.sdk_configuration.__dict__.get("_hooks"),
|
|
AfterParseErrorContext(_speakeasy_hook_ctx),
|
|
http_res,
|
|
parse_exc_,
|
|
)
|
|
|
|
async def delete(
|
|
self,
|
|
id: str,
|
|
*,
|
|
api_version: Optional[str] = None,
|
|
extra_headers: Optional[Mapping[str, str]] = None,
|
|
extra_query: Optional[Mapping[str, Any]] = None,
|
|
timeout: Optional[Union[float, httpx.Timeout]] = None,
|
|
) -> interactions.Empty:
|
|
r"""Deletes a Webhook.
|
|
|
|
:param id: Required. The ID of the webhook to delete.
|
|
Format: `{webhook_id}`
|
|
:param api_version: Which version of the API to use.
|
|
:param extra_headers: Additional headers to set or replace on requests.
|
|
:param extra_query: Additional query parameters to append to requests.
|
|
:param timeout: Override the default request timeout configuration for this method in seconds
|
|
"""
|
|
base_url = None
|
|
url_variables = None
|
|
retries: OptionalNullable[utils.RetryConfig] = UNSET
|
|
server_url = None
|
|
http_headers = extra_headers
|
|
timeout_ms = self._coerce_timeout_ms(timeout)
|
|
if timeout_ms is None:
|
|
timeout_ms = self.sdk_configuration.timeout_ms
|
|
|
|
if server_url is not None:
|
|
base_url = server_url
|
|
else:
|
|
base_url = self._get_url(base_url, url_variables)
|
|
|
|
request = models.DeleteWebhookRequest(
|
|
api_version=api_version,
|
|
id=id,
|
|
)
|
|
|
|
_speakeasy_response_mode, http_headers = response_helpers.consume_response_mode(
|
|
http_headers
|
|
)
|
|
req = self._build_request_async(
|
|
method="DELETE",
|
|
path="/{api_version}/webhooks/{id}",
|
|
base_url=base_url,
|
|
url_variables=url_variables,
|
|
request=request,
|
|
request_body_required=False,
|
|
request_has_path_params=True,
|
|
request_has_query_params=True,
|
|
user_agent_header="user-agent",
|
|
accept_header_value="application/json",
|
|
http_headers=http_headers,
|
|
extra_query_params=extra_query,
|
|
_globals=models.DeleteWebhookGlobals(
|
|
api_version=self.sdk_configuration.globals.api_version,
|
|
),
|
|
security=self.sdk_configuration.security,
|
|
allow_empty_value=None,
|
|
timeout_ms=timeout_ms,
|
|
)
|
|
|
|
if retries == UNSET:
|
|
if self.sdk_configuration.retry_config is not UNSET:
|
|
retries = self.sdk_configuration.retry_config
|
|
else:
|
|
retries = utils.RetryConfig(
|
|
"attempt-count-backoff",
|
|
utils.BackoffStrategy(500, 8000, 2, 30000),
|
|
True,
|
|
max_retries=4,
|
|
)
|
|
|
|
retry_config = None
|
|
if isinstance(retries, utils.RetryConfig):
|
|
retry_config = (retries, ["408", "409", "429", "5XX"])
|
|
|
|
async def _speakeasy_parse_response(http_res):
|
|
if utils.match_response(http_res, "4XX", "*"):
|
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
raise errors.GenAiDefaultError(
|
|
"API error occurred", http_res, http_res_text
|
|
)
|
|
if utils.match_response(http_res, "5XX", "*"):
|
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
raise errors.GenAiDefaultError(
|
|
"API error occurred", http_res, http_res_text
|
|
)
|
|
if utils.match_response(http_res, "default", "application/json"):
|
|
return unmarshal_json_response(
|
|
interactions.Empty, http_res, validate=False
|
|
)
|
|
|
|
raise errors.GenAiDefaultError("Unexpected response received", http_res)
|
|
|
|
_speakeasy_hook_ctx = HookContext(
|
|
config=self.sdk_configuration,
|
|
base_url=base_url or "",
|
|
operation_id="DeleteWebhook",
|
|
oauth2_scopes=None,
|
|
security_source=get_security_from_env(
|
|
self.sdk_configuration.security, types.Security
|
|
),
|
|
response=ResponseContext(mode=_speakeasy_response_mode, execution="async"),
|
|
)
|
|
http_res = await self.do_request_async(
|
|
hook_ctx=_speakeasy_hook_ctx,
|
|
request=req,
|
|
is_error_status_code=lambda c: utils.match_status_codes(["4XX", "5XX"], c),
|
|
stream=_speakeasy_response_mode == "streaming",
|
|
retry_config=retry_config,
|
|
)
|
|
if _speakeasy_response_mode != "parsed":
|
|
_speakeasy_response_cls = (
|
|
response_helpers.AsyncStreamedAPIResponse
|
|
if _speakeasy_response_mode == "streaming"
|
|
else response_helpers.AsyncAPIResponse
|
|
)
|
|
return cast(
|
|
Any,
|
|
_speakeasy_response_cls(
|
|
raw=http_res,
|
|
parser=_speakeasy_parse_response,
|
|
mode="buffered",
|
|
client_ref=self,
|
|
hook_ctx=AfterParseErrorContext(_speakeasy_hook_ctx),
|
|
hooks=self.sdk_configuration.__dict__.get("_hooks"),
|
|
async_hooks=self.sdk_configuration.__dict__.get("_async_hooks"),
|
|
),
|
|
)
|
|
try:
|
|
return await _speakeasy_parse_response(http_res)
|
|
except Exception as parse_exc_:
|
|
await response_helpers.raise_parse_error_async(
|
|
self.sdk_configuration.__dict__.get("_async_hooks"),
|
|
self.sdk_configuration.__dict__.get("_hooks"),
|
|
AfterParseErrorContext(_speakeasy_hook_ctx),
|
|
http_res,
|
|
parse_exc_,
|
|
)
|
|
|
|
async def rotate_signing_secret(
|
|
self,
|
|
id: str,
|
|
*,
|
|
api_version: Optional[str] = None,
|
|
revocation_behavior: Optional[
|
|
webhooks_rotatesigningsecretrequest.RevocationBehavior
|
|
] = None,
|
|
extra_headers: Optional[Mapping[str, str]] = None,
|
|
extra_query: Optional[Mapping[str, Any]] = None,
|
|
extra_body: Optional[Mapping[str, Any]] = None,
|
|
timeout: Optional[Union[float, httpx.Timeout]] = None,
|
|
) -> webhooks.WebhookRotateSigningSecretResponse:
|
|
r"""Generates a new signing secret for a Webhook.
|
|
|
|
:param id: Required. The ID of the webhook for which to generate a signing secret.
|
|
Format: `{webhook_id}`
|
|
:param api_version: Which version of the API to use.
|
|
:param revocation_behavior: Optional. The revocation behavior for previous signing secrets.
|
|
:param extra_headers: Additional headers to set or replace on requests.
|
|
:param extra_query: Additional query parameters to append to requests.
|
|
:param extra_body: Additional JSON object fields to merge into request bodies.
|
|
:param timeout: Override the default request timeout configuration for this method in seconds
|
|
"""
|
|
base_url = None
|
|
url_variables = None
|
|
retries: OptionalNullable[utils.RetryConfig] = UNSET
|
|
server_url = None
|
|
http_headers = extra_headers
|
|
timeout_ms = self._coerce_timeout_ms(timeout)
|
|
if timeout_ms is None:
|
|
timeout_ms = self.sdk_configuration.timeout_ms
|
|
|
|
if server_url is not None:
|
|
base_url = server_url
|
|
else:
|
|
base_url = self._get_url(base_url, url_variables)
|
|
|
|
request = models.RotateSigningSecretRequest(
|
|
api_version=api_version,
|
|
id=id,
|
|
body=webhooks.RotateSigningSecretRequest(
|
|
revocation_behavior=revocation_behavior,
|
|
),
|
|
)
|
|
|
|
_speakeasy_response_mode, http_headers = response_helpers.consume_response_mode(
|
|
http_headers
|
|
)
|
|
req = self._build_request_async(
|
|
method="POST",
|
|
path="/{api_version}/webhooks/{id}:rotateSigningSecret",
|
|
base_url=base_url,
|
|
url_variables=url_variables,
|
|
request=request,
|
|
request_body_required=False,
|
|
request_has_path_params=True,
|
|
request_has_query_params=True,
|
|
user_agent_header="user-agent",
|
|
accept_header_value="application/json",
|
|
http_headers=http_headers,
|
|
extra_query_params=extra_query,
|
|
_globals=models.RotateSigningSecretGlobals(
|
|
api_version=self.sdk_configuration.globals.api_version,
|
|
),
|
|
security=self.sdk_configuration.security,
|
|
get_serialized_body=lambda: utils.serialize_request_body(
|
|
request.body if request is not None else None,
|
|
False,
|
|
True,
|
|
"json",
|
|
Optional[webhooks.RotateSigningSecretRequest],
|
|
extra_body=extra_body,
|
|
),
|
|
allow_empty_value=None,
|
|
timeout_ms=timeout_ms,
|
|
)
|
|
|
|
if retries == UNSET:
|
|
if self.sdk_configuration.retry_config is not UNSET:
|
|
retries = self.sdk_configuration.retry_config
|
|
else:
|
|
retries = utils.RetryConfig(
|
|
"attempt-count-backoff",
|
|
utils.BackoffStrategy(500, 8000, 2, 30000),
|
|
True,
|
|
max_retries=4,
|
|
)
|
|
|
|
retry_config = None
|
|
if isinstance(retries, utils.RetryConfig):
|
|
retry_config = (retries, ["408", "409", "429", "5XX"])
|
|
|
|
async def _speakeasy_parse_response(http_res):
|
|
if utils.match_response(http_res, "4XX", "*"):
|
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
raise errors.GenAiDefaultError(
|
|
"API error occurred", http_res, http_res_text
|
|
)
|
|
if utils.match_response(http_res, "5XX", "*"):
|
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
raise errors.GenAiDefaultError(
|
|
"API error occurred", http_res, http_res_text
|
|
)
|
|
if utils.match_response(http_res, "default", "application/json"):
|
|
return unmarshal_json_response(
|
|
webhooks.WebhookRotateSigningSecretResponse,
|
|
http_res,
|
|
validate=False,
|
|
)
|
|
|
|
raise errors.GenAiDefaultError("Unexpected response received", http_res)
|
|
|
|
_speakeasy_hook_ctx = HookContext(
|
|
config=self.sdk_configuration,
|
|
base_url=base_url or "",
|
|
operation_id="RotateSigningSecret",
|
|
oauth2_scopes=None,
|
|
security_source=get_security_from_env(
|
|
self.sdk_configuration.security, types.Security
|
|
),
|
|
response=ResponseContext(mode=_speakeasy_response_mode, execution="async"),
|
|
)
|
|
http_res = await self.do_request_async(
|
|
hook_ctx=_speakeasy_hook_ctx,
|
|
request=req,
|
|
is_error_status_code=lambda c: utils.match_status_codes(["4XX", "5XX"], c),
|
|
stream=_speakeasy_response_mode == "streaming",
|
|
retry_config=retry_config,
|
|
)
|
|
if _speakeasy_response_mode != "parsed":
|
|
_speakeasy_response_cls = (
|
|
response_helpers.AsyncStreamedAPIResponse
|
|
if _speakeasy_response_mode == "streaming"
|
|
else response_helpers.AsyncAPIResponse
|
|
)
|
|
return cast(
|
|
Any,
|
|
_speakeasy_response_cls(
|
|
raw=http_res,
|
|
parser=_speakeasy_parse_response,
|
|
mode="buffered",
|
|
client_ref=self,
|
|
hook_ctx=AfterParseErrorContext(_speakeasy_hook_ctx),
|
|
hooks=self.sdk_configuration.__dict__.get("_hooks"),
|
|
async_hooks=self.sdk_configuration.__dict__.get("_async_hooks"),
|
|
),
|
|
)
|
|
try:
|
|
return await _speakeasy_parse_response(http_res)
|
|
except Exception as parse_exc_:
|
|
await response_helpers.raise_parse_error_async(
|
|
self.sdk_configuration.__dict__.get("_async_hooks"),
|
|
self.sdk_configuration.__dict__.get("_hooks"),
|
|
AfterParseErrorContext(_speakeasy_hook_ctx),
|
|
http_res,
|
|
parse_exc_,
|
|
)
|
|
|
|
async def ping(
|
|
self,
|
|
id: str,
|
|
*,
|
|
api_version: Optional[str] = None,
|
|
body: Optional[
|
|
Union[
|
|
webhooks_pingwebhookrequest.PingWebhookRequest,
|
|
webhooks_pingwebhookrequest.PingWebhookRequestParam,
|
|
]
|
|
] = None,
|
|
extra_headers: Optional[Mapping[str, str]] = None,
|
|
extra_query: Optional[Mapping[str, Any]] = None,
|
|
extra_body: Optional[Mapping[str, Any]] = None,
|
|
timeout: Optional[Union[float, httpx.Timeout]] = None,
|
|
) -> webhooks.WebhookPingResponse:
|
|
r"""Sends a ping event to a Webhook.
|
|
|
|
:param id: Required. The ID of the webhook to ping.
|
|
Format: `{webhook_id}`
|
|
:param api_version: Which version of the API to use.
|
|
:param body: The request body.
|
|
:param extra_headers: Additional headers to set or replace on requests.
|
|
:param extra_query: Additional query parameters to append to requests.
|
|
:param extra_body: Additional JSON object fields to merge into request bodies.
|
|
:param timeout: Override the default request timeout configuration for this method in seconds
|
|
"""
|
|
base_url = None
|
|
url_variables = None
|
|
retries: OptionalNullable[utils.RetryConfig] = UNSET
|
|
server_url = None
|
|
http_headers = extra_headers
|
|
timeout_ms = self._coerce_timeout_ms(timeout)
|
|
if timeout_ms is None:
|
|
timeout_ms = self.sdk_configuration.timeout_ms
|
|
|
|
if server_url is not None:
|
|
base_url = server_url
|
|
else:
|
|
base_url = self._get_url(base_url, url_variables)
|
|
|
|
request = models.PingWebhookRequest(
|
|
api_version=api_version,
|
|
id=id,
|
|
body=utils.get_pydantic_model(body, Optional[webhooks.PingWebhookRequest]),
|
|
)
|
|
|
|
_speakeasy_response_mode, http_headers = response_helpers.consume_response_mode(
|
|
http_headers
|
|
)
|
|
req = self._build_request_async(
|
|
method="POST",
|
|
path="/{api_version}/webhooks/{id}:ping",
|
|
base_url=base_url,
|
|
url_variables=url_variables,
|
|
request=request,
|
|
request_body_required=False,
|
|
request_has_path_params=True,
|
|
request_has_query_params=True,
|
|
user_agent_header="user-agent",
|
|
accept_header_value="application/json",
|
|
http_headers=http_headers,
|
|
extra_query_params=extra_query,
|
|
_globals=models.PingWebhookGlobals(
|
|
api_version=self.sdk_configuration.globals.api_version,
|
|
),
|
|
security=self.sdk_configuration.security,
|
|
get_serialized_body=lambda: utils.serialize_request_body(
|
|
request.body if request is not None else None,
|
|
False,
|
|
True,
|
|
"json",
|
|
Optional[webhooks.PingWebhookRequest],
|
|
extra_body=extra_body,
|
|
),
|
|
allow_empty_value=None,
|
|
timeout_ms=timeout_ms,
|
|
)
|
|
|
|
if retries == UNSET:
|
|
if self.sdk_configuration.retry_config is not UNSET:
|
|
retries = self.sdk_configuration.retry_config
|
|
else:
|
|
retries = utils.RetryConfig(
|
|
"attempt-count-backoff",
|
|
utils.BackoffStrategy(500, 8000, 2, 30000),
|
|
True,
|
|
max_retries=4,
|
|
)
|
|
|
|
retry_config = None
|
|
if isinstance(retries, utils.RetryConfig):
|
|
retry_config = (retries, ["408", "409", "429", "5XX"])
|
|
|
|
async def _speakeasy_parse_response(http_res):
|
|
if utils.match_response(http_res, "4XX", "*"):
|
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
raise errors.GenAiDefaultError(
|
|
"API error occurred", http_res, http_res_text
|
|
)
|
|
if utils.match_response(http_res, "5XX", "*"):
|
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
raise errors.GenAiDefaultError(
|
|
"API error occurred", http_res, http_res_text
|
|
)
|
|
if utils.match_response(http_res, "default", "application/json"):
|
|
return unmarshal_json_response(
|
|
webhooks.WebhookPingResponse, http_res, validate=False
|
|
)
|
|
|
|
raise errors.GenAiDefaultError("Unexpected response received", http_res)
|
|
|
|
_speakeasy_hook_ctx = HookContext(
|
|
config=self.sdk_configuration,
|
|
base_url=base_url or "",
|
|
operation_id="PingWebhook",
|
|
oauth2_scopes=None,
|
|
security_source=get_security_from_env(
|
|
self.sdk_configuration.security, types.Security
|
|
),
|
|
response=ResponseContext(mode=_speakeasy_response_mode, execution="async"),
|
|
)
|
|
http_res = await self.do_request_async(
|
|
hook_ctx=_speakeasy_hook_ctx,
|
|
request=req,
|
|
is_error_status_code=lambda c: utils.match_status_codes(["4XX", "5XX"], c),
|
|
stream=_speakeasy_response_mode == "streaming",
|
|
retry_config=retry_config,
|
|
)
|
|
if _speakeasy_response_mode != "parsed":
|
|
_speakeasy_response_cls = (
|
|
response_helpers.AsyncStreamedAPIResponse
|
|
if _speakeasy_response_mode == "streaming"
|
|
else response_helpers.AsyncAPIResponse
|
|
)
|
|
return cast(
|
|
Any,
|
|
_speakeasy_response_cls(
|
|
raw=http_res,
|
|
parser=_speakeasy_parse_response,
|
|
mode="buffered",
|
|
client_ref=self,
|
|
hook_ctx=AfterParseErrorContext(_speakeasy_hook_ctx),
|
|
hooks=self.sdk_configuration.__dict__.get("_hooks"),
|
|
async_hooks=self.sdk_configuration.__dict__.get("_async_hooks"),
|
|
),
|
|
)
|
|
try:
|
|
return await _speakeasy_parse_response(http_res)
|
|
except Exception as parse_exc_:
|
|
await response_helpers.raise_parse_error_async(
|
|
self.sdk_configuration.__dict__.get("_async_hooks"),
|
|
self.sdk_configuration.__dict__.get("_hooks"),
|
|
AfterParseErrorContext(_speakeasy_hook_ctx),
|
|
http_res,
|
|
parse_exc_,
|
|
)
|
|
|
|
|
|
class AsyncWebhooksWithRawResponse:
|
|
def __init__(self, sdk: AsyncWebhooks) -> None:
|
|
self._sdk = sdk
|
|
self.create = response_helpers.async_to_raw_response_wrapper(
|
|
sdk.create, "extra_headers"
|
|
)
|
|
self.list = response_helpers.async_to_raw_response_wrapper(
|
|
sdk.list, "extra_headers"
|
|
)
|
|
self.get = response_helpers.async_to_raw_response_wrapper(
|
|
sdk.get, "extra_headers"
|
|
)
|
|
self.update = response_helpers.async_to_raw_response_wrapper(
|
|
sdk.update, "extra_headers"
|
|
)
|
|
self.delete = response_helpers.async_to_raw_response_wrapper(
|
|
sdk.delete, "extra_headers"
|
|
)
|
|
self.rotate_signing_secret = response_helpers.async_to_raw_response_wrapper(
|
|
sdk.rotate_signing_secret, "extra_headers"
|
|
)
|
|
self.ping = response_helpers.async_to_raw_response_wrapper(
|
|
sdk.ping, "extra_headers"
|
|
)
|
|
|
|
|
|
class AsyncWebhooksWithStreamingResponse:
|
|
def __init__(self, sdk: AsyncWebhooks) -> None:
|
|
self._sdk = sdk
|
|
self.create = response_helpers.async_to_streamed_response_wrapper(
|
|
sdk.create, "extra_headers"
|
|
)
|
|
self.list = response_helpers.async_to_streamed_response_wrapper(
|
|
sdk.list, "extra_headers"
|
|
)
|
|
self.get = response_helpers.async_to_streamed_response_wrapper(
|
|
sdk.get, "extra_headers"
|
|
)
|
|
self.update = response_helpers.async_to_streamed_response_wrapper(
|
|
sdk.update, "extra_headers"
|
|
)
|
|
self.delete = response_helpers.async_to_streamed_response_wrapper(
|
|
sdk.delete, "extra_headers"
|
|
)
|
|
self.rotate_signing_secret = (
|
|
response_helpers.async_to_streamed_response_wrapper(
|
|
sdk.rotate_signing_secret, "extra_headers"
|
|
)
|
|
)
|
|
self.ping = response_helpers.async_to_streamed_response_wrapper(
|
|
sdk.ping, "extra_headers"
|
|
)
|