diff --git a/posthog/temporal/data_imports/pipelines/hubspot/__init__.py b/posthog/temporal/data_imports/pipelines/hubspot/__init__.py index 39aa377cbd25e..656506af7a65a 100644 --- a/posthog/temporal/data_imports/pipelines/hubspot/__init__.py +++ b/posthog/temporal/data_imports/pipelines/hubspot/__init__.py @@ -24,7 +24,6 @@ """ from typing import Literal, Sequence, Iterator -from urllib.parse import quote import dlt from dlt.common.typing import TDataItems @@ -38,14 +37,9 @@ from .settings import ( ALL, CRM_OBJECT_ENDPOINTS, - DEFAULT_COMPANY_PROPS, - DEFAULT_CONTACT_PROPS, - DEFAULT_DEAL_PROPS, - DEFAULT_TICKET_PROPS, - DEFAULT_QUOTE_PROPS, + DEFAULT_PROPS, OBJECT_TYPE_PLURAL, - STARTDATE, - WEB_ANALYTICS_EVENTS_ENDPOINT, + OBJECT_TYPE_SINGULAR, ) THubspotObjectType = Literal["company", "contact", "deal", "ticket", "quote"] @@ -84,106 +78,20 @@ def hubspot( `api_key` argument. """ - @dlt.resource(name="companies", write_disposition="replace") - def companies( - api_key: str = api_key, - include_history: bool = include_history, - props: Sequence[str] = DEFAULT_COMPANY_PROPS, - include_custom_props: bool = True, - ) -> Iterator[TDataItems]: - """Hubspot companies resource""" - yield from crm_objects( - "company", - api_key, - refresh_token, - include_history=include_history, - props=props, - include_custom_props=include_custom_props, - ) - - @dlt.resource(name="contacts", write_disposition="replace") - def contacts( - api_key: str = api_key, - include_history: bool = include_history, - props: Sequence[str] = DEFAULT_CONTACT_PROPS, - include_custom_props: bool = True, - ) -> Iterator[TDataItems]: - """Hubspot contacts resource""" - yield from crm_objects( - "contact", - api_key, - refresh_token, - include_history, - props, - include_custom_props, - ) - - @dlt.resource(name="deals", write_disposition="replace") - def deals( - api_key: str = api_key, - include_history: bool = include_history, - props: Sequence[str] = DEFAULT_DEAL_PROPS, - include_custom_props: bool = True, - ) -> Iterator[TDataItems]: - """Hubspot deals resource""" - yield from crm_objects( - "deal", - api_key, - refresh_token, - include_history, - props, - include_custom_props, - ) - - @dlt.resource(name="tickets", write_disposition="replace") - def tickets( - api_key: str = api_key, - include_history: bool = include_history, - props: Sequence[str] = DEFAULT_TICKET_PROPS, - include_custom_props: bool = True, - ) -> Iterator[TDataItems]: - """Hubspot tickets resource""" - yield from crm_objects( - "ticket", - api_key, - refresh_token, - include_history, - props, - include_custom_props, - ) - - @dlt.resource(name="quotes", write_disposition="replace") - def quotes( - api_key: str = api_key, - include_history: bool = include_history, - props: Sequence[str] = DEFAULT_QUOTE_PROPS, - include_custom_props: bool = True, - ) -> Iterator[TDataItems]: - """Hubspot quotes resource""" - yield from crm_objects( - "quote", + for endpoint in endpoints: + yield dlt.resource( + crm_objects, + name=endpoint, + write_disposition="append", + )( + OBJECT_TYPE_SINGULAR[endpoint], api_key, refresh_token, include_history, - props, - include_custom_props, + DEFAULT_PROPS[endpoint], + include_custom_props=True, ) - resource_map = { - "companies": companies, - "contacts": contacts, - "deals": deals, - "tickets": tickets, - "quotes": quotes, - } - - resources = () - - for endpoint in endpoints: - resources += (resource_map[endpoint],) - - return resources - def crm_objects( object_type: str, diff --git a/posthog/temporal/data_imports/pipelines/hubspot/settings.py b/posthog/temporal/data_imports/pipelines/hubspot/settings.py index 32cbcc6de37f2..10af4c47b5a31 100644 --- a/posthog/temporal/data_imports/pipelines/hubspot/settings.py +++ b/posthog/temporal/data_imports/pipelines/hubspot/settings.py @@ -95,4 +95,12 @@ "hs_title", ] +DEFAULT_PROPS = { + OBJECT_TYPE_PLURAL[CONTACT]: DEFAULT_CONTACT_PROPS, + OBJECT_TYPE_PLURAL[COMPANY]: DEFAULT_COMPANY_PROPS, + OBJECT_TYPE_PLURAL[DEAL]: DEFAULT_DEAL_PROPS, + OBJECT_TYPE_PLURAL[TICKET]: DEFAULT_TICKET_PROPS, + OBJECT_TYPE_PLURAL[QUOTE]: DEFAULT_QUOTE_PROPS, +} + ALL = ("ALL",)