From d784637932760bebd86e4f2bf83c010f46eb6003 Mon Sep 17 00:00:00 2001 From: Pat Nadolny Date: Thu, 24 Oct 2024 16:16:41 -0400 Subject: [PATCH] rename to unencoded and add doc string --- tap_linkedin_ads/client.py | 16 +++-- tap_linkedin_ads/streams.py | 122 +++++++++++++++++++++++++++++++----- 2 files changed, 117 insertions(+), 21 deletions(-) diff --git a/tap_linkedin_ads/client.py b/tap_linkedin_ads/client.py index fb9042a..69b47fc 100644 --- a/tap_linkedin_ads/client.py +++ b/tap_linkedin_ads/client.py @@ -105,7 +105,15 @@ def parse_response(self, response: requests.Response) -> t.Iterable[dict]: """ yield from extract_jsonpath(self.records_jsonpath, input=response.json()) - def get_unescaped_params(self, context: Context | None) -> dict: + def get_unencoded_params(self, context: Context | None) -> dict: + """Return a dictionary of unencoded params. + + Args: + context: The stream context. + + Returns: + A dictionary of URL query parameters. + """ return {} def request_records(self, context: Context | None) -> t.Iterable[dict]: @@ -131,15 +139,15 @@ def request_records(self, context: Context | None) -> t.Iterable[dict]: context, next_page_token=paginator.current_value, ) - # Patch to add unescaped params to the path and url - if self.get_unescaped_params(context): + # Patch to add unencoded params to the path and url + if self.get_unencoded_params(context): prepared_request.url = ( prepared_request.url + "&" + "&".join( [ f"{k}={v}" - for k, v in self.get_unescaped_params(context).items() + for k, v in self.get_unencoded_params(context).items() ], ) ) diff --git a/tap_linkedin_ads/streams.py b/tap_linkedin_ads/streams.py index 722e00f..a4f0faa 100644 --- a/tap_linkedin_ads/streams.py +++ b/tap_linkedin_ads/streams.py @@ -168,7 +168,15 @@ def get_url_params( **super().get_url_params(context, next_page_token), } - def get_unescaped_params(self, context: Context | None) -> dict: + def get_unencoded_params(self, context: Context | None) -> dict: + """Return a dictionary of unencoded params. + + Args: + context: The stream context. + + Returns: + A dictionary of URL query parameters. + """ return { "accounts": f"urn:li:sponsoredAccount:{context['account_id']}", } @@ -462,7 +470,15 @@ def get_url_params( **super().get_url_params(context, next_page_token), } - def get_unescaped_params(self, context: Context | None) -> dict: + def get_unencoded_params(self, context: Context | None) -> dict: + """Return a dictionary of unencoded params. + + Args: + context: The stream context. + + Returns: + A dictionary of URL query parameters. + """ return { "search": "(status:(values:List(ACTIVE,PAUSED,ARCHIVED,COMPLETED,CANCELED,DRAFT,PENDING_DELETION,REMOVED)))" } @@ -560,7 +576,15 @@ def get_url_params( **super().get_url_params(context, next_page_token), } - def get_unescaped_params(self, context: Context | None) -> dict: + def get_unencoded_params(self, context: Context | None) -> dict: + """Return a dictionary of unencoded params. + + Args: + context: The stream context. + + Returns: + A dictionary of URL query parameters. + """ return { "search": "(status:(values:List(ACTIVE,ARCHIVED,CANCELED,DRAFT,PAUSED,PENDING_DELETION,REMOVED)))" } @@ -876,7 +900,15 @@ def get_url_params( **super().get_url_params(context, next_page_token), } - def get_unescaped_params(self, context: Context | None) -> dict: + def get_unencoded_params(self, context: Context | None) -> dict: + """Return a dictionary of unencoded params. + + Args: + context: The stream context. + + Returns: + A dictionary of URL query parameters. + """ start_date = pendulum.parse(self.config["start_date"]) end_date = pendulum.parse(self.config["end_date"]) return { @@ -905,9 +937,17 @@ def post_process(self, row: dict, context: dict | None = None) -> dict | None: class AdAnalyticsByCampaignSecond(AdAnalyticsByCampaignInit): name = "adanalyticsbycampaign_second" - def get_unescaped_params(self, context: Context | None) -> dict: + def get_unencoded_params(self, context: Context | None) -> dict: + """Return a dictionary of unencoded params. + + Args: + context: The stream context. + + Returns: + A dictionary of URL query parameters. + """ return { - **super().get_unescaped_params(context), + **super().get_unencoded_params(context), # Overwrite fields with this column subset "fields": self.adanalyticscolumns[0], } @@ -916,9 +956,17 @@ def get_unescaped_params(self, context: Context | None) -> dict: class AdAnalyticsByCampaignThird(AdAnalyticsByCampaignInit): name = "adanalyticsbycampaign_third" - def get_unescaped_params(self, context: Context | None) -> dict: + def get_unencoded_params(self, context: Context | None) -> dict: + """Return a dictionary of unencoded params. + + Args: + context: The stream context. + + Returns: + A dictionary of URL query parameters. + """ return { - **super().get_unescaped_params(context), + **super().get_unencoded_params(context), # Overwrite fields with this column subset "fields": self.adanalyticscolumns[3], } @@ -927,9 +975,17 @@ def get_unescaped_params(self, context: Context | None) -> dict: class AdAnalyticsByCampaignStream(AdAnalyticsByCampaignInit): name = "ad_analytics_by_campaign" - def get_unescaped_params(self, context: Context | None) -> dict: + def get_unencoded_params(self, context: Context | None) -> dict: + """Return a dictionary of unencoded params. + + Args: + context: The stream context. + + Returns: + A dictionary of URL query parameters. + """ return { - **super().get_unescaped_params(context), + **super().get_unencoded_params(context), # Overwrite fields with this column subset "fields": self.adanalyticscolumns[1], } @@ -1135,7 +1191,15 @@ def get_url_params( **super().get_url_params(context, next_page_token), } - def get_unescaped_params(self, context: Context | None) -> dict: + def get_unencoded_params(self, context: Context | None) -> dict: + """Return a dictionary of unencoded params. + + Args: + context: The stream context. + + Returns: + A dictionary of URL query parameters. + """ start_date = pendulum.parse(self.config["start_date"]) end_date = pendulum.parse(self.config["end_date"]) creative_urn = context["creative_urn"] @@ -1170,9 +1234,17 @@ def post_process(self, row: dict, context: dict | None = None) -> dict | None: class AdAnalyticsByCreativeStream(AdAnalyticsByCreativeInit): name = "ad_analytics_by_creative" - def get_unescaped_params(self, context: Context | None) -> dict: + def get_unencoded_params(self, context: Context | None) -> dict: + """Return a dictionary of unencoded params. + + Args: + context: The stream context. + + Returns: + A dictionary of URL query parameters. + """ return { - **super().get_unescaped_params(context), + **super().get_unencoded_params(context), # Overwrite fields with this column subset "fields": self.adanalyticscolumns[1], } @@ -1234,9 +1306,17 @@ def merge_dicts(self, *dict_args: dict) -> dict: class AdAnalyticsByCreativeSecond(AdAnalyticsByCreativeInit): name = "adanalyticsbycreative_second" - def get_unescaped_params(self, context: Context | None) -> dict: + def get_unencoded_params(self, context: Context | None) -> dict: + """Return a dictionary of unencoded params. + + Args: + context: The stream context. + + Returns: + A dictionary of URL query parameters. + """ return { - **super().get_unescaped_params(context), + **super().get_unencoded_params(context), # Overwrite fields with this column subset "fields": self.adanalyticscolumns[2], } @@ -1245,9 +1325,17 @@ def get_unescaped_params(self, context: Context | None) -> dict: class AdAnalyticsByCreativeThird(AdAnalyticsByCreativeInit): name = "adanalyticsbycreative_third" - def get_unescaped_params(self, context: Context | None) -> dict: + def get_unencoded_params(self, context: Context | None) -> dict: + """Return a dictionary of unencoded params. + + Args: + context: The stream context. + + Returns: + A dictionary of URL query parameters. + """ return { - **super().get_unescaped_params(context), + **super().get_unencoded_params(context), # Overwrite fields with this column subset "fields": self.adanalyticscolumns[3], }