Skip to content

Commit

Permalink
add owners archived stream (#94)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Hassan Syyid <[email protected]>
  • Loading branch information
keyn4 and hsyyid authored Nov 6, 2024
1 parent 925f2f0 commit eedec50
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 3 deletions.
60 changes: 59 additions & 1 deletion tap_hubspot_beta/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,9 +595,16 @@ class OwnersStream(hubspotV3Stream):
th.Property("archived", th.BooleanType),
th.Property("userId", th.IntegerType),
th.Property("updatedAt", th.DateTimeType),
th.Property("updatedAt", th.DateTimeType),
th.Property("createdAt", th.DateTimeType),
th.Property("archivedAt", th.DateTimeType),
th.Property("_hg_archived", th.BooleanType),
).to_dict()

def post_process(self, row: dict, context: Optional[dict]) -> dict:
"""As needed, append or transform raw data to match expected structure."""
row = super().post_process(row, context)
row["_hg_archived"] = False
return row

class ListsStream(hubspotV1Stream):
"""Lists Stream"""
Expand Down Expand Up @@ -1657,6 +1664,57 @@ class CurrenciesStream(hubspotV3Stream):
th.Property("updatedAt", th.DateTimeType),
).to_dict()


class ArchivedOwnersStream(ArchivedStream):
"""Archived Owners Stream"""

name = "owners_archived"
replication_key = "archivedAt"
path = "crm/v3/owners/?archived=true"
primary_keys = ["id"]

schema = OwnersStream.schema

@property
def selected(self) -> bool:
"""Check if stream is selected.
Returns:
True if the stream is selected.
"""
# It has to be in the catalog or it will cause issues
if not self._tap.catalog.get("owners_archived"):
return False
try:
# Make this stream auto-select if owners is selected
self._tap.catalog["owners_archived"] = self._tap.catalog["owners"]
return self.mask.get((), False) or self._tap.catalog["owners"].metadata.get(()).selected
except:
return self.mask.get((), False)

def _write_record_message(self, record: dict) -> None:
"""Write out a RECORD message.
Args:
record: A single stream record.
"""
for record_message in self._generate_record_messages(record):
# force this to think it's the owners stream
record_message.stream = "owners"
singer.write_message(record_message)

@property
def metadata(self):
new_metadata = super().metadata
new_metadata[("properties", "archivedAt")].selected = True
new_metadata[("properties", "archivedAt")].selected_by_default = True
return new_metadata

def post_process(self, row, context):
# archivedAt is not in the response for static resources, using updatedAt
row["archivedAt"] = row["updatedAt"]
row = super().post_process(row, context)
return row


# Get associations for engagements streams in v3

class AssociationMeetingsStream(hubspotV4Stream):
Expand Down
6 changes: 4 additions & 2 deletions tap_hubspot_beta/tap.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
AssociationTasksContactsStream,
AssociationTasksDealsStream,
DealsHistoryPropertiesStream,
ContactsHistoryPropertiesStream
ContactsHistoryPropertiesStream,
ArchivedOwnersStream
)

STREAM_TYPES = [
Expand Down Expand Up @@ -140,7 +141,8 @@
AssociationTasksContactsStream,
AssociationTasksDealsStream,
DealsHistoryPropertiesStream,
ContactsHistoryPropertiesStream
ContactsHistoryPropertiesStream,
ArchivedOwnersStream
]


Expand Down

0 comments on commit eedec50

Please sign in to comment.