diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ee2a849f..a75cb087 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/**' diff --git a/.release-please-manifest.json b/.release-please-manifest.json index a75e9e71..b2b27d46 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "7.9.0" + ".": "7.9.1" } \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index 75c12180..005d7f35 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 +config_hash: c501fe3838c270e9b44dd5dc4b7fca70 diff --git a/CHANGELOG.md b/CHANGELOG.md index 67719e19..3785c849 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ # Changelog +## 7.9.1 (2026-03-20) + +Full Changelog: [v7.9.0...v7.9.1](https://github.com/trycourier/courier-python/compare/v7.9.0...v7.9.1) + +### 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 + +* **internal:** tweak CI branches ([75425fb](https://github.com/trycourier/courier-python/commit/75425fbbcab9362d2e2f55dd91f0f954e90b812e)) + ## 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/pyproject.toml b/pyproject.toml index f17335a1..31b1721f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "trycourier" -version = "7.9.0" +version = "7.9.1" 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..535faa48 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.9.1" # 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..e8d362de 100644 --- a/src/courier/resources/notifications/notifications.py +++ b/src/courier/resources/notifications/notifications.py @@ -24,7 +24,7 @@ ) 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 ..._utils import path_template, maybe_transform, async_maybe_transform from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource from ..._response import ( @@ -134,7 +134,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 ), @@ -236,7 +236,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 ), 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/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)