diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ee2a849f..e150fdf4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,12 +1,14 @@ name: CI on: push: - branches-ignore: - - 'generated' - - 'codegen/**' - - 'integrated/**' - - 'stl-preview-head/**' - - 'stl-preview-base/**' + branches: + - '**' + - '!integrated/**' + - '!stl-preview-head/**' + - '!stl-preview-base/**' + - '!generated' + - '!codegen/**' + - 'codegen/stl/**' pull_request: branches-ignore: - 'stl-preview-head/**' @@ -17,7 +19,7 @@ jobs: timeout-minutes: 10 name: lint runs-on: ${{ github.repository == 'stainless-sdks/courier-python' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }} - if: github.event_name == 'push' || github.event.pull_request.head.repo.fork + if: (github.event_name == 'push' || github.event.pull_request.head.repo.fork) && (github.event_name != 'push' || github.event.head_commit.message != 'codegen metadata') steps: - uses: actions/checkout@v6 @@ -36,7 +38,7 @@ jobs: run: ./scripts/lint build: - if: github.event_name == 'push' || github.event.pull_request.head.repo.fork + if: (github.event_name == 'push' || github.event.pull_request.head.repo.fork) && (github.event_name != 'push' || github.event.head_commit.message != 'codegen metadata') timeout-minutes: 10 name: build permissions: diff --git a/.gitignore b/.gitignore index 95ceb189..3824f4c4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .prism.log +.stdy.log _dev __pycache__ diff --git a/.release-please-manifest.json b/.release-please-manifest.json index a75e9e71..cef64269 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "7.9.0" + ".": "7.10.0" } \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index 75c12180..51d97c36 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ -configured_endpoints: 83 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/courier%2Fcourier-19330fca8fa9bbae835ec9d9f83b37b3df364d9b462090b9623bfc9b6eae99c2.yml -openapi_spec_hash: 0bc6889464c9ac2542b4837f569c1837 -config_hash: 1ae49ed522c8423378d9463cdd0fb880 +configured_endpoints: 88 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/courier%2Fcourier-288ef53fff4d0cc92b3ac14bc1e03dc41c112b55634713adb75158b1c97c4576.yml +openapi_spec_hash: 5c4fed9a1639a6cdfcb5adaf666c9ed6 +config_hash: a0ecf9dfbd637db38508b3de2b81aeeb diff --git a/CHANGELOG.md b/CHANGELOG.md index 67719e19..138987ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,27 @@ # Changelog +## 7.10.0 (2026-03-25) + +Full Changelog: [v7.9.0...v7.10.0](https://github.com/trycourier/courier-python/compare/v7.9.0...v7.10.0) + +### Features + +* **api:** add create/retrieve/archive/publish/replace, event_id param to notifications ([3cd5477](https://github.com/trycourier/courier-python/commit/3cd547737982b5d845780b64e0526321b0b54a85)) + + +### Bug Fixes + +* **deps:** bump minimum typing-extensions version ([19dae33](https://github.com/trycourier/courier-python/commit/19dae33c3428ebd7e5c1bf27b51d97c491862f62)) +* **pydantic:** do not pass `by_alias` unless set ([10db070](https://github.com/trycourier/courier-python/commit/10db0705d5f517511df5c649b6183f12409fa977)) +* sanitize endpoint path params ([3565a88](https://github.com/trycourier/courier-python/commit/3565a88b9340b52f36c4a73d377133cfcd2bf6fa)) + + +### Chores + +* **ci:** skip lint on metadata-only changes ([4d21b50](https://github.com/trycourier/courier-python/commit/4d21b50d99ef1424e04abdd7427e3818d857ed03)) +* **internal:** tweak CI branches ([75425fb](https://github.com/trycourier/courier-python/commit/75425fbbcab9362d2e2f55dd91f0f954e90b812e)) +* **internal:** update gitignore ([622db6f](https://github.com/trycourier/courier-python/commit/622db6f22ee15af2a08269ae1c792e592c5c9a50)) + ## 7.9.0 (2026-03-12) Full Changelog: [v7.8.0...v7.9.0](https://github.com/trycourier/courier-python/compare/v7.8.0...v7.9.0) diff --git a/api.md b/api.md index 0a640000..bcfe775b 100644 --- a/api.md +++ b/api.md @@ -304,12 +304,28 @@ Methods: Types: ```python -from courier.types import BaseCheck, Check, NotificationGetContent, NotificationListResponse +from courier.types import ( + BaseCheck, + Check, + NotificationGetContent, + NotificationTemplateCreateRequest, + NotificationTemplateGetResponse, + NotificationTemplateMutationResponse, + NotificationTemplatePayload, + NotificationTemplateSummary, + NotificationTemplateUpdateRequest, + NotificationListResponse, +) ``` Methods: +- client.notifications.create(\*\*params) -> NotificationTemplateMutationResponse +- client.notifications.retrieve(id, \*\*params) -> NotificationTemplateGetResponse - client.notifications.list(\*\*params) -> NotificationListResponse +- client.notifications.archive(id) -> None +- client.notifications.publish(id) -> None +- client.notifications.replace(id, \*\*params) -> NotificationTemplateMutationResponse - client.notifications.retrieve_content(id) -> NotificationGetContent ## Draft diff --git a/pyproject.toml b/pyproject.toml index f17335a1..52c6bc0b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "trycourier" -version = "7.9.0" +version = "7.10.0" description = "The official Python library for the Courier API" dynamic = ["readme"] license = "Apache-2.0" @@ -11,7 +11,7 @@ authors = [ dependencies = [ "httpx>=0.23.0, <1", "pydantic>=1.9.0, <3", - "typing-extensions>=4.10, <5", + "typing-extensions>=4.14, <5", "anyio>=3.5.0, <5", "distro>=1.7.0, <2", "sniffio", diff --git a/src/courier/_compat.py b/src/courier/_compat.py index 786ff42a..e6690a4f 100644 --- a/src/courier/_compat.py +++ b/src/courier/_compat.py @@ -2,7 +2,7 @@ from typing import TYPE_CHECKING, Any, Union, Generic, TypeVar, Callable, cast, overload from datetime import date, datetime -from typing_extensions import Self, Literal +from typing_extensions import Self, Literal, TypedDict import pydantic from pydantic.fields import FieldInfo @@ -131,6 +131,10 @@ def model_json(model: pydantic.BaseModel, *, indent: int | None = None) -> str: return model.model_dump_json(indent=indent) +class _ModelDumpKwargs(TypedDict, total=False): + by_alias: bool + + def model_dump( model: pydantic.BaseModel, *, @@ -142,6 +146,9 @@ def model_dump( by_alias: bool | None = None, ) -> dict[str, Any]: if (not PYDANTIC_V1) or hasattr(model, "model_dump"): + kwargs: _ModelDumpKwargs = {} + if by_alias is not None: + kwargs["by_alias"] = by_alias return model.model_dump( mode=mode, exclude=exclude, @@ -149,7 +156,7 @@ def model_dump( exclude_defaults=exclude_defaults, # warnings are not supported in Pydantic v1 warnings=True if PYDANTIC_V1 else warnings, - by_alias=by_alias, + **kwargs, ) return cast( "dict[str, Any]", diff --git a/src/courier/_utils/__init__.py b/src/courier/_utils/__init__.py index dc64e29a..10cb66d2 100644 --- a/src/courier/_utils/__init__.py +++ b/src/courier/_utils/__init__.py @@ -1,3 +1,4 @@ +from ._path import path_template as path_template from ._sync import asyncify as asyncify from ._proxy import LazyProxy as LazyProxy from ._utils import ( diff --git a/src/courier/_utils/_path.py b/src/courier/_utils/_path.py new file mode 100644 index 00000000..4d6e1e4c --- /dev/null +++ b/src/courier/_utils/_path.py @@ -0,0 +1,127 @@ +from __future__ import annotations + +import re +from typing import ( + Any, + Mapping, + Callable, +) +from urllib.parse import quote + +# Matches '.' or '..' where each dot is either literal or percent-encoded (%2e / %2E). +_DOT_SEGMENT_RE = re.compile(r"^(?:\.|%2[eE]){1,2}$") + +_PLACEHOLDER_RE = re.compile(r"\{(\w+)\}") + + +def _quote_path_segment_part(value: str) -> str: + """Percent-encode `value` for use in a URI path segment. + + Considers characters not in `pchar` set from RFC 3986 §3.3 to be unsafe. + https://datatracker.ietf.org/doc/html/rfc3986#section-3.3 + """ + # quote() already treats unreserved characters (letters, digits, and -._~) + # as safe, so we only need to add sub-delims, ':', and '@'. + # Notably, unlike the default `safe` for quote(), / is unsafe and must be quoted. + return quote(value, safe="!$&'()*+,;=:@") + + +def _quote_query_part(value: str) -> str: + """Percent-encode `value` for use in a URI query string. + + Considers &, = and characters not in `query` set from RFC 3986 §3.4 to be unsafe. + https://datatracker.ietf.org/doc/html/rfc3986#section-3.4 + """ + return quote(value, safe="!$'()*+,;:@/?") + + +def _quote_fragment_part(value: str) -> str: + """Percent-encode `value` for use in a URI fragment. + + Considers characters not in `fragment` set from RFC 3986 §3.5 to be unsafe. + https://datatracker.ietf.org/doc/html/rfc3986#section-3.5 + """ + return quote(value, safe="!$&'()*+,;=:@/?") + + +def _interpolate( + template: str, + values: Mapping[str, Any], + quoter: Callable[[str], str], +) -> str: + """Replace {name} placeholders in `template`, quoting each value with `quoter`. + + Placeholder names are looked up in `values`. + + Raises: + KeyError: If a placeholder is not found in `values`. + """ + # re.split with a capturing group returns alternating + # [text, name, text, name, ..., text] elements. + parts = _PLACEHOLDER_RE.split(template) + + for i in range(1, len(parts), 2): + name = parts[i] + if name not in values: + raise KeyError(f"a value for placeholder {{{name}}} was not provided") + val = values[name] + if val is None: + parts[i] = "null" + elif isinstance(val, bool): + parts[i] = "true" if val else "false" + else: + parts[i] = quoter(str(values[name])) + + return "".join(parts) + + +def path_template(template: str, /, **kwargs: Any) -> str: + """Interpolate {name} placeholders in `template` from keyword arguments. + + Args: + template: The template string containing {name} placeholders. + **kwargs: Keyword arguments to interpolate into the template. + + Returns: + The template with placeholders interpolated and percent-encoded. + + Safe characters for percent-encoding are dependent on the URI component. + Placeholders in path and fragment portions are percent-encoded where the `segment` + and `fragment` sets from RFC 3986 respectively are considered safe. + Placeholders in the query portion are percent-encoded where the `query` set from + RFC 3986 §3.3 is considered safe except for = and & characters. + + Raises: + KeyError: If a placeholder is not found in `kwargs`. + ValueError: If resulting path contains /./ or /../ segments (including percent-encoded dot-segments). + """ + # Split the template into path, query, and fragment portions. + fragment_template: str | None = None + query_template: str | None = None + + rest = template + if "#" in rest: + rest, fragment_template = rest.split("#", 1) + if "?" in rest: + rest, query_template = rest.split("?", 1) + path_template = rest + + # Interpolate each portion with the appropriate quoting rules. + path_result = _interpolate(path_template, kwargs, _quote_path_segment_part) + + # Reject dot-segments (. and ..) in the final assembled path. The check + # runs after interpolation so that adjacent placeholders or a mix of static + # text and placeholders that together form a dot-segment are caught. + # Also reject percent-encoded dot-segments to protect against incorrectly + # implemented normalization in servers/proxies. + for segment in path_result.split("/"): + if _DOT_SEGMENT_RE.match(segment): + raise ValueError(f"Constructed path {path_result!r} contains dot-segment {segment!r} which is not allowed") + + result = path_result + if query_template is not None: + result += "?" + _interpolate(query_template, kwargs, _quote_query_part) + if fragment_template is not None: + result += "#" + _interpolate(fragment_template, kwargs, _quote_fragment_part) + + return result diff --git a/src/courier/_version.py b/src/courier/_version.py index c3d0de8c..baccb2b3 100644 --- a/src/courier/_version.py +++ b/src/courier/_version.py @@ -1,4 +1,4 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. __title__ = "courier" -__version__ = "7.9.0" # x-release-please-version +__version__ = "7.10.0" # x-release-please-version diff --git a/src/courier/resources/audiences.py b/src/courier/resources/audiences.py index 449c9ff0..82b0c558 100644 --- a/src/courier/resources/audiences.py +++ b/src/courier/resources/audiences.py @@ -9,7 +9,7 @@ from ..types import audience_list_params, audience_update_params, audience_list_members_params from .._types import Body, Omit, Query, Headers, NoneType, NotGiven, omit, not_given -from .._utils import maybe_transform, async_maybe_transform +from .._utils import path_template, maybe_transform, async_maybe_transform from .._compat import cached_property from .._resource import SyncAPIResource, AsyncAPIResource from .._response import ( @@ -74,7 +74,7 @@ def retrieve( if not audience_id: raise ValueError(f"Expected a non-empty value for `audience_id` but received {audience_id!r}") return self._get( - f"/audiences/{audience_id}", + path_template("/audiences/{audience_id}", audience_id=audience_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -119,7 +119,7 @@ def update( if not audience_id: raise ValueError(f"Expected a non-empty value for `audience_id` but received {audience_id!r}") return self._put( - f"/audiences/{audience_id}", + path_template("/audiences/{audience_id}", audience_id=audience_id), body=maybe_transform( { "description": description, @@ -199,7 +199,7 @@ def delete( raise ValueError(f"Expected a non-empty value for `audience_id` but received {audience_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return self._delete( - f"/audiences/{audience_id}", + path_template("/audiences/{audience_id}", audience_id=audience_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -235,7 +235,7 @@ def list_members( if not audience_id: raise ValueError(f"Expected a non-empty value for `audience_id` but received {audience_id!r}") return self._get( - f"/audiences/{audience_id}/members", + path_template("/audiences/{audience_id}/members", audience_id=audience_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, @@ -293,7 +293,7 @@ async def retrieve( if not audience_id: raise ValueError(f"Expected a non-empty value for `audience_id` but received {audience_id!r}") return await self._get( - f"/audiences/{audience_id}", + path_template("/audiences/{audience_id}", audience_id=audience_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -338,7 +338,7 @@ async def update( if not audience_id: raise ValueError(f"Expected a non-empty value for `audience_id` but received {audience_id!r}") return await self._put( - f"/audiences/{audience_id}", + path_template("/audiences/{audience_id}", audience_id=audience_id), body=await async_maybe_transform( { "description": description, @@ -418,7 +418,7 @@ async def delete( raise ValueError(f"Expected a non-empty value for `audience_id` but received {audience_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return await self._delete( - f"/audiences/{audience_id}", + path_template("/audiences/{audience_id}", audience_id=audience_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -454,7 +454,7 @@ async def list_members( if not audience_id: raise ValueError(f"Expected a non-empty value for `audience_id` but received {audience_id!r}") return await self._get( - f"/audiences/{audience_id}/members", + path_template("/audiences/{audience_id}/members", audience_id=audience_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, diff --git a/src/courier/resources/audit_events.py b/src/courier/resources/audit_events.py index 48d31d55..0323e1fc 100644 --- a/src/courier/resources/audit_events.py +++ b/src/courier/resources/audit_events.py @@ -8,7 +8,7 @@ from ..types import audit_event_list_params from .._types import Body, Omit, Query, Headers, NotGiven, omit, not_given -from .._utils import maybe_transform, async_maybe_transform +from .._utils import path_template, maybe_transform, async_maybe_transform from .._compat import cached_property from .._resource import SyncAPIResource, AsyncAPIResource from .._response import ( @@ -70,7 +70,7 @@ def retrieve( if not audit_event_id: raise ValueError(f"Expected a non-empty value for `audit_event_id` but received {audit_event_id!r}") return self._get( - f"/audit-events/{audit_event_id}", + path_template("/audit-events/{audit_event_id}", audit_event_id=audit_event_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -161,7 +161,7 @@ async def retrieve( if not audit_event_id: raise ValueError(f"Expected a non-empty value for `audit_event_id` but received {audit_event_id!r}") return await self._get( - f"/audit-events/{audit_event_id}", + path_template("/audit-events/{audit_event_id}", audit_event_id=audit_event_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), diff --git a/src/courier/resources/automations/invoke.py b/src/courier/resources/automations/invoke.py index 2904c862..7ec143ec 100644 --- a/src/courier/resources/automations/invoke.py +++ b/src/courier/resources/automations/invoke.py @@ -7,7 +7,7 @@ import httpx from ..._types import Body, Omit, Query, Headers, NotGiven, omit, not_given -from ..._utils import maybe_transform, async_maybe_transform +from ..._utils import path_template, maybe_transform, async_maybe_transform from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource from ..._response import ( @@ -125,7 +125,7 @@ def invoke_by_template( if not template_id: raise ValueError(f"Expected a non-empty value for `template_id` but received {template_id!r}") return self._post( - f"/automations/{template_id}/invoke", + path_template("/automations/{template_id}/invoke", template_id=template_id), body=maybe_transform( { "recipient": recipient, @@ -245,7 +245,7 @@ async def invoke_by_template( if not template_id: raise ValueError(f"Expected a non-empty value for `template_id` but received {template_id!r}") return await self._post( - f"/automations/{template_id}/invoke", + path_template("/automations/{template_id}/invoke", template_id=template_id), body=await async_maybe_transform( { "recipient": recipient, diff --git a/src/courier/resources/brands.py b/src/courier/resources/brands.py index 2579172e..f33b1d0b 100644 --- a/src/courier/resources/brands.py +++ b/src/courier/resources/brands.py @@ -8,7 +8,7 @@ from ..types import brand_list_params, brand_create_params, brand_update_params from .._types import Body, Omit, Query, Headers, NoneType, NotGiven, omit, not_given -from .._utils import maybe_transform, async_maybe_transform +from .._utils import path_template, maybe_transform, async_maybe_transform from .._compat import cached_property from .._resource import SyncAPIResource, AsyncAPIResource from .._response import ( @@ -115,7 +115,7 @@ def retrieve( if not brand_id: raise ValueError(f"Expected a non-empty value for `brand_id` but received {brand_id!r}") return self._get( - f"/brands/{brand_id}", + path_template("/brands/{brand_id}", brand_id=brand_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -153,7 +153,7 @@ def update( if not brand_id: raise ValueError(f"Expected a non-empty value for `brand_id` but received {brand_id!r}") return self._put( - f"/brands/{brand_id}", + path_template("/brands/{brand_id}", brand_id=brand_id), body=maybe_transform( { "name": name, @@ -232,7 +232,7 @@ def delete( raise ValueError(f"Expected a non-empty value for `brand_id` but received {brand_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return self._delete( - f"/brands/{brand_id}", + path_template("/brands/{brand_id}", brand_id=brand_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -329,7 +329,7 @@ async def retrieve( if not brand_id: raise ValueError(f"Expected a non-empty value for `brand_id` but received {brand_id!r}") return await self._get( - f"/brands/{brand_id}", + path_template("/brands/{brand_id}", brand_id=brand_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -367,7 +367,7 @@ async def update( if not brand_id: raise ValueError(f"Expected a non-empty value for `brand_id` but received {brand_id!r}") return await self._put( - f"/brands/{brand_id}", + path_template("/brands/{brand_id}", brand_id=brand_id), body=await async_maybe_transform( { "name": name, @@ -446,7 +446,7 @@ async def delete( raise ValueError(f"Expected a non-empty value for `brand_id` but received {brand_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return await self._delete( - f"/brands/{brand_id}", + path_template("/brands/{brand_id}", brand_id=brand_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), diff --git a/src/courier/resources/bulk.py b/src/courier/resources/bulk.py index c431cea0..464a615a 100644 --- a/src/courier/resources/bulk.py +++ b/src/courier/resources/bulk.py @@ -8,7 +8,7 @@ from ..types import bulk_add_users_params, bulk_create_job_params, bulk_list_users_params from .._types import Body, Omit, Query, Headers, NoneType, NotGiven, omit, not_given -from .._utils import maybe_transform, async_maybe_transform +from .._utils import path_template, maybe_transform, async_maybe_transform from .._compat import cached_property from .._resource import SyncAPIResource, AsyncAPIResource from .._response import ( @@ -79,7 +79,7 @@ def add_users( raise ValueError(f"Expected a non-empty value for `job_id` but received {job_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return self._post( - f"/bulk/{job_id}", + path_template("/bulk/{job_id}", job_id=job_id), body=maybe_transform({"users": users}, bulk_add_users_params.BulkAddUsersParams), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout @@ -162,7 +162,7 @@ def list_users( if not job_id: raise ValueError(f"Expected a non-empty value for `job_id` but received {job_id!r}") return self._get( - f"/bulk/{job_id}/users", + path_template("/bulk/{job_id}/users", job_id=job_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, @@ -199,7 +199,7 @@ def retrieve_job( if not job_id: raise ValueError(f"Expected a non-empty value for `job_id` but received {job_id!r}") return self._get( - f"/bulk/{job_id}", + path_template("/bulk/{job_id}", job_id=job_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -233,7 +233,7 @@ def run_job( raise ValueError(f"Expected a non-empty value for `job_id` but received {job_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return self._post( - f"/bulk/{job_id}/run", + path_template("/bulk/{job_id}/run", job_id=job_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -293,7 +293,7 @@ async def add_users( raise ValueError(f"Expected a non-empty value for `job_id` but received {job_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return await self._post( - f"/bulk/{job_id}", + path_template("/bulk/{job_id}", job_id=job_id), body=await async_maybe_transform({"users": users}, bulk_add_users_params.BulkAddUsersParams), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout @@ -376,7 +376,7 @@ async def list_users( if not job_id: raise ValueError(f"Expected a non-empty value for `job_id` but received {job_id!r}") return await self._get( - f"/bulk/{job_id}/users", + path_template("/bulk/{job_id}/users", job_id=job_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, @@ -413,7 +413,7 @@ async def retrieve_job( if not job_id: raise ValueError(f"Expected a non-empty value for `job_id` but received {job_id!r}") return await self._get( - f"/bulk/{job_id}", + path_template("/bulk/{job_id}", job_id=job_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -447,7 +447,7 @@ async def run_job( raise ValueError(f"Expected a non-empty value for `job_id` but received {job_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return await self._post( - f"/bulk/{job_id}/run", + path_template("/bulk/{job_id}/run", job_id=job_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), diff --git a/src/courier/resources/journeys.py b/src/courier/resources/journeys.py index 06204a70..15b5139e 100644 --- a/src/courier/resources/journeys.py +++ b/src/courier/resources/journeys.py @@ -9,7 +9,7 @@ from ..types import journey_list_params, journey_invoke_params from .._types import Body, Omit, Query, Headers, NotGiven, omit, not_given -from .._utils import maybe_transform, async_maybe_transform +from .._utils import path_template, maybe_transform, async_maybe_transform from .._compat import cached_property from .._resource import SyncAPIResource, AsyncAPIResource from .._response import ( @@ -138,7 +138,7 @@ def invoke( if not template_id: raise ValueError(f"Expected a non-empty value for `template_id` but received {template_id!r}") return self._post( - f"/journeys/{template_id}/invoke", + path_template("/journeys/{template_id}/invoke", template_id=template_id), body=maybe_transform( { "data": data, @@ -267,7 +267,7 @@ async def invoke( if not template_id: raise ValueError(f"Expected a non-empty value for `template_id` but received {template_id!r}") return await self._post( - f"/journeys/{template_id}/invoke", + path_template("/journeys/{template_id}/invoke", template_id=template_id), body=await async_maybe_transform( { "data": data, diff --git a/src/courier/resources/lists/lists.py b/src/courier/resources/lists/lists.py index ffd09f4c..ae71b29b 100644 --- a/src/courier/resources/lists/lists.py +++ b/src/courier/resources/lists/lists.py @@ -8,7 +8,7 @@ from ...types import list_list_params, list_update_params from ..._types import Body, Omit, Query, Headers, NoneType, NotGiven, omit, not_given -from ..._utils import maybe_transform, async_maybe_transform +from ..._utils import path_template, maybe_transform, async_maybe_transform from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource from ..._response import ( @@ -83,7 +83,7 @@ def retrieve( if not list_id: raise ValueError(f"Expected a non-empty value for `list_id` but received {list_id!r}") return self._get( - f"/lists/{list_id}", + path_template("/lists/{list_id}", list_id=list_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -119,7 +119,7 @@ def update( raise ValueError(f"Expected a non-empty value for `list_id` but received {list_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return self._put( - f"/lists/{list_id}", + path_template("/lists/{list_id}", list_id=list_id), body=maybe_transform( { "name": name, @@ -210,7 +210,7 @@ def delete( raise ValueError(f"Expected a non-empty value for `list_id` but received {list_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return self._delete( - f"/lists/{list_id}", + path_template("/lists/{list_id}", list_id=list_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -244,7 +244,7 @@ def restore( raise ValueError(f"Expected a non-empty value for `list_id` but received {list_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return self._put( - f"/lists/{list_id}/restore", + path_template("/lists/{list_id}/restore", list_id=list_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -302,7 +302,7 @@ async def retrieve( if not list_id: raise ValueError(f"Expected a non-empty value for `list_id` but received {list_id!r}") return await self._get( - f"/lists/{list_id}", + path_template("/lists/{list_id}", list_id=list_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -338,7 +338,7 @@ async def update( raise ValueError(f"Expected a non-empty value for `list_id` but received {list_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return await self._put( - f"/lists/{list_id}", + path_template("/lists/{list_id}", list_id=list_id), body=await async_maybe_transform( { "name": name, @@ -429,7 +429,7 @@ async def delete( raise ValueError(f"Expected a non-empty value for `list_id` but received {list_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return await self._delete( - f"/lists/{list_id}", + path_template("/lists/{list_id}", list_id=list_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -463,7 +463,7 @@ async def restore( raise ValueError(f"Expected a non-empty value for `list_id` but received {list_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return await self._put( - f"/lists/{list_id}/restore", + path_template("/lists/{list_id}/restore", list_id=list_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), diff --git a/src/courier/resources/lists/subscriptions.py b/src/courier/resources/lists/subscriptions.py index b4e310d0..74034f4b 100644 --- a/src/courier/resources/lists/subscriptions.py +++ b/src/courier/resources/lists/subscriptions.py @@ -7,7 +7,7 @@ import httpx from ..._types import Body, Omit, Query, Headers, NoneType, NotGiven, omit, not_given -from ..._utils import maybe_transform, async_maybe_transform +from ..._utils import path_template, maybe_transform, async_maybe_transform from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource from ..._response import ( @@ -79,7 +79,7 @@ def list( if not list_id: raise ValueError(f"Expected a non-empty value for `list_id` but received {list_id!r}") return self._get( - f"/lists/{list_id}/subscriptions", + path_template("/lists/{list_id}/subscriptions", list_id=list_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, @@ -119,7 +119,7 @@ def add( raise ValueError(f"Expected a non-empty value for `list_id` but received {list_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return self._post( - f"/lists/{list_id}/subscriptions", + path_template("/lists/{list_id}/subscriptions", list_id=list_id), body=maybe_transform({"recipients": recipients}, subscription_add_params.SubscriptionAddParams), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout @@ -157,7 +157,7 @@ def subscribe( raise ValueError(f"Expected a non-empty value for `list_id` but received {list_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return self._put( - f"/lists/{list_id}/subscriptions", + path_template("/lists/{list_id}/subscriptions", list_id=list_id), body=maybe_transform({"recipients": recipients}, subscription_subscribe_params.SubscriptionSubscribeParams), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout @@ -197,7 +197,7 @@ def subscribe_user( raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return self._put( - f"/lists/{list_id}/subscriptions/{user_id}", + path_template("/lists/{list_id}/subscriptions/{user_id}", list_id=list_id, user_id=user_id), body=maybe_transform( {"preferences": preferences}, subscription_subscribe_user_params.SubscriptionSubscribeUserParams ), @@ -237,7 +237,7 @@ def unsubscribe_user( raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return self._delete( - f"/lists/{list_id}/subscriptions/{user_id}", + path_template("/lists/{list_id}/subscriptions/{user_id}", list_id=list_id, user_id=user_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -294,7 +294,7 @@ async def list( if not list_id: raise ValueError(f"Expected a non-empty value for `list_id` but received {list_id!r}") return await self._get( - f"/lists/{list_id}/subscriptions", + path_template("/lists/{list_id}/subscriptions", list_id=list_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, @@ -334,7 +334,7 @@ async def add( raise ValueError(f"Expected a non-empty value for `list_id` but received {list_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return await self._post( - f"/lists/{list_id}/subscriptions", + path_template("/lists/{list_id}/subscriptions", list_id=list_id), body=await async_maybe_transform({"recipients": recipients}, subscription_add_params.SubscriptionAddParams), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout @@ -372,7 +372,7 @@ async def subscribe( raise ValueError(f"Expected a non-empty value for `list_id` but received {list_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return await self._put( - f"/lists/{list_id}/subscriptions", + path_template("/lists/{list_id}/subscriptions", list_id=list_id), body=await async_maybe_transform( {"recipients": recipients}, subscription_subscribe_params.SubscriptionSubscribeParams ), @@ -414,7 +414,7 @@ async def subscribe_user( raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return await self._put( - f"/lists/{list_id}/subscriptions/{user_id}", + path_template("/lists/{list_id}/subscriptions/{user_id}", list_id=list_id, user_id=user_id), body=await async_maybe_transform( {"preferences": preferences}, subscription_subscribe_user_params.SubscriptionSubscribeUserParams ), @@ -454,7 +454,7 @@ async def unsubscribe_user( raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return await self._delete( - f"/lists/{list_id}/subscriptions/{user_id}", + path_template("/lists/{list_id}/subscriptions/{user_id}", list_id=list_id, user_id=user_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), diff --git a/src/courier/resources/messages.py b/src/courier/resources/messages.py index cf0e4184..a607c86f 100644 --- a/src/courier/resources/messages.py +++ b/src/courier/resources/messages.py @@ -8,7 +8,7 @@ from ..types import message_list_params, message_history_params from .._types import Body, Omit, Query, Headers, NotGiven, SequenceNotStr, omit, not_given -from .._utils import maybe_transform, async_maybe_transform +from .._utils import path_template, maybe_transform, async_maybe_transform from .._compat import cached_property from .._resource import SyncAPIResource, AsyncAPIResource from .._response import ( @@ -73,7 +73,7 @@ def retrieve( if not message_id: raise ValueError(f"Expected a non-empty value for `message_id` but received {message_id!r}") return self._get( - f"/messages/{message_id}", + path_template("/messages/{message_id}", message_id=message_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -214,7 +214,7 @@ def cancel( if not message_id: raise ValueError(f"Expected a non-empty value for `message_id` but received {message_id!r}") return self._post( - f"/messages/{message_id}/cancel", + path_template("/messages/{message_id}/cancel", message_id=message_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -247,7 +247,7 @@ def content( if not message_id: raise ValueError(f"Expected a non-empty value for `message_id` but received {message_id!r}") return self._get( - f"/messages/{message_id}/output", + path_template("/messages/{message_id}/output", message_id=message_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -283,7 +283,7 @@ def history( if not message_id: raise ValueError(f"Expected a non-empty value for `message_id` but received {message_id!r}") return self._get( - f"/messages/{message_id}/history", + path_template("/messages/{message_id}/history", message_id=message_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, @@ -341,7 +341,7 @@ async def retrieve( if not message_id: raise ValueError(f"Expected a non-empty value for `message_id` but received {message_id!r}") return await self._get( - f"/messages/{message_id}", + path_template("/messages/{message_id}", message_id=message_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -482,7 +482,7 @@ async def cancel( if not message_id: raise ValueError(f"Expected a non-empty value for `message_id` but received {message_id!r}") return await self._post( - f"/messages/{message_id}/cancel", + path_template("/messages/{message_id}/cancel", message_id=message_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -515,7 +515,7 @@ async def content( if not message_id: raise ValueError(f"Expected a non-empty value for `message_id` but received {message_id!r}") return await self._get( - f"/messages/{message_id}/output", + path_template("/messages/{message_id}/output", message_id=message_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -551,7 +551,7 @@ async def history( if not message_id: raise ValueError(f"Expected a non-empty value for `message_id` but received {message_id!r}") return await self._get( - f"/messages/{message_id}/history", + path_template("/messages/{message_id}/history", message_id=message_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, diff --git a/src/courier/resources/notifications/checks.py b/src/courier/resources/notifications/checks.py index a22ea653..0b2c523b 100644 --- a/src/courier/resources/notifications/checks.py +++ b/src/courier/resources/notifications/checks.py @@ -7,7 +7,7 @@ import httpx from ..._types import Body, Query, Headers, NoneType, NotGiven, not_given -from ..._utils import maybe_transform, async_maybe_transform +from ..._utils import path_template, maybe_transform, async_maybe_transform from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource from ..._response import ( @@ -73,7 +73,7 @@ def update( if not submission_id: raise ValueError(f"Expected a non-empty value for `submission_id` but received {submission_id!r}") return self._put( - f"/notifications/{id}/{submission_id}/checks", + path_template("/notifications/{id}/{submission_id}/checks", id=id, submission_id=submission_id), body=maybe_transform({"checks": checks}, check_update_params.CheckUpdateParams), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout @@ -108,7 +108,7 @@ def list( if not submission_id: raise ValueError(f"Expected a non-empty value for `submission_id` but received {submission_id!r}") return self._get( - f"/notifications/{id}/{submission_id}/checks", + path_template("/notifications/{id}/{submission_id}/checks", id=id, submission_id=submission_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -143,7 +143,7 @@ def delete( raise ValueError(f"Expected a non-empty value for `submission_id` but received {submission_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return self._delete( - f"/notifications/{id}/{submission_id}/checks", + path_template("/notifications/{id}/{submission_id}/checks", id=id, submission_id=submission_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -199,7 +199,7 @@ async def update( if not submission_id: raise ValueError(f"Expected a non-empty value for `submission_id` but received {submission_id!r}") return await self._put( - f"/notifications/{id}/{submission_id}/checks", + path_template("/notifications/{id}/{submission_id}/checks", id=id, submission_id=submission_id), body=await async_maybe_transform({"checks": checks}, check_update_params.CheckUpdateParams), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout @@ -234,7 +234,7 @@ async def list( if not submission_id: raise ValueError(f"Expected a non-empty value for `submission_id` but received {submission_id!r}") return await self._get( - f"/notifications/{id}/{submission_id}/checks", + path_template("/notifications/{id}/{submission_id}/checks", id=id, submission_id=submission_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -269,7 +269,7 @@ async def delete( raise ValueError(f"Expected a non-empty value for `submission_id` but received {submission_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return await self._delete( - f"/notifications/{id}/{submission_id}/checks", + path_template("/notifications/{id}/{submission_id}/checks", id=id, submission_id=submission_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), diff --git a/src/courier/resources/notifications/draft.py b/src/courier/resources/notifications/draft.py index bbbab8db..10ba1da6 100644 --- a/src/courier/resources/notifications/draft.py +++ b/src/courier/resources/notifications/draft.py @@ -5,6 +5,7 @@ import httpx from ..._types import Body, Query, Headers, NotGiven, not_given +from ..._utils import path_template from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource from ..._response import ( @@ -63,7 +64,7 @@ def retrieve_content( if not id: raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") return self._get( - f"/notifications/{id}/draft/content", + path_template("/notifications/{id}/draft/content", id=id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -115,7 +116,7 @@ async def retrieve_content( if not id: raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") return await self._get( - f"/notifications/{id}/draft/content", + path_template("/notifications/{id}/draft/content", id=id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), diff --git a/src/courier/resources/notifications/notifications.py b/src/courier/resources/notifications/notifications.py index 6347bba3..6c111c5a 100644 --- a/src/courier/resources/notifications/notifications.py +++ b/src/courier/resources/notifications/notifications.py @@ -3,6 +3,7 @@ from __future__ import annotations from typing import Optional +from typing_extensions import Literal import httpx @@ -22,9 +23,14 @@ ChecksResourceWithStreamingResponse, AsyncChecksResourceWithStreamingResponse, ) -from ...types import notification_list_params -from ..._types import Body, Omit, Query, Headers, NotGiven, omit, not_given -from ..._utils import maybe_transform, async_maybe_transform +from ...types import ( + notification_list_params, + notification_create_params, + notification_replace_params, + notification_retrieve_params, +) +from ..._types import Body, Omit, Query, Headers, NoneType, NotGiven, omit, not_given +from ..._utils import path_template, maybe_transform, async_maybe_transform from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource from ..._response import ( @@ -36,6 +42,9 @@ from ..._base_client import make_request_options from ...types.notification_get_content import NotificationGetContent from ...types.notification_list_response import NotificationListResponse +from ...types.notification_template_get_response import NotificationTemplateGetResponse +from ...types.notification_template_payload_param import NotificationTemplatePayloadParam +from ...types.notification_template_mutation_response import NotificationTemplateMutationResponse __all__ = ["NotificationsResource", "AsyncNotificationsResource"] @@ -68,10 +77,101 @@ def with_streaming_response(self) -> NotificationsResourceWithStreamingResponse: """ return NotificationsResourceWithStreamingResponse(self) + def create( + self, + *, + notification: NotificationTemplatePayloadParam, + state: Literal["DRAFT", "PUBLISHED"] | Omit = omit, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = not_given, + ) -> NotificationTemplateMutationResponse: + """Create a notification template. + + Requires all fields in the notification object. + Templates are created in draft state by default. + + Args: + notification: Full document shape used in POST and PUT request bodies, and returned inside the + GET response envelope. + + state: Template state after creation. Case-insensitive input, normalized to uppercase + in the response. Defaults to "DRAFT". + + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + return self._post( + "/notifications", + body=maybe_transform( + { + "notification": notification, + "state": state, + }, + notification_create_params.NotificationCreateParams, + ), + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=NotificationTemplateMutationResponse, + ) + + def retrieve( + self, + id: str, + *, + version: str | Omit = omit, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = not_given, + ) -> NotificationTemplateGetResponse: + """Retrieve a notification template by ID. + + Returns the published version by + default. Pass version=draft to retrieve an unpublished template. + + Args: + version: Version to retrieve. One of "draft", "published", or a version string like + "v001". Defaults to "published". + + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + if not id: + raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") + return self._get( + path_template("/notifications/{id}", id=id), + options=make_request_options( + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + query=maybe_transform({"version": version}, notification_retrieve_params.NotificationRetrieveParams), + ), + cast_to=NotificationTemplateGetResponse, + ) + def list( self, *, cursor: Optional[str] | Omit = omit, + event_id: str | Omit = omit, notes: Optional[bool] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. @@ -81,8 +181,14 @@ def list( timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> NotificationListResponse: """ + List notification templates in your workspace. + Args: - notes: Retrieve the notes from the Notification template settings. + cursor: Opaque pagination cursor from a previous response. Omit for the first page. + + event_id: Filter to templates linked to this event map ID. + + notes: Include template notes in the response. Only applies to legacy templates. extra_headers: Send extra headers @@ -102,6 +208,7 @@ def list( query=maybe_transform( { "cursor": cursor, + "event_id": event_id, "notes": notes, }, notification_list_params.NotificationListParams, @@ -110,6 +217,123 @@ def list( cast_to=NotificationListResponse, ) + def archive( + self, + id: str, + *, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = not_given, + ) -> None: + """ + Archive a notification template. + + Args: + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + if not id: + raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") + extra_headers = {"Accept": "*/*", **(extra_headers or {})} + return self._delete( + path_template("/notifications/{id}", id=id), + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=NoneType, + ) + + def publish( + self, + id: str, + *, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = not_given, + ) -> None: + """ + Publish the current draft of a notification template. + + Args: + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + if not id: + raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") + extra_headers = {"Accept": "*/*", **(extra_headers or {})} + return self._post( + path_template("/notifications/{id}/publish", id=id), + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=NoneType, + ) + + def replace( + self, + id: str, + *, + notification: NotificationTemplatePayloadParam, + state: Literal["DRAFT", "PUBLISHED"] | Omit = omit, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = not_given, + ) -> NotificationTemplateMutationResponse: + """Replace a notification template. + + All fields are required. + + Args: + notification: Full document shape used in POST and PUT request bodies, and returned inside the + GET response envelope. + + state: Template state after update. Case-insensitive input, normalized to uppercase in + the response. Defaults to "DRAFT". + + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + if not id: + raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") + return self._put( + path_template("/notifications/{id}", id=id), + body=maybe_transform( + { + "notification": notification, + "state": state, + }, + notification_replace_params.NotificationReplaceParams, + ), + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=NotificationTemplateMutationResponse, + ) + def retrieve_content( self, id: str, @@ -134,7 +358,7 @@ def retrieve_content( if not id: raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") return self._get( - f"/notifications/{id}/content", + path_template("/notifications/{id}/content", id=id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -170,10 +394,103 @@ def with_streaming_response(self) -> AsyncNotificationsResourceWithStreamingResp """ return AsyncNotificationsResourceWithStreamingResponse(self) + async def create( + self, + *, + notification: NotificationTemplatePayloadParam, + state: Literal["DRAFT", "PUBLISHED"] | Omit = omit, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = not_given, + ) -> NotificationTemplateMutationResponse: + """Create a notification template. + + Requires all fields in the notification object. + Templates are created in draft state by default. + + Args: + notification: Full document shape used in POST and PUT request bodies, and returned inside the + GET response envelope. + + state: Template state after creation. Case-insensitive input, normalized to uppercase + in the response. Defaults to "DRAFT". + + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + return await self._post( + "/notifications", + body=await async_maybe_transform( + { + "notification": notification, + "state": state, + }, + notification_create_params.NotificationCreateParams, + ), + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=NotificationTemplateMutationResponse, + ) + + async def retrieve( + self, + id: str, + *, + version: str | Omit = omit, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = not_given, + ) -> NotificationTemplateGetResponse: + """Retrieve a notification template by ID. + + Returns the published version by + default. Pass version=draft to retrieve an unpublished template. + + Args: + version: Version to retrieve. One of "draft", "published", or a version string like + "v001". Defaults to "published". + + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + if not id: + raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") + return await self._get( + path_template("/notifications/{id}", id=id), + options=make_request_options( + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + query=await async_maybe_transform( + {"version": version}, notification_retrieve_params.NotificationRetrieveParams + ), + ), + cast_to=NotificationTemplateGetResponse, + ) + async def list( self, *, cursor: Optional[str] | Omit = omit, + event_id: str | Omit = omit, notes: Optional[bool] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. @@ -183,8 +500,14 @@ async def list( timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> NotificationListResponse: """ + List notification templates in your workspace. + Args: - notes: Retrieve the notes from the Notification template settings. + cursor: Opaque pagination cursor from a previous response. Omit for the first page. + + event_id: Filter to templates linked to this event map ID. + + notes: Include template notes in the response. Only applies to legacy templates. extra_headers: Send extra headers @@ -204,6 +527,7 @@ async def list( query=await async_maybe_transform( { "cursor": cursor, + "event_id": event_id, "notes": notes, }, notification_list_params.NotificationListParams, @@ -212,6 +536,123 @@ async def list( cast_to=NotificationListResponse, ) + async def archive( + self, + id: str, + *, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = not_given, + ) -> None: + """ + Archive a notification template. + + Args: + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + if not id: + raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") + extra_headers = {"Accept": "*/*", **(extra_headers or {})} + return await self._delete( + path_template("/notifications/{id}", id=id), + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=NoneType, + ) + + async def publish( + self, + id: str, + *, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = not_given, + ) -> None: + """ + Publish the current draft of a notification template. + + Args: + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + if not id: + raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") + extra_headers = {"Accept": "*/*", **(extra_headers or {})} + return await self._post( + path_template("/notifications/{id}/publish", id=id), + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=NoneType, + ) + + async def replace( + self, + id: str, + *, + notification: NotificationTemplatePayloadParam, + state: Literal["DRAFT", "PUBLISHED"] | Omit = omit, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = not_given, + ) -> NotificationTemplateMutationResponse: + """Replace a notification template. + + All fields are required. + + Args: + notification: Full document shape used in POST and PUT request bodies, and returned inside the + GET response envelope. + + state: Template state after update. Case-insensitive input, normalized to uppercase in + the response. Defaults to "DRAFT". + + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + if not id: + raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") + return await self._put( + path_template("/notifications/{id}", id=id), + body=await async_maybe_transform( + { + "notification": notification, + "state": state, + }, + notification_replace_params.NotificationReplaceParams, + ), + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=NotificationTemplateMutationResponse, + ) + async def retrieve_content( self, id: str, @@ -236,7 +677,7 @@ async def retrieve_content( if not id: raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") return await self._get( - f"/notifications/{id}/content", + path_template("/notifications/{id}/content", id=id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -248,9 +689,24 @@ class NotificationsResourceWithRawResponse: def __init__(self, notifications: NotificationsResource) -> None: self._notifications = notifications + self.create = to_raw_response_wrapper( + notifications.create, + ) + self.retrieve = to_raw_response_wrapper( + notifications.retrieve, + ) self.list = to_raw_response_wrapper( notifications.list, ) + self.archive = to_raw_response_wrapper( + notifications.archive, + ) + self.publish = to_raw_response_wrapper( + notifications.publish, + ) + self.replace = to_raw_response_wrapper( + notifications.replace, + ) self.retrieve_content = to_raw_response_wrapper( notifications.retrieve_content, ) @@ -268,9 +724,24 @@ class AsyncNotificationsResourceWithRawResponse: def __init__(self, notifications: AsyncNotificationsResource) -> None: self._notifications = notifications + self.create = async_to_raw_response_wrapper( + notifications.create, + ) + self.retrieve = async_to_raw_response_wrapper( + notifications.retrieve, + ) self.list = async_to_raw_response_wrapper( notifications.list, ) + self.archive = async_to_raw_response_wrapper( + notifications.archive, + ) + self.publish = async_to_raw_response_wrapper( + notifications.publish, + ) + self.replace = async_to_raw_response_wrapper( + notifications.replace, + ) self.retrieve_content = async_to_raw_response_wrapper( notifications.retrieve_content, ) @@ -288,9 +759,24 @@ class NotificationsResourceWithStreamingResponse: def __init__(self, notifications: NotificationsResource) -> None: self._notifications = notifications + self.create = to_streamed_response_wrapper( + notifications.create, + ) + self.retrieve = to_streamed_response_wrapper( + notifications.retrieve, + ) self.list = to_streamed_response_wrapper( notifications.list, ) + self.archive = to_streamed_response_wrapper( + notifications.archive, + ) + self.publish = to_streamed_response_wrapper( + notifications.publish, + ) + self.replace = to_streamed_response_wrapper( + notifications.replace, + ) self.retrieve_content = to_streamed_response_wrapper( notifications.retrieve_content, ) @@ -308,9 +794,24 @@ class AsyncNotificationsResourceWithStreamingResponse: def __init__(self, notifications: AsyncNotificationsResource) -> None: self._notifications = notifications + self.create = async_to_streamed_response_wrapper( + notifications.create, + ) + self.retrieve = async_to_streamed_response_wrapper( + notifications.retrieve, + ) self.list = async_to_streamed_response_wrapper( notifications.list, ) + self.archive = async_to_streamed_response_wrapper( + notifications.archive, + ) + self.publish = async_to_streamed_response_wrapper( + notifications.publish, + ) + self.replace = async_to_streamed_response_wrapper( + notifications.replace, + ) self.retrieve_content = async_to_streamed_response_wrapper( notifications.retrieve_content, ) diff --git a/src/courier/resources/profiles/lists.py b/src/courier/resources/profiles/lists.py index 291d6542..4f41eb9d 100644 --- a/src/courier/resources/profiles/lists.py +++ b/src/courier/resources/profiles/lists.py @@ -7,7 +7,7 @@ import httpx from ..._types import Body, Omit, Query, Headers, NotGiven, omit, not_given -from ..._utils import maybe_transform, async_maybe_transform +from ..._utils import path_template, maybe_transform, async_maybe_transform from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource from ..._response import ( @@ -75,7 +75,7 @@ def retrieve( if not user_id: raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}") return self._get( - f"/profiles/{user_id}/lists", + path_template("/profiles/{user_id}/lists", user_id=user_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, @@ -112,7 +112,7 @@ def delete( if not user_id: raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}") return self._delete( - f"/profiles/{user_id}/lists", + path_template("/profiles/{user_id}/lists", user_id=user_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -148,7 +148,7 @@ def subscribe( if not user_id: raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}") return self._post( - f"/profiles/{user_id}/lists", + path_template("/profiles/{user_id}/lists", user_id=user_id), body=maybe_transform({"lists": lists}, list_subscribe_params.ListSubscribeParams), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout @@ -206,7 +206,7 @@ async def retrieve( if not user_id: raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}") return await self._get( - f"/profiles/{user_id}/lists", + path_template("/profiles/{user_id}/lists", user_id=user_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, @@ -243,7 +243,7 @@ async def delete( if not user_id: raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}") return await self._delete( - f"/profiles/{user_id}/lists", + path_template("/profiles/{user_id}/lists", user_id=user_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -279,7 +279,7 @@ async def subscribe( if not user_id: raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}") return await self._post( - f"/profiles/{user_id}/lists", + path_template("/profiles/{user_id}/lists", user_id=user_id), body=await async_maybe_transform({"lists": lists}, list_subscribe_params.ListSubscribeParams), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout diff --git a/src/courier/resources/profiles/profiles.py b/src/courier/resources/profiles/profiles.py index 0ff7ffa3..d359fbc1 100644 --- a/src/courier/resources/profiles/profiles.py +++ b/src/courier/resources/profiles/profiles.py @@ -16,7 +16,7 @@ ) from ...types import profile_create_params, profile_update_params, profile_replace_params from ..._types import Body, Query, Headers, NoneType, NotGiven, not_given -from ..._utils import maybe_transform, async_maybe_transform +from ..._utils import path_template, maybe_transform, async_maybe_transform from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource from ..._response import ( @@ -85,7 +85,7 @@ def create( if not user_id: raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}") return self._post( - f"/profiles/{user_id}", + path_template("/profiles/{user_id}", user_id=user_id), body=maybe_transform({"profile": profile}, profile_create_params.ProfileCreateParams), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout @@ -119,7 +119,7 @@ def retrieve( if not user_id: raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}") return self._get( - f"/profiles/{user_id}", + path_template("/profiles/{user_id}", user_id=user_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -156,7 +156,7 @@ def update( raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return self._patch( - f"/profiles/{user_id}", + path_template("/profiles/{user_id}", user_id=user_id), body=maybe_transform({"patch": patch}, profile_update_params.ProfileUpdateParams), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout @@ -191,7 +191,7 @@ def delete( raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return self._delete( - f"/profiles/{user_id}", + path_template("/profiles/{user_id}", user_id=user_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -229,7 +229,7 @@ def replace( if not user_id: raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}") return self._put( - f"/profiles/{user_id}", + path_template("/profiles/{user_id}", user_id=user_id), body=maybe_transform({"profile": profile}, profile_replace_params.ProfileReplaceParams), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout @@ -290,7 +290,7 @@ async def create( if not user_id: raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}") return await self._post( - f"/profiles/{user_id}", + path_template("/profiles/{user_id}", user_id=user_id), body=await async_maybe_transform({"profile": profile}, profile_create_params.ProfileCreateParams), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout @@ -324,7 +324,7 @@ async def retrieve( if not user_id: raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}") return await self._get( - f"/profiles/{user_id}", + path_template("/profiles/{user_id}", user_id=user_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -361,7 +361,7 @@ async def update( raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return await self._patch( - f"/profiles/{user_id}", + path_template("/profiles/{user_id}", user_id=user_id), body=await async_maybe_transform({"patch": patch}, profile_update_params.ProfileUpdateParams), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout @@ -396,7 +396,7 @@ async def delete( raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return await self._delete( - f"/profiles/{user_id}", + path_template("/profiles/{user_id}", user_id=user_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -434,7 +434,7 @@ async def replace( if not user_id: raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}") return await self._put( - f"/profiles/{user_id}", + path_template("/profiles/{user_id}", user_id=user_id), body=await async_maybe_transform({"profile": profile}, profile_replace_params.ProfileReplaceParams), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout diff --git a/src/courier/resources/requests.py b/src/courier/resources/requests.py index 677f793d..c2ddf98b 100644 --- a/src/courier/resources/requests.py +++ b/src/courier/resources/requests.py @@ -5,6 +5,7 @@ import httpx from .._types import Body, Query, Headers, NoneType, NotGiven, not_given +from .._utils import path_template from .._compat import cached_property from .._resource import SyncAPIResource, AsyncAPIResource from .._response import ( @@ -65,7 +66,7 @@ def archive( raise ValueError(f"Expected a non-empty value for `request_id` but received {request_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return self._put( - f"/requests/{request_id}/archive", + path_template("/requests/{request_id}/archive", request_id=request_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -120,7 +121,7 @@ async def archive( raise ValueError(f"Expected a non-empty value for `request_id` but received {request_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return await self._put( - f"/requests/{request_id}/archive", + path_template("/requests/{request_id}/archive", request_id=request_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), diff --git a/src/courier/resources/tenants/preferences/items.py b/src/courier/resources/tenants/preferences/items.py index 30bef4d3..91d35dc4 100644 --- a/src/courier/resources/tenants/preferences/items.py +++ b/src/courier/resources/tenants/preferences/items.py @@ -8,7 +8,7 @@ import httpx from ...._types import Body, Omit, Query, Headers, NoneType, NotGiven, omit, not_given -from ...._utils import maybe_transform, async_maybe_transform +from ...._utils import path_template, maybe_transform, async_maybe_transform from ...._compat import cached_property from ...._resource import SyncAPIResource, AsyncAPIResource from ...._response import ( @@ -83,7 +83,9 @@ def update( raise ValueError(f"Expected a non-empty value for `topic_id` but received {topic_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return self._put( - f"/tenants/{tenant_id}/default_preferences/items/{topic_id}", + path_template( + "/tenants/{tenant_id}/default_preferences/items/{topic_id}", tenant_id=tenant_id, topic_id=topic_id + ), body=maybe_transform( { "status": status, @@ -128,7 +130,9 @@ def delete( raise ValueError(f"Expected a non-empty value for `topic_id` but received {topic_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return self._delete( - f"/tenants/{tenant_id}/default_preferences/items/{topic_id}", + path_template( + "/tenants/{tenant_id}/default_preferences/items/{topic_id}", tenant_id=tenant_id, topic_id=topic_id + ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -195,7 +199,9 @@ async def update( raise ValueError(f"Expected a non-empty value for `topic_id` but received {topic_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return await self._put( - f"/tenants/{tenant_id}/default_preferences/items/{topic_id}", + path_template( + "/tenants/{tenant_id}/default_preferences/items/{topic_id}", tenant_id=tenant_id, topic_id=topic_id + ), body=await async_maybe_transform( { "status": status, @@ -240,7 +246,9 @@ async def delete( raise ValueError(f"Expected a non-empty value for `topic_id` but received {topic_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return await self._delete( - f"/tenants/{tenant_id}/default_preferences/items/{topic_id}", + path_template( + "/tenants/{tenant_id}/default_preferences/items/{topic_id}", tenant_id=tenant_id, topic_id=topic_id + ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), diff --git a/src/courier/resources/tenants/templates/templates.py b/src/courier/resources/tenants/templates/templates.py index 87ad2d6a..12a3733b 100644 --- a/src/courier/resources/tenants/templates/templates.py +++ b/src/courier/resources/tenants/templates/templates.py @@ -15,7 +15,7 @@ AsyncVersionsResourceWithStreamingResponse, ) from ...._types import Body, Omit, Query, Headers, NotGiven, omit, not_given -from ...._utils import maybe_transform, async_maybe_transform +from ...._utils import path_template, maybe_transform, async_maybe_transform from ...._compat import cached_property from ...._resource import SyncAPIResource, AsyncAPIResource from ...._response import ( @@ -88,7 +88,7 @@ def retrieve( if not template_id: raise ValueError(f"Expected a non-empty value for `template_id` but received {template_id!r}") return self._get( - f"/tenants/{tenant_id}/templates/{template_id}", + path_template("/tenants/{tenant_id}/templates/{template_id}", tenant_id=tenant_id, template_id=template_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -127,7 +127,7 @@ def list( if not tenant_id: raise ValueError(f"Expected a non-empty value for `tenant_id` but received {tenant_id!r}") return self._get( - f"/tenants/{tenant_id}/templates", + path_template("/tenants/{tenant_id}/templates", tenant_id=tenant_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, @@ -180,7 +180,9 @@ def publish( if not template_id: raise ValueError(f"Expected a non-empty value for `template_id` but received {template_id!r}") return self._post( - f"/tenants/{tenant_id}/templates/{template_id}/publish", + path_template( + "/tenants/{tenant_id}/templates/{template_id}/publish", tenant_id=tenant_id, template_id=template_id + ), body=maybe_transform({"version": version}, template_publish_params.TemplatePublishParams), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout @@ -231,7 +233,7 @@ def replace( if not template_id: raise ValueError(f"Expected a non-empty value for `template_id` but received {template_id!r}") return self._put( - f"/tenants/{tenant_id}/templates/{template_id}", + path_template("/tenants/{tenant_id}/templates/{template_id}", tenant_id=tenant_id, template_id=template_id), body=maybe_transform( { "template": template, @@ -299,7 +301,7 @@ async def retrieve( if not template_id: raise ValueError(f"Expected a non-empty value for `template_id` but received {template_id!r}") return await self._get( - f"/tenants/{tenant_id}/templates/{template_id}", + path_template("/tenants/{tenant_id}/templates/{template_id}", tenant_id=tenant_id, template_id=template_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -338,7 +340,7 @@ async def list( if not tenant_id: raise ValueError(f"Expected a non-empty value for `tenant_id` but received {tenant_id!r}") return await self._get( - f"/tenants/{tenant_id}/templates", + path_template("/tenants/{tenant_id}/templates", tenant_id=tenant_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, @@ -391,7 +393,9 @@ async def publish( if not template_id: raise ValueError(f"Expected a non-empty value for `template_id` but received {template_id!r}") return await self._post( - f"/tenants/{tenant_id}/templates/{template_id}/publish", + path_template( + "/tenants/{tenant_id}/templates/{template_id}/publish", tenant_id=tenant_id, template_id=template_id + ), body=await async_maybe_transform({"version": version}, template_publish_params.TemplatePublishParams), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout @@ -442,7 +446,7 @@ async def replace( if not template_id: raise ValueError(f"Expected a non-empty value for `template_id` but received {template_id!r}") return await self._put( - f"/tenants/{tenant_id}/templates/{template_id}", + path_template("/tenants/{tenant_id}/templates/{template_id}", tenant_id=tenant_id, template_id=template_id), body=await async_maybe_transform( { "template": template, diff --git a/src/courier/resources/tenants/templates/versions.py b/src/courier/resources/tenants/templates/versions.py index bcbef612..8b941609 100644 --- a/src/courier/resources/tenants/templates/versions.py +++ b/src/courier/resources/tenants/templates/versions.py @@ -5,6 +5,7 @@ import httpx from ...._types import Body, Query, Headers, NotGiven, not_given +from ...._utils import path_template from ...._compat import cached_property from ...._resource import SyncAPIResource, AsyncAPIResource from ...._response import ( @@ -77,7 +78,12 @@ def retrieve( if not version: raise ValueError(f"Expected a non-empty value for `version` but received {version!r}") return self._get( - f"/tenants/{tenant_id}/templates/{template_id}/versions/{version}", + path_template( + "/tenants/{tenant_id}/templates/{template_id}/versions/{version}", + tenant_id=tenant_id, + template_id=template_id, + version=version, + ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -143,7 +149,12 @@ async def retrieve( if not version: raise ValueError(f"Expected a non-empty value for `version` but received {version!r}") return await self._get( - f"/tenants/{tenant_id}/templates/{template_id}/versions/{version}", + path_template( + "/tenants/{tenant_id}/templates/{template_id}/versions/{version}", + tenant_id=tenant_id, + template_id=template_id, + version=version, + ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), diff --git a/src/courier/resources/tenants/tenants.py b/src/courier/resources/tenants/tenants.py index c1fd3ea3..1c0d55b9 100644 --- a/src/courier/resources/tenants/tenants.py +++ b/src/courier/resources/tenants/tenants.py @@ -8,7 +8,7 @@ from ...types import tenant_list_params, tenant_update_params, tenant_list_users_params from ..._types import Body, Omit, Query, Headers, NoneType, NotGiven, omit, not_given -from ..._utils import maybe_transform, async_maybe_transform +from ..._utils import path_template, maybe_transform, async_maybe_transform from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource from ..._response import ( @@ -96,7 +96,7 @@ def retrieve( if not tenant_id: raise ValueError(f"Expected a non-empty value for `tenant_id` but received {tenant_id!r}") return self._get( - f"/tenants/{tenant_id}", + path_template("/tenants/{tenant_id}", tenant_id=tenant_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -148,7 +148,7 @@ def update( if not tenant_id: raise ValueError(f"Expected a non-empty value for `tenant_id` but received {tenant_id!r}") return self._put( - f"/tenants/{tenant_id}", + path_template("/tenants/{tenant_id}", tenant_id=tenant_id), body=maybe_transform( { "name": name, @@ -243,7 +243,7 @@ def delete( raise ValueError(f"Expected a non-empty value for `tenant_id` but received {tenant_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return self._delete( - f"/tenants/{tenant_id}", + path_template("/tenants/{tenant_id}", tenant_id=tenant_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -282,7 +282,7 @@ def list_users( if not tenant_id: raise ValueError(f"Expected a non-empty value for `tenant_id` but received {tenant_id!r}") return self._get( - f"/tenants/{tenant_id}/users", + path_template("/tenants/{tenant_id}/users", tenant_id=tenant_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, @@ -354,7 +354,7 @@ async def retrieve( if not tenant_id: raise ValueError(f"Expected a non-empty value for `tenant_id` but received {tenant_id!r}") return await self._get( - f"/tenants/{tenant_id}", + path_template("/tenants/{tenant_id}", tenant_id=tenant_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -406,7 +406,7 @@ async def update( if not tenant_id: raise ValueError(f"Expected a non-empty value for `tenant_id` but received {tenant_id!r}") return await self._put( - f"/tenants/{tenant_id}", + path_template("/tenants/{tenant_id}", tenant_id=tenant_id), body=await async_maybe_transform( { "name": name, @@ -501,7 +501,7 @@ async def delete( raise ValueError(f"Expected a non-empty value for `tenant_id` but received {tenant_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return await self._delete( - f"/tenants/{tenant_id}", + path_template("/tenants/{tenant_id}", tenant_id=tenant_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -540,7 +540,7 @@ async def list_users( if not tenant_id: raise ValueError(f"Expected a non-empty value for `tenant_id` but received {tenant_id!r}") return await self._get( - f"/tenants/{tenant_id}/users", + path_template("/tenants/{tenant_id}/users", tenant_id=tenant_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, diff --git a/src/courier/resources/translations.py b/src/courier/resources/translations.py index cd3fed95..f4b1cfd9 100644 --- a/src/courier/resources/translations.py +++ b/src/courier/resources/translations.py @@ -6,7 +6,7 @@ from ..types import translation_update_params from .._types import Body, Query, Headers, NoneType, NotGiven, not_given -from .._utils import maybe_transform, async_maybe_transform +from .._utils import path_template, maybe_transform, async_maybe_transform from .._compat import cached_property from .._resource import SyncAPIResource, AsyncAPIResource from .._response import ( @@ -69,7 +69,7 @@ def retrieve( if not locale: raise ValueError(f"Expected a non-empty value for `locale` but received {locale!r}") return self._get( - f"/translations/{domain}/{locale}", + path_template("/translations/{domain}/{locale}", domain=domain, locale=locale), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -107,7 +107,7 @@ def update( raise ValueError(f"Expected a non-empty value for `locale` but received {locale!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return self._put( - f"/translations/{domain}/{locale}", + path_template("/translations/{domain}/{locale}", domain=domain, locale=locale), body=maybe_transform(body, translation_update_params.TranslationUpdateParams), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout @@ -165,7 +165,7 @@ async def retrieve( if not locale: raise ValueError(f"Expected a non-empty value for `locale` but received {locale!r}") return await self._get( - f"/translations/{domain}/{locale}", + path_template("/translations/{domain}/{locale}", domain=domain, locale=locale), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -203,7 +203,7 @@ async def update( raise ValueError(f"Expected a non-empty value for `locale` but received {locale!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return await self._put( - f"/translations/{domain}/{locale}", + path_template("/translations/{domain}/{locale}", domain=domain, locale=locale), body=await async_maybe_transform(body, translation_update_params.TranslationUpdateParams), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout diff --git a/src/courier/resources/users/preferences.py b/src/courier/resources/users/preferences.py index 2c05bc71..eb7483d4 100644 --- a/src/courier/resources/users/preferences.py +++ b/src/courier/resources/users/preferences.py @@ -7,7 +7,7 @@ import httpx from ..._types import Body, Omit, Query, Headers, NotGiven, omit, not_given -from ..._utils import maybe_transform, async_maybe_transform +from ..._utils import path_template, maybe_transform, async_maybe_transform from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource from ..._response import ( @@ -78,7 +78,7 @@ def retrieve( if not user_id: raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}") return self._get( - f"/users/{user_id}/preferences", + path_template("/users/{user_id}/preferences", user_id=user_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, @@ -121,7 +121,7 @@ def retrieve_topic( if not topic_id: raise ValueError(f"Expected a non-empty value for `topic_id` but received {topic_id!r}") return self._get( - f"/users/{user_id}/preferences/{topic_id}", + path_template("/users/{user_id}/preferences/{topic_id}", user_id=user_id, topic_id=topic_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, @@ -167,7 +167,7 @@ def update_or_create_topic( if not topic_id: raise ValueError(f"Expected a non-empty value for `topic_id` but received {topic_id!r}") return self._put( - f"/users/{user_id}/preferences/{topic_id}", + path_template("/users/{user_id}/preferences/{topic_id}", user_id=user_id, topic_id=topic_id), body=maybe_transform( {"topic": topic}, preference_update_or_create_topic_params.PreferenceUpdateOrCreateTopicParams ), @@ -234,7 +234,7 @@ async def retrieve( if not user_id: raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}") return await self._get( - f"/users/{user_id}/preferences", + path_template("/users/{user_id}/preferences", user_id=user_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, @@ -279,7 +279,7 @@ async def retrieve_topic( if not topic_id: raise ValueError(f"Expected a non-empty value for `topic_id` but received {topic_id!r}") return await self._get( - f"/users/{user_id}/preferences/{topic_id}", + path_template("/users/{user_id}/preferences/{topic_id}", user_id=user_id, topic_id=topic_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, @@ -325,7 +325,7 @@ async def update_or_create_topic( if not topic_id: raise ValueError(f"Expected a non-empty value for `topic_id` but received {topic_id!r}") return await self._put( - f"/users/{user_id}/preferences/{topic_id}", + path_template("/users/{user_id}/preferences/{topic_id}", user_id=user_id, topic_id=topic_id), body=await async_maybe_transform( {"topic": topic}, preference_update_or_create_topic_params.PreferenceUpdateOrCreateTopicParams ), diff --git a/src/courier/resources/users/tenants.py b/src/courier/resources/users/tenants.py index 83f913cc..64b9fb56 100644 --- a/src/courier/resources/users/tenants.py +++ b/src/courier/resources/users/tenants.py @@ -7,7 +7,7 @@ import httpx from ..._types import Body, Omit, Query, Headers, NoneType, NotGiven, omit, not_given -from ..._utils import maybe_transform, async_maybe_transform +from ..._utils import path_template, maybe_transform, async_maybe_transform from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource from ..._response import ( @@ -76,7 +76,7 @@ def list( if not user_id: raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}") return self._get( - f"/users/{user_id}/tenants", + path_template("/users/{user_id}/tenants", user_id=user_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, @@ -124,7 +124,7 @@ def add_multiple( raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return self._put( - f"/users/{user_id}/tenants", + path_template("/users/{user_id}/tenants", user_id=user_id), body=maybe_transform({"tenants": tenants}, tenant_add_multiple_params.TenantAddMultipleParams), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout @@ -166,7 +166,7 @@ def add_single( raise ValueError(f"Expected a non-empty value for `tenant_id` but received {tenant_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return self._put( - f"/users/{user_id}/tenants/{tenant_id}", + path_template("/users/{user_id}/tenants/{tenant_id}", user_id=user_id, tenant_id=tenant_id), body=maybe_transform({"profile": profile}, tenant_add_single_params.TenantAddSingleParams), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout @@ -201,7 +201,7 @@ def remove_all( raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return self._delete( - f"/users/{user_id}/tenants", + path_template("/users/{user_id}/tenants", user_id=user_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -238,7 +238,7 @@ def remove_single( raise ValueError(f"Expected a non-empty value for `tenant_id` but received {tenant_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return self._delete( - f"/users/{user_id}/tenants/{tenant_id}", + path_template("/users/{user_id}/tenants/{tenant_id}", user_id=user_id, tenant_id=tenant_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -298,7 +298,7 @@ async def list( if not user_id: raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}") return await self._get( - f"/users/{user_id}/tenants", + path_template("/users/{user_id}/tenants", user_id=user_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, @@ -346,7 +346,7 @@ async def add_multiple( raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return await self._put( - f"/users/{user_id}/tenants", + path_template("/users/{user_id}/tenants", user_id=user_id), body=await async_maybe_transform({"tenants": tenants}, tenant_add_multiple_params.TenantAddMultipleParams), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout @@ -388,7 +388,7 @@ async def add_single( raise ValueError(f"Expected a non-empty value for `tenant_id` but received {tenant_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return await self._put( - f"/users/{user_id}/tenants/{tenant_id}", + path_template("/users/{user_id}/tenants/{tenant_id}", user_id=user_id, tenant_id=tenant_id), body=await async_maybe_transform({"profile": profile}, tenant_add_single_params.TenantAddSingleParams), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout @@ -423,7 +423,7 @@ async def remove_all( raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return await self._delete( - f"/users/{user_id}/tenants", + path_template("/users/{user_id}/tenants", user_id=user_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -460,7 +460,7 @@ async def remove_single( raise ValueError(f"Expected a non-empty value for `tenant_id` but received {tenant_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return await self._delete( - f"/users/{user_id}/tenants/{tenant_id}", + path_template("/users/{user_id}/tenants/{tenant_id}", user_id=user_id, tenant_id=tenant_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), diff --git a/src/courier/resources/users/tokens.py b/src/courier/resources/users/tokens.py index 047a1988..964065af 100644 --- a/src/courier/resources/users/tokens.py +++ b/src/courier/resources/users/tokens.py @@ -8,7 +8,7 @@ import httpx from ..._types import Body, Omit, Query, Headers, NoneType, NotGiven, omit, not_given -from ..._utils import maybe_transform, async_maybe_transform +from ..._utils import path_template, maybe_transform, async_maybe_transform from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource from ..._response import ( @@ -74,7 +74,7 @@ def retrieve( if not token: raise ValueError(f"Expected a non-empty value for `token` but received {token!r}") return self._get( - f"/users/{user_id}/tokens/{token}", + path_template("/users/{user_id}/tokens/{token}", user_id=user_id, token=token), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -112,7 +112,7 @@ def update( raise ValueError(f"Expected a non-empty value for `token` but received {token!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return self._patch( - f"/users/{user_id}/tokens/{token}", + path_template("/users/{user_id}/tokens/{token}", user_id=user_id, token=token), body=maybe_transform({"patch": patch}, token_update_params.TokenUpdateParams), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout @@ -146,7 +146,7 @@ def list( if not user_id: raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}") return self._get( - f"/users/{user_id}/tokens", + path_template("/users/{user_id}/tokens", user_id=user_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -183,7 +183,7 @@ def delete( raise ValueError(f"Expected a non-empty value for `token` but received {token!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return self._delete( - f"/users/{user_id}/tokens/{token}", + path_template("/users/{user_id}/tokens/{token}", user_id=user_id, token=token), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -217,7 +217,7 @@ def add_multiple( raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return self._put( - f"/users/{user_id}/tokens", + path_template("/users/{user_id}/tokens", user_id=user_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -268,7 +268,7 @@ def add_single( raise ValueError(f"Expected a non-empty value for `token` but received {token!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return self._put( - f"/users/{user_id}/tokens/{token}", + path_template("/users/{user_id}/tokens/{token}", user_id=user_id, token=token), body=maybe_transform( { "provider_key": provider_key, @@ -335,7 +335,7 @@ async def retrieve( if not token: raise ValueError(f"Expected a non-empty value for `token` but received {token!r}") return await self._get( - f"/users/{user_id}/tokens/{token}", + path_template("/users/{user_id}/tokens/{token}", user_id=user_id, token=token), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -373,7 +373,7 @@ async def update( raise ValueError(f"Expected a non-empty value for `token` but received {token!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return await self._patch( - f"/users/{user_id}/tokens/{token}", + path_template("/users/{user_id}/tokens/{token}", user_id=user_id, token=token), body=await async_maybe_transform({"patch": patch}, token_update_params.TokenUpdateParams), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout @@ -407,7 +407,7 @@ async def list( if not user_id: raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}") return await self._get( - f"/users/{user_id}/tokens", + path_template("/users/{user_id}/tokens", user_id=user_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -444,7 +444,7 @@ async def delete( raise ValueError(f"Expected a non-empty value for `token` but received {token!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return await self._delete( - f"/users/{user_id}/tokens/{token}", + path_template("/users/{user_id}/tokens/{token}", user_id=user_id, token=token), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -478,7 +478,7 @@ async def add_multiple( raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return await self._put( - f"/users/{user_id}/tokens", + path_template("/users/{user_id}/tokens", user_id=user_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -529,7 +529,7 @@ async def add_single( raise ValueError(f"Expected a non-empty value for `token` but received {token!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return await self._put( - f"/users/{user_id}/tokens/{token}", + path_template("/users/{user_id}/tokens/{token}", user_id=user_id, token=token), body=await async_maybe_transform( { "provider_key": provider_key, diff --git a/src/courier/types/__init__.py b/src/courier/types/__init__.py index 53a18548..d9786358 100644 --- a/src/courier/types/__init__.py +++ b/src/courier/types/__init__.py @@ -168,24 +168,34 @@ from .bulk_retrieve_job_response import BulkRetrieveJobResponse as BulkRetrieveJobResponse from .inbound_bulk_message_param import InboundBulkMessageParam as InboundBulkMessageParam from .inbound_track_event_params import InboundTrackEventParams as InboundTrackEventParams +from .notification_create_params import NotificationCreateParams as NotificationCreateParams from .notification_list_response import NotificationListResponse as NotificationListResponse from .tenant_list_users_response import TenantListUsersResponse as TenantListUsersResponse from .brand_settings_in_app_param import BrandSettingsInAppParam as BrandSettingsInAppParam +from .notification_replace_params import NotificationReplaceParams as NotificationReplaceParams from .tenant_template_input_param import TenantTemplateInputParam as TenantTemplateInputParam from .audience_list_members_params import AudienceListMembersParams as AudienceListMembersParams from .inbound_track_event_response import InboundTrackEventResponse as InboundTrackEventResponse +from .notification_retrieve_params import NotificationRetrieveParams as NotificationRetrieveParams from .put_tenant_template_response import PutTenantTemplateResponse as PutTenantTemplateResponse from .subscription_topic_new_param import SubscriptionTopicNewParam as SubscriptionTopicNewParam +from .notification_template_payload import NotificationTemplatePayload as NotificationTemplatePayload +from .notification_template_summary import NotificationTemplateSummary as NotificationTemplateSummary from .translation_retrieve_response import TranslationRetrieveResponse as TranslationRetrieveResponse from .audience_list_members_response import AudienceListMembersResponse as AudienceListMembersResponse from .inbound_bulk_message_user_param import InboundBulkMessageUserParam as InboundBulkMessageUserParam from .base_template_tenant_association import BaseTemplateTenantAssociation as BaseTemplateTenantAssociation from .automation_template_list_response import AutomationTemplateListResponse as AutomationTemplateListResponse from .put_subscriptions_recipient_param import PutSubscriptionsRecipientParam as PutSubscriptionsRecipientParam +from .notification_template_get_response import NotificationTemplateGetResponse as NotificationTemplateGetResponse +from .notification_template_payload_param import NotificationTemplatePayloadParam as NotificationTemplatePayloadParam from .post_tenant_template_publish_response import ( PostTenantTemplatePublishResponse as PostTenantTemplatePublishResponse, ) from .subscribe_to_lists_request_item_param import SubscribeToListsRequestItemParam as SubscribeToListsRequestItemParam +from .notification_template_mutation_response import ( + NotificationTemplateMutationResponse as NotificationTemplateMutationResponse, +) # Rebuild cyclical models only after all modules are imported. # This ensures that, when building the deferred (due to cyclical references) model schema, diff --git a/src/courier/types/notification_create_params.py b/src/courier/types/notification_create_params.py new file mode 100644 index 00000000..b64d3a19 --- /dev/null +++ b/src/courier/types/notification_create_params.py @@ -0,0 +1,24 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing_extensions import Literal, Required, TypedDict + +from .notification_template_payload_param import NotificationTemplatePayloadParam + +__all__ = ["NotificationCreateParams"] + + +class NotificationCreateParams(TypedDict, total=False): + notification: Required[NotificationTemplatePayloadParam] + """ + Full document shape used in POST and PUT request bodies, and returned inside the + GET response envelope. + """ + + state: Literal["DRAFT", "PUBLISHED"] + """Template state after creation. + + Case-insensitive input, normalized to uppercase in the response. Defaults to + "DRAFT". + """ diff --git a/src/courier/types/notification_list_params.py b/src/courier/types/notification_list_params.py index 6465dcb9..26106e9a 100644 --- a/src/courier/types/notification_list_params.py +++ b/src/courier/types/notification_list_params.py @@ -10,6 +10,10 @@ class NotificationListParams(TypedDict, total=False): cursor: Optional[str] + """Opaque pagination cursor from a previous response. Omit for the first page.""" + + event_id: str + """Filter to templates linked to this event map ID.""" notes: Optional[bool] - """Retrieve the notes from the Notification template settings.""" + """Include template notes in the response. Only applies to legacy templates.""" diff --git a/src/courier/types/notification_list_response.py b/src/courier/types/notification_list_response.py index 7e132e65..717e07d4 100644 --- a/src/courier/types/notification_list_response.py +++ b/src/courier/types/notification_list_response.py @@ -2,25 +2,33 @@ from __future__ import annotations -from typing import List, Optional +from typing import List, Union, Optional +from typing_extensions import TypeAlias from .._models import BaseModel from .shared.paging import Paging +from .notification_template_summary import NotificationTemplateSummary -__all__ = ["NotificationListResponse", "Result", "ResultTags", "ResultTagsData"] +__all__ = [ + "NotificationListResponse", + "Result", + "ResultNotification", + "ResultNotificationTags", + "ResultNotificationTagsData", +] -class ResultTagsData(BaseModel): +class ResultNotificationTagsData(BaseModel): id: str name: str -class ResultTags(BaseModel): - data: List[ResultTagsData] +class ResultNotificationTags(BaseModel): + data: List[ResultNotificationTagsData] -class Result(BaseModel): +class ResultNotification(BaseModel): id: str created_at: int @@ -36,15 +44,19 @@ class Result(BaseModel): updated_at: int - tags: Optional[ResultTags] = None + tags: Optional[ResultNotificationTags] = None title: Optional[str] = None +Result: TypeAlias = Union[ResultNotification, NotificationTemplateSummary] + + class NotificationListResponse(BaseModel): paging: Paging results: List[Result] + """Notification templates in this workspace.""" from .shared.message_routing import MessageRouting diff --git a/src/courier/types/notification_replace_params.py b/src/courier/types/notification_replace_params.py new file mode 100644 index 00000000..e48eb1b6 --- /dev/null +++ b/src/courier/types/notification_replace_params.py @@ -0,0 +1,24 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing_extensions import Literal, Required, TypedDict + +from .notification_template_payload_param import NotificationTemplatePayloadParam + +__all__ = ["NotificationReplaceParams"] + + +class NotificationReplaceParams(TypedDict, total=False): + notification: Required[NotificationTemplatePayloadParam] + """ + Full document shape used in POST and PUT request bodies, and returned inside the + GET response envelope. + """ + + state: Literal["DRAFT", "PUBLISHED"] + """Template state after update. + + Case-insensitive input, normalized to uppercase in the response. Defaults to + "DRAFT". + """ diff --git a/src/courier/types/notification_retrieve_params.py b/src/courier/types/notification_retrieve_params.py new file mode 100644 index 00000000..78e933aa --- /dev/null +++ b/src/courier/types/notification_retrieve_params.py @@ -0,0 +1,16 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing_extensions import TypedDict + +__all__ = ["NotificationRetrieveParams"] + + +class NotificationRetrieveParams(TypedDict, total=False): + version: str + """Version to retrieve. + + One of "draft", "published", or a version string like "v001". Defaults to + "published". + """ diff --git a/src/courier/types/notification_template_get_response.py b/src/courier/types/notification_template_get_response.py new file mode 100644 index 00000000..8ec00092 --- /dev/null +++ b/src/courier/types/notification_template_get_response.py @@ -0,0 +1,46 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import Optional +from typing_extensions import Literal + +from .._models import BaseModel +from .notification_template_payload import NotificationTemplatePayload + +__all__ = ["NotificationTemplateGetResponse", "Notification"] + + +class Notification(NotificationTemplatePayload): + """ + Full document shape used in POST and PUT request bodies, and returned inside the GET response envelope. + """ + + id: str + """The template ID.""" + + +class NotificationTemplateGetResponse(BaseModel): + """Envelope response for GET /notifications/{id}. + + The notification object mirrors the POST/PUT input shape. Nullable fields return null when unset. + """ + + created: int + """Epoch milliseconds when the template was created.""" + + creator: str + """User ID of the creator.""" + + notification: Notification + """ + Full document shape used in POST and PUT request bodies, and returned inside the + GET response envelope. + """ + + state: Literal["DRAFT", "PUBLISHED"] + """The template state. Always uppercase.""" + + updated: Optional[int] = None + """Epoch milliseconds of last update.""" + + updater: Optional[str] = None + """User ID of the last updater.""" diff --git a/src/courier/types/notification_template_mutation_response.py b/src/courier/types/notification_template_mutation_response.py new file mode 100644 index 00000000..d67e4951 --- /dev/null +++ b/src/courier/types/notification_template_mutation_response.py @@ -0,0 +1,21 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing_extensions import Literal + +from .._models import BaseModel + +__all__ = ["NotificationTemplateMutationResponse", "Notification"] + + +class Notification(BaseModel): + id: str + """The ID of the created or updated template.""" + + +class NotificationTemplateMutationResponse(BaseModel): + """Response returned by POST and PUT operations.""" + + notification: Notification + + state: Literal["DRAFT", "PUBLISHED"] + """The template state after the operation. Always uppercase.""" diff --git a/src/courier/types/notification_template_payload.py b/src/courier/types/notification_template_payload.py new file mode 100644 index 00000000..dd6d89fb --- /dev/null +++ b/src/courier/types/notification_template_payload.py @@ -0,0 +1,50 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import List, Optional + +from .._models import BaseModel +from .shared.elemental_content import ElementalContent + +__all__ = ["NotificationTemplatePayload", "Brand", "Routing", "Subscription"] + + +class Brand(BaseModel): + """Brand reference, or null for no brand.""" + + id: str + + +class Routing(BaseModel): + """Routing strategy reference, or null for none.""" + + strategy_id: str + + +class Subscription(BaseModel): + """Subscription topic reference, or null for none.""" + + topic_id: str + + +class NotificationTemplatePayload(BaseModel): + """ + Full document shape used in POST and PUT request bodies, and returned inside the GET response envelope. + """ + + brand: Optional[Brand] = None + """Brand reference, or null for no brand.""" + + content: ElementalContent + """Elemental content definition.""" + + name: str + """Display name for the template.""" + + routing: Optional[Routing] = None + """Routing strategy reference, or null for none.""" + + subscription: Optional[Subscription] = None + """Subscription topic reference, or null for none.""" + + tags: List[str] + """Tags for categorization. Send empty array for none.""" diff --git a/src/courier/types/notification_template_payload_param.py b/src/courier/types/notification_template_payload_param.py new file mode 100644 index 00000000..258eb93d --- /dev/null +++ b/src/courier/types/notification_template_payload_param.py @@ -0,0 +1,53 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing import Optional +from typing_extensions import Required, TypedDict + +from .._types import SequenceNotStr +from .shared_params.elemental_content import ElementalContent + +__all__ = ["NotificationTemplatePayloadParam", "Brand", "Routing", "Subscription"] + + +class Brand(TypedDict, total=False): + """Brand reference, or null for no brand.""" + + id: Required[str] + + +class Routing(TypedDict, total=False): + """Routing strategy reference, or null for none.""" + + strategy_id: Required[str] + + +class Subscription(TypedDict, total=False): + """Subscription topic reference, or null for none.""" + + topic_id: Required[str] + + +class NotificationTemplatePayloadParam(TypedDict, total=False): + """ + Full document shape used in POST and PUT request bodies, and returned inside the GET response envelope. + """ + + brand: Required[Optional[Brand]] + """Brand reference, or null for no brand.""" + + content: Required[ElementalContent] + """Elemental content definition.""" + + name: Required[str] + """Display name for the template.""" + + routing: Required[Optional[Routing]] + """Routing strategy reference, or null for none.""" + + subscription: Required[Optional[Subscription]] + """Subscription topic reference, or null for none.""" + + tags: Required[SequenceNotStr[str]] + """Tags for categorization. Send empty array for none.""" diff --git a/src/courier/types/notification_template_summary.py b/src/courier/types/notification_template_summary.py new file mode 100644 index 00000000..3e4d617c --- /dev/null +++ b/src/courier/types/notification_template_summary.py @@ -0,0 +1,32 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import List, Optional +from typing_extensions import Literal + +from .._models import BaseModel + +__all__ = ["NotificationTemplateSummary"] + + +class NotificationTemplateSummary(BaseModel): + """V2 (CDS) template summary returned in list responses.""" + + id: str + + created: int + """Epoch milliseconds when the template was created.""" + + creator: str + """User ID of the creator.""" + + name: str + + state: Literal["DRAFT", "PUBLISHED"] + + tags: List[str] + + updated: Optional[int] = None + """Epoch milliseconds of last update.""" + + updater: Optional[str] = None + """User ID of the last updater.""" diff --git a/tests/api_resources/test_notifications.py b/tests/api_resources/test_notifications.py index 9e16a9f7..3ba35566 100644 --- a/tests/api_resources/test_notifications.py +++ b/tests/api_resources/test_notifications.py @@ -9,7 +9,12 @@ from courier import Courier, AsyncCourier from tests.utils import assert_matches_type -from courier.types import NotificationGetContent, NotificationListResponse +from courier.types import ( + NotificationGetContent, + NotificationListResponse, + NotificationTemplateGetResponse, + NotificationTemplateMutationResponse, +) base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") @@ -17,6 +22,140 @@ class TestNotifications: parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_method_create(self, client: Courier) -> None: + notification = client.notifications.create( + notification={ + "brand": {"id": "brand_abc"}, + "content": { + "elements": [{}], + "version": "2022-01-01", + }, + "name": "Welcome Email", + "routing": {"strategy_id": "rs_123"}, + "subscription": {"topic_id": "marketing"}, + "tags": ["onboarding", "welcome"], + }, + ) + assert_matches_type(NotificationTemplateMutationResponse, notification, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_method_create_with_all_params(self, client: Courier) -> None: + notification = client.notifications.create( + notification={ + "brand": {"id": "brand_abc"}, + "content": { + "elements": [{"type": "channel"}], + "version": "2022-01-01", + }, + "name": "Welcome Email", + "routing": {"strategy_id": "rs_123"}, + "subscription": {"topic_id": "marketing"}, + "tags": ["onboarding", "welcome"], + }, + state="DRAFT", + ) + assert_matches_type(NotificationTemplateMutationResponse, notification, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_raw_response_create(self, client: Courier) -> None: + response = client.notifications.with_raw_response.create( + notification={ + "brand": {"id": "brand_abc"}, + "content": { + "elements": [{}], + "version": "2022-01-01", + }, + "name": "Welcome Email", + "routing": {"strategy_id": "rs_123"}, + "subscription": {"topic_id": "marketing"}, + "tags": ["onboarding", "welcome"], + }, + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + notification = response.parse() + assert_matches_type(NotificationTemplateMutationResponse, notification, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_streaming_response_create(self, client: Courier) -> None: + with client.notifications.with_streaming_response.create( + notification={ + "brand": {"id": "brand_abc"}, + "content": { + "elements": [{}], + "version": "2022-01-01", + }, + "name": "Welcome Email", + "routing": {"strategy_id": "rs_123"}, + "subscription": {"topic_id": "marketing"}, + "tags": ["onboarding", "welcome"], + }, + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + notification = response.parse() + assert_matches_type(NotificationTemplateMutationResponse, notification, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_method_retrieve(self, client: Courier) -> None: + notification = client.notifications.retrieve( + id="id", + ) + assert_matches_type(NotificationTemplateGetResponse, notification, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_method_retrieve_with_all_params(self, client: Courier) -> None: + notification = client.notifications.retrieve( + id="id", + version="version", + ) + assert_matches_type(NotificationTemplateGetResponse, notification, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_raw_response_retrieve(self, client: Courier) -> None: + response = client.notifications.with_raw_response.retrieve( + id="id", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + notification = response.parse() + assert_matches_type(NotificationTemplateGetResponse, notification, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_streaming_response_retrieve(self, client: Courier) -> None: + with client.notifications.with_streaming_response.retrieve( + id="id", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + notification = response.parse() + assert_matches_type(NotificationTemplateGetResponse, notification, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_path_params_retrieve(self, client: Courier) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `id` but received ''"): + client.notifications.with_raw_response.retrieve( + id="", + ) + @pytest.mark.skip(reason="Mock server tests are disabled") @parametrize def test_method_list(self, client: Courier) -> None: @@ -28,6 +167,7 @@ def test_method_list(self, client: Courier) -> None: def test_method_list_with_all_params(self, client: Courier) -> None: notification = client.notifications.list( cursor="cursor", + event_id="event_id", notes=True, ) assert_matches_type(NotificationListResponse, notification, path=["response"]) @@ -54,6 +194,196 @@ def test_streaming_response_list(self, client: Courier) -> None: assert cast(Any, response.is_closed) is True + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_method_archive(self, client: Courier) -> None: + notification = client.notifications.archive( + "id", + ) + assert notification is None + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_raw_response_archive(self, client: Courier) -> None: + response = client.notifications.with_raw_response.archive( + "id", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + notification = response.parse() + assert notification is None + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_streaming_response_archive(self, client: Courier) -> None: + with client.notifications.with_streaming_response.archive( + "id", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + notification = response.parse() + assert notification is None + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_path_params_archive(self, client: Courier) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `id` but received ''"): + client.notifications.with_raw_response.archive( + "", + ) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_method_publish(self, client: Courier) -> None: + notification = client.notifications.publish( + "id", + ) + assert notification is None + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_raw_response_publish(self, client: Courier) -> None: + response = client.notifications.with_raw_response.publish( + "id", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + notification = response.parse() + assert notification is None + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_streaming_response_publish(self, client: Courier) -> None: + with client.notifications.with_streaming_response.publish( + "id", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + notification = response.parse() + assert notification is None + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_path_params_publish(self, client: Courier) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `id` but received ''"): + client.notifications.with_raw_response.publish( + "", + ) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_method_replace(self, client: Courier) -> None: + notification = client.notifications.replace( + id="id", + notification={ + "brand": {"id": "id"}, + "content": { + "elements": [{}], + "version": "2022-01-01", + }, + "name": "Updated Name", + "routing": {"strategy_id": "strategy_id"}, + "subscription": {"topic_id": "topic_id"}, + "tags": ["updated"], + }, + ) + assert_matches_type(NotificationTemplateMutationResponse, notification, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_method_replace_with_all_params(self, client: Courier) -> None: + notification = client.notifications.replace( + id="id", + notification={ + "brand": {"id": "id"}, + "content": { + "elements": [{"type": "channel"}], + "version": "2022-01-01", + }, + "name": "Updated Name", + "routing": {"strategy_id": "strategy_id"}, + "subscription": {"topic_id": "topic_id"}, + "tags": ["updated"], + }, + state="PUBLISHED", + ) + assert_matches_type(NotificationTemplateMutationResponse, notification, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_raw_response_replace(self, client: Courier) -> None: + response = client.notifications.with_raw_response.replace( + id="id", + notification={ + "brand": {"id": "id"}, + "content": { + "elements": [{}], + "version": "2022-01-01", + }, + "name": "Updated Name", + "routing": {"strategy_id": "strategy_id"}, + "subscription": {"topic_id": "topic_id"}, + "tags": ["updated"], + }, + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + notification = response.parse() + assert_matches_type(NotificationTemplateMutationResponse, notification, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_streaming_response_replace(self, client: Courier) -> None: + with client.notifications.with_streaming_response.replace( + id="id", + notification={ + "brand": {"id": "id"}, + "content": { + "elements": [{}], + "version": "2022-01-01", + }, + "name": "Updated Name", + "routing": {"strategy_id": "strategy_id"}, + "subscription": {"topic_id": "topic_id"}, + "tags": ["updated"], + }, + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + notification = response.parse() + assert_matches_type(NotificationTemplateMutationResponse, notification, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_path_params_replace(self, client: Courier) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `id` but received ''"): + client.notifications.with_raw_response.replace( + id="", + notification={ + "brand": {"id": "id"}, + "content": { + "elements": [{}], + "version": "2022-01-01", + }, + "name": "Updated Name", + "routing": {"strategy_id": "strategy_id"}, + "subscription": {"topic_id": "topic_id"}, + "tags": ["updated"], + }, + ) + @pytest.mark.skip(reason="Mock server tests are disabled") @parametrize def test_method_retrieve_content(self, client: Courier) -> None: @@ -102,6 +432,140 @@ class TestAsyncNotifications: "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"] ) + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_method_create(self, async_client: AsyncCourier) -> None: + notification = await async_client.notifications.create( + notification={ + "brand": {"id": "brand_abc"}, + "content": { + "elements": [{}], + "version": "2022-01-01", + }, + "name": "Welcome Email", + "routing": {"strategy_id": "rs_123"}, + "subscription": {"topic_id": "marketing"}, + "tags": ["onboarding", "welcome"], + }, + ) + assert_matches_type(NotificationTemplateMutationResponse, notification, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_method_create_with_all_params(self, async_client: AsyncCourier) -> None: + notification = await async_client.notifications.create( + notification={ + "brand": {"id": "brand_abc"}, + "content": { + "elements": [{"type": "channel"}], + "version": "2022-01-01", + }, + "name": "Welcome Email", + "routing": {"strategy_id": "rs_123"}, + "subscription": {"topic_id": "marketing"}, + "tags": ["onboarding", "welcome"], + }, + state="DRAFT", + ) + assert_matches_type(NotificationTemplateMutationResponse, notification, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_raw_response_create(self, async_client: AsyncCourier) -> None: + response = await async_client.notifications.with_raw_response.create( + notification={ + "brand": {"id": "brand_abc"}, + "content": { + "elements": [{}], + "version": "2022-01-01", + }, + "name": "Welcome Email", + "routing": {"strategy_id": "rs_123"}, + "subscription": {"topic_id": "marketing"}, + "tags": ["onboarding", "welcome"], + }, + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + notification = await response.parse() + assert_matches_type(NotificationTemplateMutationResponse, notification, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_streaming_response_create(self, async_client: AsyncCourier) -> None: + async with async_client.notifications.with_streaming_response.create( + notification={ + "brand": {"id": "brand_abc"}, + "content": { + "elements": [{}], + "version": "2022-01-01", + }, + "name": "Welcome Email", + "routing": {"strategy_id": "rs_123"}, + "subscription": {"topic_id": "marketing"}, + "tags": ["onboarding", "welcome"], + }, + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + notification = await response.parse() + assert_matches_type(NotificationTemplateMutationResponse, notification, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_method_retrieve(self, async_client: AsyncCourier) -> None: + notification = await async_client.notifications.retrieve( + id="id", + ) + assert_matches_type(NotificationTemplateGetResponse, notification, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_method_retrieve_with_all_params(self, async_client: AsyncCourier) -> None: + notification = await async_client.notifications.retrieve( + id="id", + version="version", + ) + assert_matches_type(NotificationTemplateGetResponse, notification, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_raw_response_retrieve(self, async_client: AsyncCourier) -> None: + response = await async_client.notifications.with_raw_response.retrieve( + id="id", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + notification = await response.parse() + assert_matches_type(NotificationTemplateGetResponse, notification, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_streaming_response_retrieve(self, async_client: AsyncCourier) -> None: + async with async_client.notifications.with_streaming_response.retrieve( + id="id", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + notification = await response.parse() + assert_matches_type(NotificationTemplateGetResponse, notification, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_path_params_retrieve(self, async_client: AsyncCourier) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `id` but received ''"): + await async_client.notifications.with_raw_response.retrieve( + id="", + ) + @pytest.mark.skip(reason="Mock server tests are disabled") @parametrize async def test_method_list(self, async_client: AsyncCourier) -> None: @@ -113,6 +577,7 @@ async def test_method_list(self, async_client: AsyncCourier) -> None: async def test_method_list_with_all_params(self, async_client: AsyncCourier) -> None: notification = await async_client.notifications.list( cursor="cursor", + event_id="event_id", notes=True, ) assert_matches_type(NotificationListResponse, notification, path=["response"]) @@ -139,6 +604,196 @@ async def test_streaming_response_list(self, async_client: AsyncCourier) -> None assert cast(Any, response.is_closed) is True + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_method_archive(self, async_client: AsyncCourier) -> None: + notification = await async_client.notifications.archive( + "id", + ) + assert notification is None + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_raw_response_archive(self, async_client: AsyncCourier) -> None: + response = await async_client.notifications.with_raw_response.archive( + "id", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + notification = await response.parse() + assert notification is None + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_streaming_response_archive(self, async_client: AsyncCourier) -> None: + async with async_client.notifications.with_streaming_response.archive( + "id", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + notification = await response.parse() + assert notification is None + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_path_params_archive(self, async_client: AsyncCourier) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `id` but received ''"): + await async_client.notifications.with_raw_response.archive( + "", + ) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_method_publish(self, async_client: AsyncCourier) -> None: + notification = await async_client.notifications.publish( + "id", + ) + assert notification is None + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_raw_response_publish(self, async_client: AsyncCourier) -> None: + response = await async_client.notifications.with_raw_response.publish( + "id", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + notification = await response.parse() + assert notification is None + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_streaming_response_publish(self, async_client: AsyncCourier) -> None: + async with async_client.notifications.with_streaming_response.publish( + "id", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + notification = await response.parse() + assert notification is None + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_path_params_publish(self, async_client: AsyncCourier) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `id` but received ''"): + await async_client.notifications.with_raw_response.publish( + "", + ) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_method_replace(self, async_client: AsyncCourier) -> None: + notification = await async_client.notifications.replace( + id="id", + notification={ + "brand": {"id": "id"}, + "content": { + "elements": [{}], + "version": "2022-01-01", + }, + "name": "Updated Name", + "routing": {"strategy_id": "strategy_id"}, + "subscription": {"topic_id": "topic_id"}, + "tags": ["updated"], + }, + ) + assert_matches_type(NotificationTemplateMutationResponse, notification, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_method_replace_with_all_params(self, async_client: AsyncCourier) -> None: + notification = await async_client.notifications.replace( + id="id", + notification={ + "brand": {"id": "id"}, + "content": { + "elements": [{"type": "channel"}], + "version": "2022-01-01", + }, + "name": "Updated Name", + "routing": {"strategy_id": "strategy_id"}, + "subscription": {"topic_id": "topic_id"}, + "tags": ["updated"], + }, + state="PUBLISHED", + ) + assert_matches_type(NotificationTemplateMutationResponse, notification, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_raw_response_replace(self, async_client: AsyncCourier) -> None: + response = await async_client.notifications.with_raw_response.replace( + id="id", + notification={ + "brand": {"id": "id"}, + "content": { + "elements": [{}], + "version": "2022-01-01", + }, + "name": "Updated Name", + "routing": {"strategy_id": "strategy_id"}, + "subscription": {"topic_id": "topic_id"}, + "tags": ["updated"], + }, + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + notification = await response.parse() + assert_matches_type(NotificationTemplateMutationResponse, notification, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_streaming_response_replace(self, async_client: AsyncCourier) -> None: + async with async_client.notifications.with_streaming_response.replace( + id="id", + notification={ + "brand": {"id": "id"}, + "content": { + "elements": [{}], + "version": "2022-01-01", + }, + "name": "Updated Name", + "routing": {"strategy_id": "strategy_id"}, + "subscription": {"topic_id": "topic_id"}, + "tags": ["updated"], + }, + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + notification = await response.parse() + assert_matches_type(NotificationTemplateMutationResponse, notification, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_path_params_replace(self, async_client: AsyncCourier) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `id` but received ''"): + await async_client.notifications.with_raw_response.replace( + id="", + notification={ + "brand": {"id": "id"}, + "content": { + "elements": [{}], + "version": "2022-01-01", + }, + "name": "Updated Name", + "routing": {"strategy_id": "strategy_id"}, + "subscription": {"topic_id": "topic_id"}, + "tags": ["updated"], + }, + ) + @pytest.mark.skip(reason="Mock server tests are disabled") @parametrize async def test_method_retrieve_content(self, async_client: AsyncCourier) -> None: diff --git a/tests/test_utils/test_path.py b/tests/test_utils/test_path.py new file mode 100644 index 00000000..7a72c7b4 --- /dev/null +++ b/tests/test_utils/test_path.py @@ -0,0 +1,89 @@ +from __future__ import annotations + +from typing import Any + +import pytest + +from courier._utils._path import path_template + + +@pytest.mark.parametrize( + "template, kwargs, expected", + [ + ("/v1/{id}", dict(id="abc"), "/v1/abc"), + ("/v1/{a}/{b}", dict(a="x", b="y"), "/v1/x/y"), + ("/v1/{a}{b}/path/{c}?val={d}#{e}", dict(a="x", b="y", c="z", d="u", e="v"), "/v1/xy/path/z?val=u#v"), + ("/{w}/{w}", dict(w="echo"), "/echo/echo"), + ("/v1/static", {}, "/v1/static"), + ("", {}, ""), + ("/v1/?q={n}&count=10", dict(n=42), "/v1/?q=42&count=10"), + ("/v1/{v}", dict(v=None), "/v1/null"), + ("/v1/{v}", dict(v=True), "/v1/true"), + ("/v1/{v}", dict(v=False), "/v1/false"), + ("/v1/{v}", dict(v=".hidden"), "/v1/.hidden"), # dot prefix ok + ("/v1/{v}", dict(v="file.txt"), "/v1/file.txt"), # dot in middle ok + ("/v1/{v}", dict(v="..."), "/v1/..."), # triple dot ok + ("/v1/{a}{b}", dict(a=".", b="txt"), "/v1/.txt"), # dot var combining with adjacent to be ok + ("/items?q={v}#{f}", dict(v=".", f=".."), "/items?q=.#.."), # dots in query/fragment are fine + ( + "/v1/{a}?query={b}", + dict(a="../../other/endpoint", b="a&bad=true"), + "/v1/..%2F..%2Fother%2Fendpoint?query=a%26bad%3Dtrue", + ), + ("/v1/{val}", dict(val="a/b/c"), "/v1/a%2Fb%2Fc"), + ("/v1/{val}", dict(val="a/b/c?query=value"), "/v1/a%2Fb%2Fc%3Fquery=value"), + ("/v1/{val}", dict(val="a/b/c?query=value&bad=true"), "/v1/a%2Fb%2Fc%3Fquery=value&bad=true"), + ("/v1/{val}", dict(val="%20"), "/v1/%2520"), # escapes escape sequences in input + # Query: slash and ? are safe, # is not + ("/items?q={v}", dict(v="a/b"), "/items?q=a/b"), + ("/items?q={v}", dict(v="a?b"), "/items?q=a?b"), + ("/items?q={v}", dict(v="a#b"), "/items?q=a%23b"), + ("/items?q={v}", dict(v="a b"), "/items?q=a%20b"), + # Fragment: slash and ? are safe + ("/docs#{v}", dict(v="a/b"), "/docs#a/b"), + ("/docs#{v}", dict(v="a?b"), "/docs#a?b"), + # Path: slash, ? and # are all encoded + ("/v1/{v}", dict(v="a/b"), "/v1/a%2Fb"), + ("/v1/{v}", dict(v="a?b"), "/v1/a%3Fb"), + ("/v1/{v}", dict(v="a#b"), "/v1/a%23b"), + # same var encoded differently by component + ( + "/v1/{v}?q={v}#{v}", + dict(v="a/b?c#d"), + "/v1/a%2Fb%3Fc%23d?q=a/b?c%23d#a/b?c%23d", + ), + ("/v1/{val}", dict(val="x?admin=true"), "/v1/x%3Fadmin=true"), # query injection + ("/v1/{val}", dict(val="x#admin"), "/v1/x%23admin"), # fragment injection + ], +) +def test_interpolation(template: str, kwargs: dict[str, Any], expected: str) -> None: + assert path_template(template, **kwargs) == expected + + +def test_missing_kwarg_raises_key_error() -> None: + with pytest.raises(KeyError, match="org_id"): + path_template("/v1/{org_id}") + + +@pytest.mark.parametrize( + "template, kwargs", + [ + ("{a}/path", dict(a=".")), + ("{a}/path", dict(a="..")), + ("/v1/{a}", dict(a=".")), + ("/v1/{a}", dict(a="..")), + ("/v1/{a}/path", dict(a=".")), + ("/v1/{a}/path", dict(a="..")), + ("/v1/{a}{b}", dict(a=".", b=".")), # adjacent vars → ".." + ("/v1/{a}.", dict(a=".")), # var + static → ".." + ("/v1/{a}{b}", dict(a="", b=".")), # empty + dot → "." + ("/v1/%2e/{x}", dict(x="ok")), # encoded dot in static text + ("/v1/%2e./{x}", dict(x="ok")), # mixed encoded ".." in static + ("/v1/.%2E/{x}", dict(x="ok")), # mixed encoded ".." in static + ("/v1/{v}?q=1", dict(v="..")), + ("/v1/{v}#frag", dict(v="..")), + ], +) +def test_dot_segment_rejected(template: str, kwargs: dict[str, Any]) -> None: + with pytest.raises(ValueError, match="dot-segment"): + path_template(template, **kwargs)