Skip to content

Commit

Permalink
rename to unencoded and add doc string
Browse files Browse the repository at this point in the history
  • Loading branch information
pnadolny13 committed Oct 24, 2024
1 parent 4c67396 commit d784637
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 21 deletions.
16 changes: 12 additions & 4 deletions tap_linkedin_ads/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand All @@ -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()
],
)
)
Expand Down
122 changes: 105 additions & 17 deletions tap_linkedin_ads/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']}",
}
Expand Down Expand Up @@ -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)))"
}
Expand Down Expand Up @@ -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)))"
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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],
}
Expand All @@ -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],
}
Expand All @@ -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],
}
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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],
}
Expand Down Expand Up @@ -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],
}
Expand All @@ -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],
}

0 comments on commit d784637

Please sign in to comment.