From 9b2c74ac21f2cff0eb4e82a4aa0bfd8aff49c0db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Sehnem?= Date: Sun, 17 Sep 2023 10:17:16 -0300 Subject: [PATCH] add numeric ids --- tap_shopify/client.py | 27 ++++++++++++++++++++++++++- tap_shopify/tap.py | 6 ++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/tap_shopify/client.py b/tap_shopify/client.py index ec421d5..8925537 100644 --- a/tap_shopify/client.py +++ b/tap_shopify/client.py @@ -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) \ No newline at end of file + 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 \ No newline at end of file diff --git a/tap_shopify/tap.py b/tap_shopify/tap.py index 2b09d2c..f66aad3 100644 --- a/tap_shopify/tap.py +++ b/tap_shopify/tap.py @@ -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,