Skip to content

Commit

Permalink
reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
EDsCODE committed Dec 29, 2023
1 parent 91a3e29 commit 0cce8d3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 103 deletions.
114 changes: 11 additions & 103 deletions posthog/temporal/data_imports/pipelines/hubspot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"""

from typing import Literal, Sequence, Iterator
from urllib.parse import quote

import dlt
from dlt.common.typing import TDataItems
Expand All @@ -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"]
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions posthog/temporal/data_imports/pipelines/hubspot/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",)

0 comments on commit 0cce8d3

Please sign in to comment.