Skip to content

Commit

Permalink
add numeric ids
Browse files Browse the repository at this point in the history
  • Loading branch information
sehnem committed Sep 17, 2023
1 parent 47d31e2 commit 9b2c74a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
27 changes: 26 additions & 1 deletion tap_shopify/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,29 @@ def validate_response(self, response: requests.Response) -> None:
< HTTPStatus.INTERNAL_SERVER_ERROR
):
msg = self.response_error_message(response)
raise FatalAPIError(msg)
raise FatalAPIError(msg)

def convert_id_fields(self, row: dict) -> dict:
"""Convert the id fields to string."""
if not isinstance(row, dict):
return row
for key, value in row.items():
if key=="id" and isinstance(value, str):
row["id"] = row["id"].split("/")[-1].split("?")[0]
elif isinstance(value, dict):
row[key] = self.convert_id_fields(value)
elif isinstance(value, list):
row[key] = [self.convert_id_fields(v) for v in value]
return row

def post_process(
self,
row: dict,
context: dict | None = None, # noqa: ARG002
) -> dict | None:
"""As needed, append or transform raw data to match expected structure."""

if self.config["use_numeric_ids"]:
self.convert_id_fields(row)

return row
6 changes: 6 additions & 0 deletions tap_shopify/tap.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ class TapShopify(Tap):
default=False,
description="To use the bulk API or not.",
),
th.Property(
"use_numeric_ids",
th.BooleanType,
default=False,
description="To use numeric ids instead of the graphql format ids.",
),
th.Property(
"ignore_deprecated",
th.BooleanType,
Expand Down

0 comments on commit 9b2c74a

Please sign in to comment.