Skip to content

Commit

Permalink
source-hubspot-native: add line items binding
Browse files Browse the repository at this point in the history
Adds a new incremental binding for "line items".

Like "products", we don't have any "line items" in our test account and I'm not
going to put any in there so the capture snapshot output is unchanged.
  • Loading branch information
williamhbaker committed Nov 22, 2024
1 parent 946cbaa commit e0cdc98
Show file tree
Hide file tree
Showing 7 changed files with 439 additions and 1 deletion.
4 changes: 4 additions & 0 deletions source-hubspot-native/acmeCo/flow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ collections:
schema: engagements.schema.yaml
key:
- /id
acmeCo/line_items:
schema: line_items.schema.yaml
key:
- /id
acmeCo/owners:
schema: owners.schema.yaml
key:
Expand Down
152 changes: 152 additions & 0 deletions source-hubspot-native/acmeCo/line_items.schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
---
$defs:
History:
additionalProperties: false
properties:
_meta:
allOf:
- $ref: "#/$defs/Meta"
default:
op: u
row_id: -1
description: Document metadata
timestamp:
format: date-time
title: Timestamp
type: string
value:
title: Value
type: string
sourceType:
title: Sourcetype
type: string
sourceId:
anyOf:
- type: string
- type: "null"
default: ~
title: Sourceid
sourceLabel:
anyOf:
- type: string
- type: "null"
default: ~
title: Sourcelabel
updatedByUserId:
anyOf:
- type: integer
- type: "null"
default: ~
title: Updatedbyuserid
required:
- timestamp
- value
- sourceType
title: History
type: object
Meta:
properties:
op:
default: u
description: "Operation type (c: Create, u: Update, d: Delete)"
enum:
- c
- u
- d
title: Op
type: string
row_id:
default: -1
description: "Row ID of the Document, counting up from zero, or -1 if not known"
title: Row Id
type: integer
title: Meta
type: object
additionalProperties: false
properties:
_meta:
allOf:
- $ref: "#/$defs/Meta"
default:
op: u
row_id: -1
description: Document metadata
id:
title: Id
type: integer
createdAt:
format: date-time
title: Createdat
type: string
updatedAt:
format: date-time
title: Updatedat
type: string
archived:
title: Archived
type: boolean
properties:
type: object
additionalProperties:
anyOf:
- type: string
- type: "null"
title: Properties
propertiesWithHistory:
additionalProperties:
items:
$ref: "#/$defs/History"
type: array
default: {}
title: Propertieswithhistory
type: object
associations:
additionalProperties: false
default: {}
title: Associations
type: object
commerce_payments:
default: []
items:
type: integer
title: Commerce Payments
type: array
products:
default: []
items:
type: integer
title: Products
type: array
deals:
default: []
items:
type: integer
title: Deals
type: array
invoices:
default: []
items:
type: integer
title: Invoices
type: array
quotes:
default: []
items:
type: integer
title: Quotes
type: array
subscriptions:
default: []
items:
type: integer
title: Subscriptions
type: array
required:
- id
- createdAt
- updatedAt
- archived
- properties
title: LineItem
type: object
x-infer-schema: true
26 changes: 25 additions & 1 deletion source-hubspot-native/source_hubspot_native/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
EmailEvent,
EmailEventsResponse,
Engagement,
LineItem,
Names,
OldRecentCompanies,
OldRecentContacts,
Expand Down Expand Up @@ -952,10 +953,33 @@ async def do_fetch(page: PageCursor, count: int) -> tuple[Iterable[tuple[datetim
return await fetch_search_objects(Names.products, log, http, since, until, page)

return fetch_changes_with_associations(
Names.contacts, Product, do_fetch, log, http, since, until
Names.products, Product, do_fetch, log, http, since, until
)


def fetch_recent_line_items(
log: Logger, http: HTTPSession, since: datetime, until: datetime | None
) -> AsyncGenerator[tuple[datetime, str, LineItem], None]:

async def do_fetch(page: PageCursor, count: int) -> tuple[Iterable[tuple[datetime, str]], PageCursor]:
return await fetch_search_objects(Names.line_items, log, http, since, until, page)

return fetch_changes_with_associations(
Names.line_items, LineItem, do_fetch, log, http, since, until
)


def fetch_delayed_line_items(
log: Logger, http: HTTPSession, since: datetime, until: datetime
) -> AsyncGenerator[tuple[datetime, str, LineItem], None]:

async def do_fetch(page: PageCursor, count: int) -> tuple[Iterable[tuple[datetime, str]], PageCursor]:
return await fetch_search_objects(Names.line_items, log, http, since, until, page)

return fetch_changes_with_associations(
Names.line_items, LineItem, do_fetch, log, http, since, until
)

async def list_custom_objects(
log: Logger,
http: HTTPSession,
Expand Down
15 changes: 15 additions & 0 deletions source-hubspot-native/source_hubspot_native/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,20 @@ class EndpointConfig(BaseModel):

# Names of things within the HubSpot API domain.
class Names(StrEnum):
commerce_payments = auto()
companies = auto()
contacts = auto()
deal_pipelines = auto()
deals = auto()
email_events = auto()
engagements = auto()
invoices = auto()
line_items = auto()
owners = auto()
products = auto()
properties = auto()
quotes = auto()
subscriptions = auto()
tickets = auto()


Expand Down Expand Up @@ -228,6 +232,17 @@ class Product(BaseCRMObject):
ASSOCIATED_ENTITIES = []


class LineItem(BaseCRMObject):
ASSOCIATED_ENTITIES = [Names.commerce_payments, Names.products, Names.deals, Names.invoices, Names.quotes, Names.subscriptions]

commerce_payments: list[int] = []
products: list[int] = []
deals: list[int] = []
invoices: list[int] = []
quotes: list[int] = []
subscriptions: list[int] = []


# An Association, as returned by the v4 associations API.
class Association(BaseModel, extra="forbid"):

Expand Down
4 changes: 4 additions & 0 deletions source-hubspot-native/source_hubspot_native/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
fetch_delayed_deals,
fetch_delayed_email_events,
fetch_delayed_engagements,
fetch_delayed_line_items,
fetch_delayed_products,
fetch_delayed_tickets,
fetch_email_events_page,
Expand All @@ -31,6 +32,7 @@
fetch_recent_deals,
fetch_recent_email_events,
fetch_recent_engagements,
fetch_recent_line_items,
fetch_recent_products,
fetch_recent_tickets,
list_custom_objects,
Expand All @@ -47,6 +49,7 @@
EmailEvent,
EndpointConfig,
Engagement,
LineItem,
Names,
Owner,
Product,
Expand Down Expand Up @@ -96,6 +99,7 @@ async def all_resources(
crm_object_with_associations(Engagement, Names.engagements, Names.engagements, http, fetch_recent_engagements, fetch_delayed_engagements),
crm_object_with_associations(Ticket, Names.tickets, Names.tickets, http, fetch_recent_tickets, fetch_delayed_tickets),
crm_object_with_associations(Product, Names.products, Names.products, http, fetch_recent_products, fetch_delayed_products),
crm_object_with_associations(LineItem, Names.line_items, Names.line_items, http, fetch_recent_line_items, fetch_delayed_line_items),
properties(http, itertools.chain(standard_object_names, custom_object_path_components)),
email_events(http),
deal_pipelines(http),
Expand Down
8 changes: 8 additions & 0 deletions source-hubspot-native/test.flow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ captures:
command:
- python
- "-m"
# - "-m"
# - "debugpy"
# - "--listen"
# - "0.0.0.0:5678"
# - "--wait-for-client"
- source_hubspot_native
config: config.yaml
bindings:
Expand All @@ -29,6 +34,9 @@ captures:
- resource:
name: products
target: acmeCo/products
- resource:
name: line_items
target: acmeCo/line_items
- resource:
name: properties
interval: P1D
Expand Down
Loading

0 comments on commit e0cdc98

Please sign in to comment.