diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 300fbc5..8304697 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/post-for-me-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: @@ -61,14 +63,18 @@ jobs: run: rye build - name: Get GitHub OIDC Token - if: github.repository == 'stainless-sdks/post-for-me-python' + if: |- + github.repository == 'stainless-sdks/post-for-me-python' && + !startsWith(github.ref, 'refs/heads/stl/') id: github-oidc uses: actions/github-script@v8 with: script: core.setOutput('github_token', await core.getIDToken()); - name: Upload tarball - if: github.repository == 'stainless-sdks/post-for-me-python' + if: |- + github.repository == 'stainless-sdks/post-for-me-python' && + !startsWith(github.ref, 'refs/heads/stl/') env: URL: https://pkg.stainless.com/s AUTH: ${{ steps.github-oidc.outputs.github_token }} diff --git a/.gitignore b/.gitignore index 95ceb18..3824f4c 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 f94eeca..e72f113 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "1.13.0" + ".": "1.14.0" } \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index 07e57fc..226e50a 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 15 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/day-moon-development%2Fpost-for-me-72599bb249d19e707656e49033ef4ce3cdc94f2eaaa2b7ce0c970181a33d2c40.yml -openapi_spec_hash: b21000843cb9ca5be35b80a35e599a48 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/day-moon-development%2Fpost-for-me-4ab77a12a89621944a10c6383193ad885148886601ae135b2558beb9fd145daa.yml +openapi_spec_hash: 74462f287ddc518cbea2f7f81e8ec350 config_hash: 0ec19602e41aea0526548245a59d4253 diff --git a/CHANGELOG.md b/CHANGELOG.md index e396406..3273b7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,32 @@ # Changelog +## 1.14.0 (2026-04-08) + +Full Changelog: [v1.13.0...v1.14.0](https://github.com/DayMoonDevelopment/post-for-me-python/compare/v1.13.0...v1.14.0) + +### Features + +* **api:** api update ([6493cff](https://github.com/DayMoonDevelopment/post-for-me-python/commit/6493cff6ece9776a1dd7284d93e5c9ae8dbcd1a3)) +* **api:** api update ([b91a784](https://github.com/DayMoonDevelopment/post-for-me-python/commit/b91a78432b0ae3b6cf3efa32b526204a5a3092cf)) +* **internal:** implement indices array format for query and form serialization ([623f551](https://github.com/DayMoonDevelopment/post-for-me-python/commit/623f551f101d34f423c3fcdb790f48dac371516f)) + + +### Bug Fixes + +* **client:** preserve hardcoded query params when merging with user params ([d129c09](https://github.com/DayMoonDevelopment/post-for-me-python/commit/d129c09679437a7e2d9d00b9795dc555b2cbdff4)) +* **deps:** bump minimum typing-extensions version ([f80fc21](https://github.com/DayMoonDevelopment/post-for-me-python/commit/f80fc219beaf2a79a312e32ea542926277608506)) +* **pydantic:** do not pass `by_alias` unless set ([39ebd98](https://github.com/DayMoonDevelopment/post-for-me-python/commit/39ebd9853f5f44b40baf3452e5f84d3e2d08f980)) +* sanitize endpoint path params ([c24a027](https://github.com/DayMoonDevelopment/post-for-me-python/commit/c24a0271af9b71201a93d881836ce0059d5e4782)) + + +### Chores + +* **ci:** skip lint on metadata-only changes ([3bd82af](https://github.com/DayMoonDevelopment/post-for-me-python/commit/3bd82afdfd9faf055e778c6ef056e07f1554fb62)) +* **ci:** skip uploading artifacts on stainless-internal branches ([2978ba7](https://github.com/DayMoonDevelopment/post-for-me-python/commit/2978ba728315992f4ab21fad7f6315b8ff5cd363)) +* **internal:** codegen related update ([43838e2](https://github.com/DayMoonDevelopment/post-for-me-python/commit/43838e2b82ae232299d10b37f87bf429b0f21472)) +* **internal:** tweak CI branches ([6251172](https://github.com/DayMoonDevelopment/post-for-me-python/commit/625117263a7863bba2f632de36a3ac23adee4be5)) +* **internal:** update gitignore ([022cf8c](https://github.com/DayMoonDevelopment/post-for-me-python/commit/022cf8c10f6accd06d21f50faf9f81adefa5c8c1)) + ## 1.13.0 (2026-02-25) Full Changelog: [v1.12.0...v1.13.0](https://github.com/DayMoonDevelopment/post-for-me-python/compare/v1.12.0...v1.13.0) diff --git a/pyproject.toml b/pyproject.toml index cb10f49..1ecbf8e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "post_for_me" -version = "1.13.0" +version = "1.14.0" description = "The official Python library for the post-for-me 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/post_for_me/_base_client.py b/src/post_for_me/_base_client.py index 41d6242..c4e24d8 100644 --- a/src/post_for_me/_base_client.py +++ b/src/post_for_me/_base_client.py @@ -540,6 +540,10 @@ def _build_request( files = cast(HttpxRequestFiles, ForceMultipartDict()) prepared_url = self._prepare_url(options.url) + # preserve hard-coded query params from the url + if params and prepared_url.query: + params = {**dict(prepared_url.params.items()), **params} + prepared_url = prepared_url.copy_with(raw_path=prepared_url.raw_path.split(b"?", 1)[0]) if "_" in prepared_url.host: # work around https://github.com/encode/httpx/discussions/2880 kwargs["extensions"] = {"sni_hostname": prepared_url.host.replace("_", "-")} diff --git a/src/post_for_me/_client.py b/src/post_for_me/_client.py index 569886f..31f98be 100644 --- a/src/post_for_me/_client.py +++ b/src/post_for_me/_client.py @@ -107,30 +107,77 @@ def __init__( @cached_property def media(self) -> MediaResource: + """ + Media are media assets (images, videos, etc.) that can be attached to posts using the media url. These endpoints are only needed if your media is not already available on a publicly accessible URL. + Media assets are stored temporarily and are automatically deleted in the following scenarios: + - When the associated post is published + - After 24 hours if not attached to any post + - When the scheduled post is deleted + """ from .resources.media import MediaResource return MediaResource(self) @cached_property def social_posts(self) -> SocialPostsResource: + """ + Posts represent content that can be published across multiple social media platforms. Each post can have platform-specific content variations, allowing customization for different platforms and accounts. Content can be defined at three levels: + + 1. Default content for all platforms + 2. Platform-specific content overrides + 3. Account-specific content overrides + + The system will use the most specific content override available when publishing to each platform and account. + """ from .resources.social_posts import SocialPostsResource return SocialPostsResource(self) @cached_property def social_post_results(self) -> SocialPostResultsResource: + """ + Post results represent the outcome of publishing content to various social media platforms. They provide comprehensive information including: + - Publication status (success/failure) + - Any errors or issues encountered during posting + - Platform url to view the published post + """ from .resources.social_post_results import SocialPostResultsResource return SocialPostResultsResource(self) @cached_property def social_accounts(self) -> SocialAccountsResource: + """Social accounts represent platform-specific accounts (e.g. + + Twitter, LinkedIn, Facebook) that are used for publishing posts. + Each social account has a unique `id` that can be referenced when creating or scheduling posts to specify which platforms the content should be published to. + """ from .resources.social_accounts import SocialAccountsResource return SocialAccountsResource(self) @cached_property def social_account_feeds(self) -> SocialAccountFeedsResource: + """ + The social account feed is every post made for the social account, including posts not made through our API. + Use this endpoint to get the platform details for any post made under the connected account. To use this endpoint accounts must be connected with the **"feeds" permission**. + + Details will include: + - Post information including caption, url, media, etc.. + - When passing **expand=metrics**, Metrics information including views, likes, follows, etc.. + + Note: Currently the following platforms are supported: + - **Instagram**, may take up to 48 hours for some metrics to be avaialbe + - **Facebook** + - **TikTok**, consumer API exposes less analytics for more details connect through TikTok Business + - **TikTok Business**, + - **Youtube** + - **Threads** + - **X (Twitter)** + - **Bluesky**, Bluesky does not expose views or impressions through their API. + - **Pinterest** + - **LinkedIn**, metrics are only available for company pages. LinkedIn has currently stopped giving permission for personal page analytics, we are on the waitlist for when they resume. + """ from .resources.social_account_feeds import SocialAccountFeedsResource return SocialAccountFeedsResource(self) @@ -305,30 +352,77 @@ def __init__( @cached_property def media(self) -> AsyncMediaResource: + """ + Media are media assets (images, videos, etc.) that can be attached to posts using the media url. These endpoints are only needed if your media is not already available on a publicly accessible URL. + Media assets are stored temporarily and are automatically deleted in the following scenarios: + - When the associated post is published + - After 24 hours if not attached to any post + - When the scheduled post is deleted + """ from .resources.media import AsyncMediaResource return AsyncMediaResource(self) @cached_property def social_posts(self) -> AsyncSocialPostsResource: + """ + Posts represent content that can be published across multiple social media platforms. Each post can have platform-specific content variations, allowing customization for different platforms and accounts. Content can be defined at three levels: + + 1. Default content for all platforms + 2. Platform-specific content overrides + 3. Account-specific content overrides + + The system will use the most specific content override available when publishing to each platform and account. + """ from .resources.social_posts import AsyncSocialPostsResource return AsyncSocialPostsResource(self) @cached_property def social_post_results(self) -> AsyncSocialPostResultsResource: + """ + Post results represent the outcome of publishing content to various social media platforms. They provide comprehensive information including: + - Publication status (success/failure) + - Any errors or issues encountered during posting + - Platform url to view the published post + """ from .resources.social_post_results import AsyncSocialPostResultsResource return AsyncSocialPostResultsResource(self) @cached_property def social_accounts(self) -> AsyncSocialAccountsResource: + """Social accounts represent platform-specific accounts (e.g. + + Twitter, LinkedIn, Facebook) that are used for publishing posts. + Each social account has a unique `id` that can be referenced when creating or scheduling posts to specify which platforms the content should be published to. + """ from .resources.social_accounts import AsyncSocialAccountsResource return AsyncSocialAccountsResource(self) @cached_property def social_account_feeds(self) -> AsyncSocialAccountFeedsResource: + """ + The social account feed is every post made for the social account, including posts not made through our API. + Use this endpoint to get the platform details for any post made under the connected account. To use this endpoint accounts must be connected with the **"feeds" permission**. + + Details will include: + - Post information including caption, url, media, etc.. + - When passing **expand=metrics**, Metrics information including views, likes, follows, etc.. + + Note: Currently the following platforms are supported: + - **Instagram**, may take up to 48 hours for some metrics to be avaialbe + - **Facebook** + - **TikTok**, consumer API exposes less analytics for more details connect through TikTok Business + - **TikTok Business**, + - **Youtube** + - **Threads** + - **X (Twitter)** + - **Bluesky**, Bluesky does not expose views or impressions through their API. + - **Pinterest** + - **LinkedIn**, metrics are only available for company pages. LinkedIn has currently stopped giving permission for personal page analytics, we are on the waitlist for when they resume. + """ from .resources.social_account_feeds import AsyncSocialAccountFeedsResource return AsyncSocialAccountFeedsResource(self) @@ -454,30 +548,77 @@ def __init__(self, client: PostForMe) -> None: @cached_property def media(self) -> media.MediaResourceWithRawResponse: + """ + Media are media assets (images, videos, etc.) that can be attached to posts using the media url. These endpoints are only needed if your media is not already available on a publicly accessible URL. + Media assets are stored temporarily and are automatically deleted in the following scenarios: + - When the associated post is published + - After 24 hours if not attached to any post + - When the scheduled post is deleted + """ from .resources.media import MediaResourceWithRawResponse return MediaResourceWithRawResponse(self._client.media) @cached_property def social_posts(self) -> social_posts.SocialPostsResourceWithRawResponse: + """ + Posts represent content that can be published across multiple social media platforms. Each post can have platform-specific content variations, allowing customization for different platforms and accounts. Content can be defined at three levels: + + 1. Default content for all platforms + 2. Platform-specific content overrides + 3. Account-specific content overrides + + The system will use the most specific content override available when publishing to each platform and account. + """ from .resources.social_posts import SocialPostsResourceWithRawResponse return SocialPostsResourceWithRawResponse(self._client.social_posts) @cached_property def social_post_results(self) -> social_post_results.SocialPostResultsResourceWithRawResponse: + """ + Post results represent the outcome of publishing content to various social media platforms. They provide comprehensive information including: + - Publication status (success/failure) + - Any errors or issues encountered during posting + - Platform url to view the published post + """ from .resources.social_post_results import SocialPostResultsResourceWithRawResponse return SocialPostResultsResourceWithRawResponse(self._client.social_post_results) @cached_property def social_accounts(self) -> social_accounts.SocialAccountsResourceWithRawResponse: + """Social accounts represent platform-specific accounts (e.g. + + Twitter, LinkedIn, Facebook) that are used for publishing posts. + Each social account has a unique `id` that can be referenced when creating or scheduling posts to specify which platforms the content should be published to. + """ from .resources.social_accounts import SocialAccountsResourceWithRawResponse return SocialAccountsResourceWithRawResponse(self._client.social_accounts) @cached_property def social_account_feeds(self) -> social_account_feeds.SocialAccountFeedsResourceWithRawResponse: + """ + The social account feed is every post made for the social account, including posts not made through our API. + Use this endpoint to get the platform details for any post made under the connected account. To use this endpoint accounts must be connected with the **"feeds" permission**. + + Details will include: + - Post information including caption, url, media, etc.. + - When passing **expand=metrics**, Metrics information including views, likes, follows, etc.. + + Note: Currently the following platforms are supported: + - **Instagram**, may take up to 48 hours for some metrics to be avaialbe + - **Facebook** + - **TikTok**, consumer API exposes less analytics for more details connect through TikTok Business + - **TikTok Business**, + - **Youtube** + - **Threads** + - **X (Twitter)** + - **Bluesky**, Bluesky does not expose views or impressions through their API. + - **Pinterest** + - **LinkedIn**, metrics are only available for company pages. LinkedIn has currently stopped giving permission for personal page analytics, we are on the waitlist for when they resume. + """ from .resources.social_account_feeds import SocialAccountFeedsResourceWithRawResponse return SocialAccountFeedsResourceWithRawResponse(self._client.social_account_feeds) @@ -491,30 +632,77 @@ def __init__(self, client: AsyncPostForMe) -> None: @cached_property def media(self) -> media.AsyncMediaResourceWithRawResponse: + """ + Media are media assets (images, videos, etc.) that can be attached to posts using the media url. These endpoints are only needed if your media is not already available on a publicly accessible URL. + Media assets are stored temporarily and are automatically deleted in the following scenarios: + - When the associated post is published + - After 24 hours if not attached to any post + - When the scheduled post is deleted + """ from .resources.media import AsyncMediaResourceWithRawResponse return AsyncMediaResourceWithRawResponse(self._client.media) @cached_property def social_posts(self) -> social_posts.AsyncSocialPostsResourceWithRawResponse: + """ + Posts represent content that can be published across multiple social media platforms. Each post can have platform-specific content variations, allowing customization for different platforms and accounts. Content can be defined at three levels: + + 1. Default content for all platforms + 2. Platform-specific content overrides + 3. Account-specific content overrides + + The system will use the most specific content override available when publishing to each platform and account. + """ from .resources.social_posts import AsyncSocialPostsResourceWithRawResponse return AsyncSocialPostsResourceWithRawResponse(self._client.social_posts) @cached_property def social_post_results(self) -> social_post_results.AsyncSocialPostResultsResourceWithRawResponse: + """ + Post results represent the outcome of publishing content to various social media platforms. They provide comprehensive information including: + - Publication status (success/failure) + - Any errors or issues encountered during posting + - Platform url to view the published post + """ from .resources.social_post_results import AsyncSocialPostResultsResourceWithRawResponse return AsyncSocialPostResultsResourceWithRawResponse(self._client.social_post_results) @cached_property def social_accounts(self) -> social_accounts.AsyncSocialAccountsResourceWithRawResponse: + """Social accounts represent platform-specific accounts (e.g. + + Twitter, LinkedIn, Facebook) that are used for publishing posts. + Each social account has a unique `id` that can be referenced when creating or scheduling posts to specify which platforms the content should be published to. + """ from .resources.social_accounts import AsyncSocialAccountsResourceWithRawResponse return AsyncSocialAccountsResourceWithRawResponse(self._client.social_accounts) @cached_property def social_account_feeds(self) -> social_account_feeds.AsyncSocialAccountFeedsResourceWithRawResponse: + """ + The social account feed is every post made for the social account, including posts not made through our API. + Use this endpoint to get the platform details for any post made under the connected account. To use this endpoint accounts must be connected with the **"feeds" permission**. + + Details will include: + - Post information including caption, url, media, etc.. + - When passing **expand=metrics**, Metrics information including views, likes, follows, etc.. + + Note: Currently the following platforms are supported: + - **Instagram**, may take up to 48 hours for some metrics to be avaialbe + - **Facebook** + - **TikTok**, consumer API exposes less analytics for more details connect through TikTok Business + - **TikTok Business**, + - **Youtube** + - **Threads** + - **X (Twitter)** + - **Bluesky**, Bluesky does not expose views or impressions through their API. + - **Pinterest** + - **LinkedIn**, metrics are only available for company pages. LinkedIn has currently stopped giving permission for personal page analytics, we are on the waitlist for when they resume. + """ from .resources.social_account_feeds import AsyncSocialAccountFeedsResourceWithRawResponse return AsyncSocialAccountFeedsResourceWithRawResponse(self._client.social_account_feeds) @@ -528,30 +716,77 @@ def __init__(self, client: PostForMe) -> None: @cached_property def media(self) -> media.MediaResourceWithStreamingResponse: + """ + Media are media assets (images, videos, etc.) that can be attached to posts using the media url. These endpoints are only needed if your media is not already available on a publicly accessible URL. + Media assets are stored temporarily and are automatically deleted in the following scenarios: + - When the associated post is published + - After 24 hours if not attached to any post + - When the scheduled post is deleted + """ from .resources.media import MediaResourceWithStreamingResponse return MediaResourceWithStreamingResponse(self._client.media) @cached_property def social_posts(self) -> social_posts.SocialPostsResourceWithStreamingResponse: + """ + Posts represent content that can be published across multiple social media platforms. Each post can have platform-specific content variations, allowing customization for different platforms and accounts. Content can be defined at three levels: + + 1. Default content for all platforms + 2. Platform-specific content overrides + 3. Account-specific content overrides + + The system will use the most specific content override available when publishing to each platform and account. + """ from .resources.social_posts import SocialPostsResourceWithStreamingResponse return SocialPostsResourceWithStreamingResponse(self._client.social_posts) @cached_property def social_post_results(self) -> social_post_results.SocialPostResultsResourceWithStreamingResponse: + """ + Post results represent the outcome of publishing content to various social media platforms. They provide comprehensive information including: + - Publication status (success/failure) + - Any errors or issues encountered during posting + - Platform url to view the published post + """ from .resources.social_post_results import SocialPostResultsResourceWithStreamingResponse return SocialPostResultsResourceWithStreamingResponse(self._client.social_post_results) @cached_property def social_accounts(self) -> social_accounts.SocialAccountsResourceWithStreamingResponse: + """Social accounts represent platform-specific accounts (e.g. + + Twitter, LinkedIn, Facebook) that are used for publishing posts. + Each social account has a unique `id` that can be referenced when creating or scheduling posts to specify which platforms the content should be published to. + """ from .resources.social_accounts import SocialAccountsResourceWithStreamingResponse return SocialAccountsResourceWithStreamingResponse(self._client.social_accounts) @cached_property def social_account_feeds(self) -> social_account_feeds.SocialAccountFeedsResourceWithStreamingResponse: + """ + The social account feed is every post made for the social account, including posts not made through our API. + Use this endpoint to get the platform details for any post made under the connected account. To use this endpoint accounts must be connected with the **"feeds" permission**. + + Details will include: + - Post information including caption, url, media, etc.. + - When passing **expand=metrics**, Metrics information including views, likes, follows, etc.. + + Note: Currently the following platforms are supported: + - **Instagram**, may take up to 48 hours for some metrics to be avaialbe + - **Facebook** + - **TikTok**, consumer API exposes less analytics for more details connect through TikTok Business + - **TikTok Business**, + - **Youtube** + - **Threads** + - **X (Twitter)** + - **Bluesky**, Bluesky does not expose views or impressions through their API. + - **Pinterest** + - **LinkedIn**, metrics are only available for company pages. LinkedIn has currently stopped giving permission for personal page analytics, we are on the waitlist for when they resume. + """ from .resources.social_account_feeds import SocialAccountFeedsResourceWithStreamingResponse return SocialAccountFeedsResourceWithStreamingResponse(self._client.social_account_feeds) @@ -565,30 +800,77 @@ def __init__(self, client: AsyncPostForMe) -> None: @cached_property def media(self) -> media.AsyncMediaResourceWithStreamingResponse: + """ + Media are media assets (images, videos, etc.) that can be attached to posts using the media url. These endpoints are only needed if your media is not already available on a publicly accessible URL. + Media assets are stored temporarily and are automatically deleted in the following scenarios: + - When the associated post is published + - After 24 hours if not attached to any post + - When the scheduled post is deleted + """ from .resources.media import AsyncMediaResourceWithStreamingResponse return AsyncMediaResourceWithStreamingResponse(self._client.media) @cached_property def social_posts(self) -> social_posts.AsyncSocialPostsResourceWithStreamingResponse: + """ + Posts represent content that can be published across multiple social media platforms. Each post can have platform-specific content variations, allowing customization for different platforms and accounts. Content can be defined at three levels: + + 1. Default content for all platforms + 2. Platform-specific content overrides + 3. Account-specific content overrides + + The system will use the most specific content override available when publishing to each platform and account. + """ from .resources.social_posts import AsyncSocialPostsResourceWithStreamingResponse return AsyncSocialPostsResourceWithStreamingResponse(self._client.social_posts) @cached_property def social_post_results(self) -> social_post_results.AsyncSocialPostResultsResourceWithStreamingResponse: + """ + Post results represent the outcome of publishing content to various social media platforms. They provide comprehensive information including: + - Publication status (success/failure) + - Any errors or issues encountered during posting + - Platform url to view the published post + """ from .resources.social_post_results import AsyncSocialPostResultsResourceWithStreamingResponse return AsyncSocialPostResultsResourceWithStreamingResponse(self._client.social_post_results) @cached_property def social_accounts(self) -> social_accounts.AsyncSocialAccountsResourceWithStreamingResponse: + """Social accounts represent platform-specific accounts (e.g. + + Twitter, LinkedIn, Facebook) that are used for publishing posts. + Each social account has a unique `id` that can be referenced when creating or scheduling posts to specify which platforms the content should be published to. + """ from .resources.social_accounts import AsyncSocialAccountsResourceWithStreamingResponse return AsyncSocialAccountsResourceWithStreamingResponse(self._client.social_accounts) @cached_property def social_account_feeds(self) -> social_account_feeds.AsyncSocialAccountFeedsResourceWithStreamingResponse: + """ + The social account feed is every post made for the social account, including posts not made through our API. + Use this endpoint to get the platform details for any post made under the connected account. To use this endpoint accounts must be connected with the **"feeds" permission**. + + Details will include: + - Post information including caption, url, media, etc.. + - When passing **expand=metrics**, Metrics information including views, likes, follows, etc.. + + Note: Currently the following platforms are supported: + - **Instagram**, may take up to 48 hours for some metrics to be avaialbe + - **Facebook** + - **TikTok**, consumer API exposes less analytics for more details connect through TikTok Business + - **TikTok Business**, + - **Youtube** + - **Threads** + - **X (Twitter)** + - **Bluesky**, Bluesky does not expose views or impressions through their API. + - **Pinterest** + - **LinkedIn**, metrics are only available for company pages. LinkedIn has currently stopped giving permission for personal page analytics, we are on the waitlist for when they resume. + """ from .resources.social_account_feeds import AsyncSocialAccountFeedsResourceWithStreamingResponse return AsyncSocialAccountFeedsResourceWithStreamingResponse(self._client.social_account_feeds) diff --git a/src/post_for_me/_compat.py b/src/post_for_me/_compat.py index 786ff42..e6690a4 100644 --- a/src/post_for_me/_compat.py +++ b/src/post_for_me/_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/post_for_me/_qs.py b/src/post_for_me/_qs.py index ada6fd3..de8c99b 100644 --- a/src/post_for_me/_qs.py +++ b/src/post_for_me/_qs.py @@ -101,7 +101,10 @@ def _stringify_item( items.extend(self._stringify_item(key, item, opts)) return items elif array_format == "indices": - raise NotImplementedError("The array indices format is not supported yet") + items = [] + for i, item in enumerate(value): + items.extend(self._stringify_item(f"{key}[{i}]", item, opts)) + return items elif array_format == "brackets": items = [] key = key + "[]" diff --git a/src/post_for_me/_utils/__init__.py b/src/post_for_me/_utils/__init__.py index dc64e29..10cb66d 100644 --- a/src/post_for_me/_utils/__init__.py +++ b/src/post_for_me/_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/post_for_me/_utils/_path.py b/src/post_for_me/_utils/_path.py new file mode 100644 index 0000000..4d6e1e4 --- /dev/null +++ b/src/post_for_me/_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/post_for_me/_version.py b/src/post_for_me/_version.py index 58a56bf..e797f53 100644 --- a/src/post_for_me/_version.py +++ b/src/post_for_me/_version.py @@ -1,4 +1,4 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. __title__ = "post_for_me" -__version__ = "1.13.0" # x-release-please-version +__version__ = "1.14.0" # x-release-please-version diff --git a/src/post_for_me/resources/media.py b/src/post_for_me/resources/media.py index 3949f59..eab60d5 100644 --- a/src/post_for_me/resources/media.py +++ b/src/post_for_me/resources/media.py @@ -20,6 +20,14 @@ class MediaResource(SyncAPIResource): + """ + Media are media assets (images, videos, etc.) that can be attached to posts using the media url. These endpoints are only needed if your media is not already available on a publicly accessible URL. + Media assets are stored temporarily and are automatically deleted in the following scenarios: + - When the associated post is published + - After 24 hours if not attached to any post + - When the scheduled post is deleted + """ + @cached_property def with_raw_response(self) -> MediaResourceWithRawResponse: """ @@ -124,6 +132,14 @@ def create_upload_url( class AsyncMediaResource(AsyncAPIResource): + """ + Media are media assets (images, videos, etc.) that can be attached to posts using the media url. These endpoints are only needed if your media is not already available on a publicly accessible URL. + Media assets are stored temporarily and are automatically deleted in the following scenarios: + - When the associated post is published + - After 24 hours if not attached to any post + - When the scheduled post is deleted + """ + @cached_property def with_raw_response(self) -> AsyncMediaResourceWithRawResponse: """ diff --git a/src/post_for_me/resources/social_account_feeds.py b/src/post_for_me/resources/social_account_feeds.py index 9b834af..965f3d1 100644 --- a/src/post_for_me/resources/social_account_feeds.py +++ b/src/post_for_me/resources/social_account_feeds.py @@ -9,7 +9,7 @@ from ..types import social_account_feed_list_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 ( @@ -25,6 +25,27 @@ class SocialAccountFeedsResource(SyncAPIResource): + """ + The social account feed is every post made for the social account, including posts not made through our API. + Use this endpoint to get the platform details for any post made under the connected account. To use this endpoint accounts must be connected with the **"feeds" permission**. + + Details will include: + - Post information including caption, url, media, etc.. + - When passing **expand=metrics**, Metrics information including views, likes, follows, etc.. + + Note: Currently the following platforms are supported: + - **Instagram**, may take up to 48 hours for some metrics to be avaialbe + - **Facebook** + - **TikTok**, consumer API exposes less analytics for more details connect through TikTok Business + - **TikTok Business**, + - **Youtube** + - **Threads** + - **X (Twitter)** + - **Bluesky**, Bluesky does not expose views or impressions through their API. + - **Pinterest** + - **LinkedIn**, metrics are only available for company pages. LinkedIn has currently stopped giving permission for personal page analytics, we are on the waitlist for when they resume. + """ + @cached_property def with_raw_response(self) -> SocialAccountFeedsResourceWithRawResponse: """ @@ -94,7 +115,7 @@ def list( if not social_account_id: raise ValueError(f"Expected a non-empty value for `social_account_id` but received {social_account_id!r}") return self._get( - f"/v1/social-account-feeds/{social_account_id}", + path_template("/v1/social-account-feeds/{social_account_id}", social_account_id=social_account_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, @@ -117,6 +138,27 @@ def list( class AsyncSocialAccountFeedsResource(AsyncAPIResource): + """ + The social account feed is every post made for the social account, including posts not made through our API. + Use this endpoint to get the platform details for any post made under the connected account. To use this endpoint accounts must be connected with the **"feeds" permission**. + + Details will include: + - Post information including caption, url, media, etc.. + - When passing **expand=metrics**, Metrics information including views, likes, follows, etc.. + + Note: Currently the following platforms are supported: + - **Instagram**, may take up to 48 hours for some metrics to be avaialbe + - **Facebook** + - **TikTok**, consumer API exposes less analytics for more details connect through TikTok Business + - **TikTok Business**, + - **Youtube** + - **Threads** + - **X (Twitter)** + - **Bluesky**, Bluesky does not expose views or impressions through their API. + - **Pinterest** + - **LinkedIn**, metrics are only available for company pages. LinkedIn has currently stopped giving permission for personal page analytics, we are on the waitlist for when they resume. + """ + @cached_property def with_raw_response(self) -> AsyncSocialAccountFeedsResourceWithRawResponse: """ @@ -186,7 +228,7 @@ async def list( if not social_account_id: raise ValueError(f"Expected a non-empty value for `social_account_id` but received {social_account_id!r}") return await self._get( - f"/v1/social-account-feeds/{social_account_id}", + path_template("/v1/social-account-feeds/{social_account_id}", social_account_id=social_account_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, diff --git a/src/post_for_me/resources/social_accounts.py b/src/post_for_me/resources/social_accounts.py index a2fbc17..923cb40 100644 --- a/src/post_for_me/resources/social_accounts.py +++ b/src/post_for_me/resources/social_accounts.py @@ -15,7 +15,7 @@ social_account_create_auth_url_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 ( @@ -34,6 +34,12 @@ class SocialAccountsResource(SyncAPIResource): + """Social accounts represent platform-specific accounts (e.g. + + Twitter, LinkedIn, Facebook) that are used for publishing posts. + Each social account has a unique `id` that can be referenced when creating or scheduling posts to specify which platforms the content should be published to. + """ + @cached_property def with_raw_response(self) -> SocialAccountsResourceWithRawResponse: """ @@ -162,7 +168,7 @@ def retrieve( if not id: raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") return self._get( - f"/v1/social-accounts/{id}", + path_template("/v1/social-accounts/{id}", id=id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -201,7 +207,7 @@ def update( if not id: raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") return self._patch( - f"/v1/social-accounts/{id}", + path_template("/v1/social-accounts/{id}", id=id), body=maybe_transform( { "external_id": external_id, @@ -376,7 +382,7 @@ def disconnect( if not id: raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") return self._post( - f"/v1/social-accounts/{id}/disconnect", + path_template("/v1/social-accounts/{id}/disconnect", id=id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -385,6 +391,12 @@ def disconnect( class AsyncSocialAccountsResource(AsyncAPIResource): + """Social accounts represent platform-specific accounts (e.g. + + Twitter, LinkedIn, Facebook) that are used for publishing posts. + Each social account has a unique `id` that can be referenced when creating or scheduling posts to specify which platforms the content should be published to. + """ + @cached_property def with_raw_response(self) -> AsyncSocialAccountsResourceWithRawResponse: """ @@ -513,7 +525,7 @@ async def retrieve( if not id: raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") return await self._get( - f"/v1/social-accounts/{id}", + path_template("/v1/social-accounts/{id}", id=id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -552,7 +564,7 @@ async def update( if not id: raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") return await self._patch( - f"/v1/social-accounts/{id}", + path_template("/v1/social-accounts/{id}", id=id), body=await async_maybe_transform( { "external_id": external_id, @@ -727,7 +739,7 @@ async def disconnect( if not id: raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") return await self._post( - f"/v1/social-accounts/{id}/disconnect", + path_template("/v1/social-accounts/{id}/disconnect", id=id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), diff --git a/src/post_for_me/resources/social_post_results.py b/src/post_for_me/resources/social_post_results.py index 650435c..6717a81 100644 --- a/src/post_for_me/resources/social_post_results.py +++ b/src/post_for_me/resources/social_post_results.py @@ -6,7 +6,7 @@ from ..types import social_post_result_list_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 ( @@ -23,6 +23,13 @@ class SocialPostResultsResource(SyncAPIResource): + """ + Post results represent the outcome of publishing content to various social media platforms. They provide comprehensive information including: + - Publication status (success/failure) + - Any errors or issues encountered during posting + - Platform url to view the published post + """ + @cached_property def with_raw_response(self) -> SocialPostResultsResourceWithRawResponse: """ @@ -68,7 +75,7 @@ def retrieve( if not id: raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") return self._get( - f"/v1/social-post-results/{id}", + path_template("/v1/social-post-results/{id}", id=id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -138,6 +145,13 @@ def list( class AsyncSocialPostResultsResource(AsyncAPIResource): + """ + Post results represent the outcome of publishing content to various social media platforms. They provide comprehensive information including: + - Publication status (success/failure) + - Any errors or issues encountered during posting + - Platform url to view the published post + """ + @cached_property def with_raw_response(self) -> AsyncSocialPostResultsResourceWithRawResponse: """ @@ -183,7 +197,7 @@ async def retrieve( if not id: raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") return await self._get( - f"/v1/social-post-results/{id}", + path_template("/v1/social-post-results/{id}", id=id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), diff --git a/src/post_for_me/resources/social_posts.py b/src/post_for_me/resources/social_posts.py index 245b75f..9b111ce 100644 --- a/src/post_for_me/resources/social_posts.py +++ b/src/post_for_me/resources/social_posts.py @@ -14,7 +14,7 @@ social_post_update_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 ( @@ -33,6 +33,16 @@ class SocialPostsResource(SyncAPIResource): + """ + Posts represent content that can be published across multiple social media platforms. Each post can have platform-specific content variations, allowing customization for different platforms and accounts. Content can be defined at three levels: + + 1. Default content for all platforms + 2. Platform-specific content overrides + 3. Account-specific content overrides + + The system will use the most specific content override available when publishing to each platform and account. + """ + @cached_property def with_raw_response(self) -> SocialPostsResourceWithRawResponse: """ @@ -84,7 +94,8 @@ def create( is_draft: If isDraft is set then the post will not be processed - media: Array of media URLs associated with the post + media: Array of media associated with the post. If multiple media items are provided + and the placement is `stories`, individual posts are created per media item. platform_configurations: Platform-specific configurations for the post @@ -146,7 +157,7 @@ def retrieve( if not id: raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") return self._get( - f"/v1/social-posts/{id}", + path_template("/v1/social-posts/{id}", id=id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -186,7 +197,8 @@ def update( is_draft: If isDraft is set then the post will not be processed - media: Array of media URLs associated with the post + media: Array of media associated with the post. If multiple media items are provided + and the placement is `stories`, individual posts are created per media item. platform_configurations: Platform-specific configurations for the post @@ -204,7 +216,7 @@ def update( if not id: raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") return self._put( - f"/v1/social-posts/{id}", + path_template("/v1/social-posts/{id}", id=id), body=maybe_transform( { "caption": caption, @@ -315,7 +327,7 @@ def delete( if not id: raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") return self._delete( - f"/v1/social-posts/{id}", + path_template("/v1/social-posts/{id}", id=id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -324,6 +336,16 @@ def delete( class AsyncSocialPostsResource(AsyncAPIResource): + """ + Posts represent content that can be published across multiple social media platforms. Each post can have platform-specific content variations, allowing customization for different platforms and accounts. Content can be defined at three levels: + + 1. Default content for all platforms + 2. Platform-specific content overrides + 3. Account-specific content overrides + + The system will use the most specific content override available when publishing to each platform and account. + """ + @cached_property def with_raw_response(self) -> AsyncSocialPostsResourceWithRawResponse: """ @@ -375,7 +397,8 @@ async def create( is_draft: If isDraft is set then the post will not be processed - media: Array of media URLs associated with the post + media: Array of media associated with the post. If multiple media items are provided + and the placement is `stories`, individual posts are created per media item. platform_configurations: Platform-specific configurations for the post @@ -437,7 +460,7 @@ async def retrieve( if not id: raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") return await self._get( - f"/v1/social-posts/{id}", + path_template("/v1/social-posts/{id}", id=id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -477,7 +500,8 @@ async def update( is_draft: If isDraft is set then the post will not be processed - media: Array of media URLs associated with the post + media: Array of media associated with the post. If multiple media items are provided + and the placement is `stories`, individual posts are created per media item. platform_configurations: Platform-specific configurations for the post @@ -495,7 +519,7 @@ async def update( if not id: raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") return await self._put( - f"/v1/social-posts/{id}", + path_template("/v1/social-posts/{id}", id=id), body=await async_maybe_transform( { "caption": caption, @@ -606,7 +630,7 @@ async def delete( if not id: raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") return await self._delete( - f"/v1/social-posts/{id}", + path_template("/v1/social-posts/{id}", id=id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), diff --git a/src/post_for_me/types/platform_post.py b/src/post_for_me/types/platform_post.py index 4ea41b6..6299598 100644 --- a/src/post_for_me/types/platform_post.py +++ b/src/post_for_me/types/platform_post.py @@ -40,6 +40,7 @@ "MetricsPinterestPostMetricsDto", "MetricsPinterestPostMetricsDto_90d", "MetricsPinterestPostMetricsDtoLifetimeMetrics", + "PlatformData", ] @@ -788,6 +789,13 @@ class MetricsPinterestPostMetricsDto(BaseModel): ] +class PlatformData(BaseModel): + """Platform-specific data for the post""" + + title: str + """Title of the post""" + + class PlatformPost(BaseModel): caption: str """Caption or text content of the post""" @@ -819,6 +827,9 @@ class PlatformPost(BaseModel): metrics: Optional[Metrics] = None """Post metrics and analytics data""" + platform_data: Optional[PlatformData] = None + """Platform-specific data for the post""" + posted_at: Optional[datetime] = None """Date the post was published""" diff --git a/src/post_for_me/types/social_post.py b/src/post_for_me/types/social_post.py index e188cd6..235b1df 100644 --- a/src/post_for_me/types/social_post.py +++ b/src/post_for_me/types/social_post.py @@ -244,7 +244,7 @@ class SocialPost(BaseModel): """Provided unique identifier of the post""" media: Optional[List[Media]] = None - """Array of media URLs associated with the post""" + """Array of media associated with the post""" platform_configurations: Optional[PlatformConfigurationsDto] = None """Platform-specific configurations for the post""" diff --git a/src/post_for_me/types/social_post_create_params.py b/src/post_for_me/types/social_post_create_params.py index 9036376..1ad8cbb 100644 --- a/src/post_for_me/types/social_post_create_params.py +++ b/src/post_for_me/types/social_post_create_params.py @@ -39,7 +39,11 @@ class SocialPostCreateParams(TypedDict, total=False): """If isDraft is set then the post will not be processed""" media: Optional[Iterable[Media]] - """Array of media URLs associated with the post""" + """Array of media associated with the post. + + If multiple media items are provided and the placement is `stories`, individual + posts are created per media item. + """ platform_configurations: Optional[PlatformConfigurationsDtoParam] """Platform-specific configurations for the post""" diff --git a/src/post_for_me/types/social_post_result.py b/src/post_for_me/types/social_post_result.py index 21f25c3..c29fbda 100644 --- a/src/post_for_me/types/social_post_result.py +++ b/src/post_for_me/types/social_post_result.py @@ -1,10 +1,58 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -from typing import Optional +from typing import List, Optional +from typing_extensions import Literal from .._models import BaseModel -__all__ = ["SocialPostResult", "PlatformData"] +__all__ = ["SocialPostResult", "Media", "MediaTag", "PlatformData"] + + +class MediaTag(BaseModel): + id: str + """Facebook User ID, Instagram Username or Instagram product id to tag""" + + platform: Literal["facebook", "instagram"] + """The platform for the tags""" + + type: Literal["user", "product"] + """ + The type of tag, user to tag accounts, product to tag products (only supported + for instagram) + """ + + x: Optional[float] = None + """ + Percentage distance from left edge of the image, Not required for videos or + stories + """ + + y: Optional[float] = None + """ + Percentage distance from top edge of the image, Not required for videos or + stories + """ + + +class Media(BaseModel): + url: str + """Public URL of the media""" + + skip_processing: Optional[bool] = None + """ + If true the media will not be processed at all and instead be posted as is, this + may increase chance of post failure if media does not meet platform's + requirements. Best used for larger files. + """ + + tags: Optional[List[MediaTag]] = None + """List of tags to attach to the media""" + + thumbnail_timestamp_ms: Optional[object] = None + """Timestamp in milliseconds of frame to use as thumbnail for the media""" + + thumbnail_url: Optional[object] = None + """Public URL of the thumbnail for the media""" class PlatformData(BaseModel): @@ -27,6 +75,9 @@ class SocialPostResult(BaseModel): error: object """Error message if the post failed""" + media: Optional[List[Media]] = None + """Array of media URLs associated with the post""" + platform_data: PlatformData """Platform-specific data""" diff --git a/src/post_for_me/types/social_post_update_params.py b/src/post_for_me/types/social_post_update_params.py index fca89c5..0a3f2ec 100644 --- a/src/post_for_me/types/social_post_update_params.py +++ b/src/post_for_me/types/social_post_update_params.py @@ -39,7 +39,11 @@ class SocialPostUpdateParams(TypedDict, total=False): """If isDraft is set then the post will not be processed""" media: Optional[Iterable[Media]] - """Array of media URLs associated with the post""" + """Array of media associated with the post. + + If multiple media items are provided and the placement is `stories`, individual + posts are created per media item. + """ platform_configurations: Optional[PlatformConfigurationsDtoParam] """Platform-specific configurations for the post""" diff --git a/tests/test_client.py b/tests/test_client.py index 7bd416c..5dc0c2c 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -429,6 +429,30 @@ def test_default_query_option(self) -> None: client.close() + def test_hardcoded_query_params_in_url(self, client: PostForMe) -> None: + request = client._build_request(FinalRequestOptions(method="get", url="/foo?beta=true")) + url = httpx.URL(request.url) + assert dict(url.params) == {"beta": "true"} + + request = client._build_request( + FinalRequestOptions( + method="get", + url="/foo?beta=true", + params={"limit": "10", "page": "abc"}, + ) + ) + url = httpx.URL(request.url) + assert dict(url.params) == {"beta": "true", "limit": "10", "page": "abc"} + + request = client._build_request( + FinalRequestOptions( + method="get", + url="/files/a%2Fb?beta=true", + params={"limit": "10"}, + ) + ) + assert request.url.raw_path == b"/files/a%2Fb?beta=true&limit=10" + def test_request_extra_json(self, client: PostForMe) -> None: request = client._build_request( FinalRequestOptions( @@ -1328,6 +1352,30 @@ async def test_default_query_option(self) -> None: await client.close() + async def test_hardcoded_query_params_in_url(self, async_client: AsyncPostForMe) -> None: + request = async_client._build_request(FinalRequestOptions(method="get", url="/foo?beta=true")) + url = httpx.URL(request.url) + assert dict(url.params) == {"beta": "true"} + + request = async_client._build_request( + FinalRequestOptions( + method="get", + url="/foo?beta=true", + params={"limit": "10", "page": "abc"}, + ) + ) + url = httpx.URL(request.url) + assert dict(url.params) == {"beta": "true", "limit": "10", "page": "abc"} + + request = async_client._build_request( + FinalRequestOptions( + method="get", + url="/files/a%2Fb?beta=true", + params={"limit": "10"}, + ) + ) + assert request.url.raw_path == b"/files/a%2Fb?beta=true&limit=10" + def test_request_extra_json(self, client: PostForMe) -> None: request = client._build_request( FinalRequestOptions( diff --git a/tests/test_utils/test_path.py b/tests/test_utils/test_path.py new file mode 100644 index 0000000..ba9208f --- /dev/null +++ b/tests/test_utils/test_path.py @@ -0,0 +1,89 @@ +from __future__ import annotations + +from typing import Any + +import pytest + +from post_for_me._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)