Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(data-warehouse): add 5 missing tables to the Vimeo source (#119140)

Tom Owersb0611a17a7f6
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
index e690ebeace22..21b77a471a80 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
@@ -12951,10 +12951,10 @@ Today (3): `folders`, `showcases`, `videos`
Diffed against: <https://raw.githubusercontent.com/vimeo/openapi/master/api.yaml>
-- [ ] `Folder videos (GET /me/projects/{project_id}/videos)` — link synced videos to their folders for reporting by collection (high)
-- [ ] `Showcase videos (GET /me/albums/{album_id}/videos)` — link synced videos to showcases and compare content across curated collections (high)
-- [ ] `Video comments and replies (GET /videos/{video_id}/comments; GET /videos/{video_id}/comments/{comment_id}/replies)` — analyze audience feedback and discussion on each video (medium)
-- [ ] `Video likes (GET /videos/{video_id}/likes)` — measure audience engagement and identify viewers who like each video (medium)
+- [x] `Folder videos (GET /me/projects/{project_id}/videos)` — link synced videos to their folders for reporting by collection (high)
+- [x] `Showcase videos (GET /me/albums/{album_id}/videos)` — link synced videos to showcases and compare content across curated collections (high)
+- [x] `Video comments and replies (GET /videos/{video_id}/comments; GET /videos/{video_id}/comments/{comment_id}/replies)` — analyze audience feedback and discussion on each video (medium)
+- [x] `Video likes (GET /videos/{video_id}/likes)` — measure audience engagement and identify viewers who like each video (medium)
- [ ] `Video tags (GET /videos/{video_id}/tags)` — group video performance by topic using the tags assigned to each video (medium)
- [ ] `Followers (GET /me/followers)` — analyze the account audience and follower acquisition (medium)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/vimeo/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/vimeo/canonical_descriptions.py
index 354cc68d0c1b..80ab7dfd7c71 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/vimeo/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/vimeo/canonical_descriptions.py
@@ -37,4 +37,55 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"duration": "Combined length of the showcase videos, in seconds.",
},
},
+ "folder_videos": {
+ "description": "Videos in each folder of the authenticated user. A video appears once for each folder that holds it.",
+ "docs_url": "https://developer.vimeo.com/api/reference/folders",
+ "columns": {
+ "folder_uri": "URI of the folder that holds the video.",
+ "uri": "Relative URI that identifies the video.",
+ "name": "Video title.",
+ "created_time": "Time when the video was created, in ISO 8601 format.",
+ },
+ },
+ "showcase_videos": {
+ "description": "Videos in each showcase of the authenticated user. A video appears once for each showcase that holds it.",
+ "docs_url": "https://developer.vimeo.com/api/reference/showcases",
+ "columns": {
+ "showcase_uri": "URI of the showcase that holds the video.",
+ "uri": "Relative URI that identifies the video.",
+ "name": "Video title.",
+ "created_time": "Time when the video was created, in ISO 8601 format.",
+ },
+ },
+ "video_comments": {
+ "description": "Top-level comments on the videos of the authenticated user.",
+ "docs_url": "https://developer.vimeo.com/api/reference/videos",
+ "columns": {
+ "video_uri": "URI of the video that the comment is about.",
+ "uri": "Unique identifier of the comment.",
+ "text": "Content of the comment.",
+ "created_on": "Time when the comment was posted, in ISO 8601 format.",
+ "user": "User who posted the comment.",
+ },
+ },
+ "video_comment_replies": {
+ "description": "Replies to the comments on the videos of the authenticated user.",
+ "docs_url": "https://developer.vimeo.com/api/reference/videos",
+ "columns": {
+ "comment_uri": "URI of the comment that the reply answers.",
+ "uri": "Unique identifier of the reply.",
+ "text": "Content of the reply.",
+ "created_on": "Time when the reply was posted, in ISO 8601 format.",
+ "user": "User who posted the reply.",
+ },
+ },
+ "video_likes": {
+ "description": "Users who liked each video of the authenticated user. A user appears once for each video that they liked.",
+ "docs_url": "https://developer.vimeo.com/api/reference/videos",
+ "columns": {
+ "video_uri": "URI of the video that the user liked.",
+ "uri": "URI that identifies the user.",
+ "name": "Display name of the user.",
+ },
+ },
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/vimeo/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/vimeo/settings.py
index a20eeb0d57ba..c4d6d12df64a 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/vimeo/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/vimeo/settings.py
@@ -1,3 +1,5 @@
+from posthog.dataclasses import frozen
+
BASE_URL = "https://api.vimeo.com"
PAGE_SIZE = 100
PRIMARY_KEYS = ["uri"]
@@ -8,6 +10,56 @@ ENDPOINTS = {
"showcases": "/me/albums",
}
+
+@frozen
+class VimeoFanout:
+ parent: str
+ # The parent's `metadata.connections` entry. Its `uri` is the child list path and its `total`
+ # lets a parent with an empty child list be skipped without a request.
+ connection: str
+ parent_uri_column: str
+ primary_keys: list[str]
+ params: dict[str, str]
+
+
+FANOUT_ENDPOINTS = {
+ "folder_videos": VimeoFanout(
+ parent="folders",
+ connection="videos",
+ parent_uri_column="folder_uri",
+ primary_keys=["folder_uri", "uri"],
+ params={"sort": "date", "direction": "asc"},
+ ),
+ "showcase_videos": VimeoFanout(
+ parent="showcases",
+ connection="videos",
+ parent_uri_column="showcase_uri",
+ primary_keys=["showcase_uri", "uri"],
+ params={"sort": "date", "direction": "asc"},
+ ),
+ "video_comments": VimeoFanout(
+ parent="videos",
+ connection="comments",
+ parent_uri_column="video_uri",
+ primary_keys=["uri"],
+ params={"direction": "asc"},
+ ),
+ "video_comment_replies": VimeoFanout(
+ parent="video_comments",
+ connection="replies",
+ parent_uri_column="comment_uri",
+ primary_keys=["uri"],
+ params={},
+ ),
+ "video_likes": VimeoFanout(
+ parent="videos",
+ connection="likes",
+ parent_uri_column="video_uri",
+ primary_keys=["video_uri", "uri"],
+ params={"sort": "date", "direction": "asc"},
+ ),
+}
+
AUTH_ERROR = "Vimeo rejected your access token. Generate an authenticated token for your account and reconnect."
PERMISSION_ERROR = (
"Vimeo denied access. Check your account permissions and enable the token's public and private scopes."
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/vimeo/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/vimeo/source.py
index 1460bae289c1..08e1c4882dff 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/vimeo/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/vimeo/source.py
@@ -26,6 +26,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.vimeo.cano
from products.warehouse_sources.backend.temporal.data_imports.sources.vimeo.settings import (
AUTH_ERROR,
ENDPOINTS,
+ FANOUT_ENDPOINTS,
PERMISSION_ERROR,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.vimeo.vimeo import (
@@ -74,7 +75,7 @@ class VimeoSource(ResumableSource[VimeoSourceConfig, VimeoResumeConfig]):
force_refresh: bool = False,
api_version: str | None = None,
) -> list[SourceSchema]:
- return build_endpoint_schemas(ENDPOINTS, {}, names)
+ return build_endpoint_schemas([*ENDPOINTS, *FANOUT_ENDPOINTS], {}, names)
def validate_credentials(
self,
@@ -114,7 +115,7 @@ class VimeoSource(ResumableSource[VimeoSourceConfig, VimeoResumeConfig]):
caption=(
"Open your app at [Vimeo Developers](https://developer.vimeo.com/apps). "
"Under **Generate an access token**, select **Authenticated (you)**. "
- "Enable `public` and `private` scopes to read your videos, folders, and showcases."
+ "Enable `public` and `private` scopes to read your videos, folders, showcases, comments, and likes."
),
fields=cast(
list[FieldType],
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/vimeo/tests/test_vimeo.py b/products/warehouse_sources/backend/temporal/data_imports/sources/vimeo/tests/test_vimeo.py
index 30af13889e74..f4b0bd5aa938 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/vimeo/tests/test_vimeo.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/vimeo/tests/test_vimeo.py
@@ -6,6 +6,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.tes
ScriptedResponse,
SourceDriver,
always,
+ route,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs.vimeo import VimeoSourceConfig
from products.warehouse_sources.backend.temporal.data_imports.sources.vimeo.settings import AUTH_ERROR, PERMISSION_ERROR
@@ -84,3 +85,145 @@ def test_resume_cannot_send_token_to_another_origin(resume_url: str) -> None:
assert isinstance(result.raised, ValueError)
assert "Refusing to send request" in str(result.raised)
assert result.requests == []
+
+
+def parent(uri: str, connection: str, link: dict[str, object] | None) -> dict[str, object]:
+ return {"uri": uri, "name": "ignored", "metadata": {"connections": {connection: link} if link else {}}}
+
+
+ "endpoint,parent_path,connection,parent_column,child_query",
+ [
+ ("folder_videos", "/me/projects", "videos", "folder_uri", {"sort": ("date",), "direction": ("asc",)}),
+ ("showcase_videos", "/me/albums", "videos", "showcase_uri", {"sort": ("date",), "direction": ("asc",)}),
+ ("video_comments", "/me/videos", "comments", "video_uri", {"direction": ("asc",)}),
+ ("video_likes", "/me/videos", "likes", "video_uri", {"sort": ("date",), "direction": ("asc",)}),
+ ],
+)
+def test_fanout_skips_empty_parents_and_tags_child_rows(
+ endpoint: str, parent_path: str, connection: str, parent_column: str, child_query: dict[str, tuple[str]]
+) -> None:
+ child_path = f"/parents/7/{connection}"
+ result = driver().run(
+ endpoint,
+ route(
+ {
+ parent_path: [
+ ScriptedResponse(
+ json={
+ "data": [
+ parent("/parents/5", connection, {"uri": f"/parents/5/{connection}", "total": 0}),
+ parent("/parents/6", connection, None),
+ parent("/parents/7", connection, {"uri": child_path, "total": 3}),
+ ],
+ "paging": {"next": None},
+ }
+ )
+ ],
+ child_path: [
+ ScriptedResponse(
+ json={"data": [{"uri": "/child/1"}], "paging": {"next": f"{child_path}?page=2&per_page=100"}}
+ ),
+ ScriptedResponse(json={"data": [{"uri": "/child/2"}], "paging": {"next": None}}),
+ ],
+ }
+ ),
+ )
+
+ assert result.raised is None
+ assert result.rows == [
+ {"uri": "/child/1", parent_column: "/parents/7"},
+ {"uri": "/child/2", parent_column: "/parents/7"},
+ ]
+ assert [request.path for request in result.requests] == [parent_path, child_path, child_path]
+ assert result.requests[0].query["fields"] == (
+ f"uri,metadata.connections.{connection}.uri,metadata.connections.{connection}.total",
+ )
+ assert result.requests[1].query == {"page": ("1",), "per_page": ("100",), **child_query}
+ for request in result.requests:
+ assert request.headers["authorization"] == "Bearer test-token"
+
+
+def test_comment_replies_walk_videos_then_comments() -> None:
+ result = driver().run(
+ "video_comment_replies",
+ route(
+ {
+ "/me/videos": [
+ ScriptedResponse(
+ json={
+ "data": [parent("/videos/1", "comments", {"uri": "/videos/1/comments", "total": 2})],
+ "paging": {"next": None},
+ }
+ )
+ ],
+ "/videos/1/comments": [
+ ScriptedResponse(
+ json={
+ "data": [
+ parent(
+ "/videos/1/comments/10",
+ "replies",
+ {"uri": "/videos/1/comments/10/replies", "total": 0},
+ ),
+ parent(
+ "/videos/1/comments/11",
+ "replies",
+ {"uri": "/videos/1/comments/11/replies", "total": 1},
+ ),
+ ],
+ "paging": {"next": None},
+ }
+ )
+ ],
+ "/videos/1/comments/11/replies": [
+ ScriptedResponse(json={"data": [{"uri": "/videos/1/comments/12"}], "paging": {"next": None}})
+ ],
+ }
+ ),
+ )
+
+ assert result.raised is None
+ assert result.rows == [{"uri": "/videos/1/comments/12", "comment_uri": "/videos/1/comments/11"}]
+ assert [request.path for request in result.requests] == [
+ "/me/videos",
+ "/videos/1/comments",
+ "/videos/1/comments/11/replies",
+ ]
+ assert result.requests[1].query["fields"] == (
+ "uri,metadata.connections.replies.uri,metadata.connections.replies.total",
+ )
+
+
+def test_fanout_resumes_after_completed_parents_and_ignores_deleted_parent() -> None:
+ result = driver().run(
+ "video_likes",
+ route(
+ {
+ "/me/videos": [
+ ScriptedResponse(
+ json={
+ "data": [
+ parent("/videos/1", "likes", {"uri": "/videos/1/likes", "total": 1}),
+ parent("/videos/2", "likes", {"uri": "/videos/2/likes", "total": 1}),
+ parent("/videos/3", "likes", {"uri": "/videos/3/likes", "total": 1}),
+ ],
+ "paging": {"next": None},
+ }
+ )
+ ],
+ "/videos/2/likes": [
+ ScriptedResponse(status=404, json={"error": "The requested video couldn't be found."})
+ ],
+ "/videos/3/likes": [ScriptedResponse(json={"data": [{"uri": "/users/9"}], "paging": {"next": None}})],
+ }
+ ),
+ resume_state=VimeoResumeConfig(completed=["/videos/1/likes"]),
+ )
+
+ assert result.raised is None
+ assert result.rows == [{"uri": "/users/9", "video_uri": "/videos/3"}]
+ assert [request.path for request in result.requests] == ["/me/videos", "/videos/2/likes", "/videos/3/likes"]
+ assert result.saved_states[-1] == VimeoResumeConfig(
+ completed=["/videos/1/likes", "/videos/2/likes", "/videos/3/likes"]
+ )
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/vimeo/tests/test_vimeo_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/vimeo/tests/test_vimeo_source.py
index 74a35d319f4d..90a54b311244 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/vimeo/tests/test_vimeo_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/vimeo/tests/test_vimeo_source.py
@@ -13,17 +13,19 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.vimeo.sour
@pytest.mark.parametrize(
- "status,schema,expected",
+ "status,schema,path,expected",
[
- (200, None, (True, None)),
- (401, None, (False, AUTH_ERROR)),
- (403, None, (True, None)),
- (200, "folders", (True, None)),
- (401, "folders", (False, AUTH_ERROR)),
- (403, "folders", (False, PERMISSION_ERROR)),
+ (200, None, "/me", (True, None)),
+ (401, None, "/me", (False, AUTH_ERROR)),
+ (403, None, "/me", (True, None)),
+ (200, "folders", "/me/projects", (True, None)),
+ (401, "folders", "/me/projects", (False, AUTH_ERROR)),
+ (403, "folders", "/me/projects", (False, PERMISSION_ERROR)),
+ (200, "showcase_videos", "/me/albums", (True, None)),
+ (403, "video_comment_replies", "/me/videos", (False, PERMISSION_ERROR)),
],
)
-def test_credentials_probe(status: int, schema: str | None, expected: tuple[bool, str | None]) -> None:
+def test_credentials_probe(status: int, schema: str | None, path: str, expected: tuple[bool, str | None]) -> None:
with scripted_network([ScriptedResponse(status=status, json={})]) as network:
assert (
VimeoSource().validate_credentials(VimeoSourceConfig(access_token="test-token"), 1, schema_name=schema)
@@ -31,7 +33,7 @@ def test_credentials_probe(status: int, schema: str | None, expected: tuple[bool
)
assert len(network.requests_log) == 1
request = network.requests_log[0]
- assert request.path == ("/me/projects" if schema else "/me")
+ assert request.path == path
assert request.query == ({"per_page": ("1",)} if schema else {"fields": ("uri",)})
assert request.headers["authorization"] == "Bearer test-token"
assert request.headers["accept"] == "application/vnd.vimeo.*+json;version=3.4"
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/vimeo/vimeo.py b/products/warehouse_sources/backend/temporal/data_imports/sources/vimeo/vimeo.py
index 8a2823865b16..d11a7edef7a5 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/vimeo/vimeo.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/vimeo/vimeo.py
@@ -1,3 +1,4 @@
+from collections.abc import Callable
from typing import Any
from requests import HTTPError
@@ -7,10 +8,16 @@ from posthog.dataclasses import frozen
from products.warehouse_sources.backend.temporal.data_imports.sources.common.http import make_tracked_session
from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source import (
RESTAPIConfig,
- rest_api_resource,
+ rest_api_resources,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.auth import BearerTokenAuth
-from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.resource import Resource
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.fanout import (
+ rename_parent_fields,
+)
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.typing import (
+ Endpoint,
+ EndpointResource,
+)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManager
from products.warehouse_sources.backend.temporal.data_imports.sources.common.schema import schema_for_resource
from products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SourceResponse
@@ -18,6 +25,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.vimeo.sett
AUTH_ERROR,
BASE_URL,
ENDPOINTS,
+ FANOUT_ENDPOINTS,
PAGE_SIZE,
PERMISSION_ERROR,
PRIMARY_KEYS,
@@ -26,15 +34,27 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.vimeo.sett
@frozen
class VimeoResumeConfig:
- next_url: str
+ # Top-level endpoints resume from the `paging.next` URL of the last page.
+ next_url: str | None = None
+ # Fan-out endpoints resume by parent, in the shape of
+ # `common.rest_source.__init__._make_paginate_dependent_resource`.
+ completed: list[str] | None = None
+ current: str | None = None
+ child_state: dict[str, Any] | None = None
def vimeo_headers(api_version: str) -> dict[str, str]:
return {"Accept": f"application/vnd.vimeo.*+json;version={api_version}"}
+def _top_level_endpoint(endpoint: str) -> str:
+ while endpoint in FANOUT_ENDPOINTS:
+ endpoint = FANOUT_ENDPOINTS[endpoint].parent
+ return endpoint
+
+
def validate_credentials(access_token: str, api_version: str, schema_name: str | None) -> tuple[bool, str | None]:
- path = schema_for_resource(ENDPOINTS, schema_name) if schema_name else "/me"
+ path = schema_for_resource(ENDPOINTS, _top_level_endpoint(schema_name)) if schema_name else "/me"
params: dict[str, str | int] = {"per_page": 1} if schema_name else {"fields": "uri"}
with make_tracked_session() as session:
response = session.get(
@@ -55,6 +75,51 @@ def validate_credentials(access_token: str, api_version: str, schema_name: str |
return True, None
+def _connection_link(connection: str) -> Callable[[dict[str, Any]], dict[str, Any] | list[dict[str, Any]]]:
+ def _link(row: dict[str, Any]) -> dict[str, Any] | list[dict[str, Any]]:
+ link = ((row.get("metadata") or {}).get("connections") or {}).get(connection) or {}
+ if not link.get("uri") or link.get("total") == 0:
+ return []
+ return {"uri": row["uri"], "connection_uri": link["uri"]}
+
+ return _link
+
+
+def _resource_chain(endpoint: str, connection: str | None = None) -> list[EndpointResource]:
+ """Resources from a top-level list down to `endpoint`.
+
+ When `connection` is set, `endpoint` is a parent: it reads only the fields the next level needs.
+ """
+ params: dict[str, Any] = {"page": 1, "per_page": PAGE_SIZE}
+ resource: EndpointResource = {"name": endpoint, "write_disposition": "replace", "endpoint": {}}
+ chain: list[EndpointResource] = []
+ fanout = FANOUT_ENDPOINTS.get(endpoint)
+ if fanout is None:
+ path = schema_for_resource(ENDPOINTS, endpoint)
+ params.update({"sort": "date", "direction": "asc"})
+ else:
+ chain = _resource_chain(fanout.parent, fanout.connection)
+ path = "{connection_uri}"
+ params.update(fanout.params)
+ params["connection_uri"] = {"type": "resolve", "resource": fanout.parent, "field": "connection_uri"}
+ resource["include_from_parent"] = ["uri"]
+ if connection is not None:
+ params["fields"] = f"uri,metadata.connections.{connection}.uri,metadata.connections.{connection}.total"
+ resource["data_map"] = _connection_link(connection)
+ endpoint_config: Endpoint = {
+ "path": path,
+ "params": params,
+ "paginator": {"type": "json_response", "next_url_path": "paging.next"},
+ "data_selector": "data",
+ "data_selector_required": True,
+ }
+ if fanout is not None:
+ # A parent deleted between its listing and this request must not fail the sync.
+ endpoint_config["response_actions"] = [{"status_code": 404, "action": "ignore"}]
+ resource["endpoint"] = endpoint_config
+ return [*chain, resource]
+
+
def vimeo_source(
access_token: str,
endpoint: str,
@@ -63,42 +128,42 @@ def vimeo_source(
job_id: str,
resumable_source_manager: ResumableSourceManager[VimeoResumeConfig],
) -> SourceResponse:
- path = schema_for_resource(ENDPOINTS, endpoint)
config: RESTAPIConfig = {
"client": {
"base_url": BASE_URL,
"auth": {"type": "bearer", "token": access_token},
"headers": vimeo_headers(api_version),
- "paginator": {"type": "json_response", "next_url_path": "paging.next"},
"allowed_hosts": ["api.vimeo.com"],
"allow_redirects": False,
"request_timeout": 30,
},
- "resources": [
- {
- "name": endpoint,
- "primary_key": PRIMARY_KEYS,
- "write_disposition": "replace",
- "endpoint": {
- "path": path,
- "params": {"page": 1, "per_page": PAGE_SIZE, "sort": "date", "direction": "asc"},
- "data_selector": "data",
- "data_selector_required": True,
- },
- }
- ],
+ "resources": [*_resource_chain(endpoint)],
}
- initial_state = None
+ initial_state: dict[str, Any] | None = None
if resumable_source_manager.can_resume():
state = resumable_source_manager.load_state()
- if state is not None:
+ if state is not None and state.next_url:
initial_state = {"next_url": state.next_url}
+ elif state is not None and (state.completed or state.current):
+ initial_state = {
+ "completed": state.completed or [],
+ "current": state.current,
+ "child_state": state.child_state,
+ }
def save_checkpoint(state: dict[str, Any] | None) -> None:
- if state and state.get("next_url"):
+ if not state:
+ return
+ if state.get("next_url"):
resumable_source_manager.save_state(VimeoResumeConfig(next_url=state["next_url"]))
+ elif "completed" in state:
+ resumable_source_manager.save_state(
+ VimeoResumeConfig(
+ completed=state["completed"], current=state.get("current"), child_state=state.get("child_state")
+ )
+ )
- resource: Resource = rest_api_resource(
+ resources = rest_api_resources(
config,
team_id,
job_id,
@@ -106,4 +171,9 @@ def vimeo_source(
resume_hook=save_checkpoint,
initial_paginator_state=initial_state,
)
- return SourceResponse(name=endpoint, items=lambda: resource, primary_keys=PRIMARY_KEYS)
+ resource = next(r for r in resources if r.name == endpoint)
+ fanout = FANOUT_ENDPOINTS.get(endpoint)
+ if fanout is not None:
+ resource.add_map(rename_parent_fields(fanout.parent, {"uri": fanout.parent_uri_column}))
+ primary_keys = fanout.primary_keys if fanout is not None else PRIMARY_KEYS
+ return SourceResponse(name=endpoint, items=lambda: resource, primary_keys=primary_keys)