Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parse boolean fields to always be boolean #67

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions tap_hubspot_beta/client_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,18 @@ def stream_maps(self) -> List[StreamMap]:
]
return self._stream_maps

def parse_value(self, field, value):
if "boolean" == self.schema["properties"].get(field, {}).get("type", [""])[0] and value in ["true", "false", "True", "False"]:
value = True if value.lower() == "true" else False if value.lower() == "false" else value
return value

def parse_properties(self, row):
if self.properties_url:
for name, value in row["properties"].items():
row[name] = self.parse_value(name, value)
del row["properties"]
return row


class hubspotStreamSchema(hubspotStream):

Expand Down
2 changes: 1 addition & 1 deletion tap_hubspot_beta/client_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def post_process(self, row: dict, context: Optional[dict]) -> dict:
if self.properties_url:
if row.get("properties"):
for name, value in row.get("properties", {}).items():
row[name] = value.get("value")
row[name] = self.parse_value(name, value.get("value"))
del row["properties"]
for field in self.datetime_fields:
if row.get(field) is not None:
Expand Down
15 changes: 3 additions & 12 deletions tap_hubspot_beta/client_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,7 @@ def prepare_request_payload(

def post_process(self, row: dict, context: Optional[dict]) -> dict:
"""As needed, append or transform raw data to match expected structure."""
if self.properties_url:
for name, value in row["properties"].items():
row[name] = value
del row["properties"]
row = self.parse_properties(row)
return row

def _sync_records( # noqa C901 # too complex
Expand Down Expand Up @@ -212,10 +209,7 @@ def get_url_params(

def post_process(self, row: dict, context: Optional[dict]) -> dict:
"""As needed, append or transform raw data to match expected structure."""
if self.properties_url:
for name, value in row["properties"].items():
row[name] = value
del row["properties"]
row = self.parse_properties(row)
return row


Expand Down Expand Up @@ -267,8 +261,5 @@ def prepare_request_payload(

def post_process(self, row: dict, context: Optional[dict]) -> dict:
"""As needed, append or transform raw data to match expected structure."""
if self.properties_url:
for name, value in row["properties"].items():
row[name] = value
del row["properties"]
row = self.parse_properties(row)
return row