-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
1,875 additions
and
493 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
324 changes: 309 additions & 15 deletions
324
airbyte-integrations/connectors/source-linkedin-ads/poetry.lock
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
airbyte-integrations/connectors/source-linkedin-ads/source_linkedin_ads/components.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Copyright (c) 2024 Airbyte, Inc., all rights reserved. | ||
|
||
from airbyte_cdk.sources.declarative.requesters import HttpRequester | ||
from airbyte_cdk.sources.declarative.requesters.request_options.interpolated_request_options_provider import ( | ||
InterpolatedRequestOptionsProvider, | ||
RequestInput, | ||
) | ||
from dataclasses import dataclass | ||
from typing import Any, Mapping, Optional | ||
from urllib.parse import urljoin | ||
|
||
import requests | ||
from airbyte_cdk.sources.declarative.requesters.request_options.interpolated_request_options_provider import ( | ||
InterpolatedRequestOptionsProvider, | ||
) | ||
from airbyte_cdk.sources.streams.http.exceptions import DefaultBackoffException, RequestBodyException, UserDefinedBackoffException | ||
from airbyte_cdk.sources.streams.http.http import BODY_REQUEST_METHODS | ||
from urllib.parse import urlencode | ||
|
||
|
||
@dataclass | ||
class SafeEncodeHttpRequester(HttpRequester): | ||
""" | ||
This custom component safely validates query parameters, ignoring the symbols ():,% for UTF-8 encoding. | ||
Attributes: | ||
request_body_json: Optional JSON body for the request. | ||
request_headers: Optional headers for the request. | ||
request_parameters: Optional parameters for the request. | ||
request_body_data: Optional data body for the request. | ||
""" | ||
request_body_json: Optional[RequestInput] = None | ||
request_headers: Optional[RequestInput] = None | ||
request_parameters: Optional[RequestInput] = None | ||
request_body_data: Optional[RequestInput] = None | ||
|
||
def __post_init__(self, parameters: Mapping[str, Any]) -> None: | ||
self.request_options_provider = InterpolatedRequestOptionsProvider( | ||
request_body_data=self.request_body_data, | ||
request_body_json=self.request_body_json, | ||
request_headers=self.request_headers, | ||
request_parameters=self.request_parameters, | ||
config=self.config, | ||
parameters=parameters or {}, | ||
) | ||
super().__post_init__(parameters) | ||
|
||
def _create_prepared_request( | ||
self, | ||
path: str, | ||
headers: Optional[Mapping[str, str]] = None, | ||
params: Optional[Mapping[str, Any]] = None, | ||
json: Any = None, | ||
data: Any = None, | ||
) -> requests.PreparedRequest: | ||
url = urljoin(self.get_url_base(), path) | ||
http_method = str(self._http_method.value) | ||
query_params = self.deduplicate_query_params(url, params) | ||
query_params = urlencode(query_params, safe="():,%") | ||
args = {"method": http_method, "url": url, "headers": headers, "params": query_params} | ||
if http_method.upper() in BODY_REQUEST_METHODS: | ||
if json and data: | ||
raise RequestBodyException( | ||
"At the same time only one of the 'request_body_data' and 'request_body_json' functions can return data" | ||
) | ||
elif json: | ||
args["json"] = json | ||
elif data: | ||
args["data"] = data | ||
|
||
return self._session.prepare_request(requests.Request(**args)) |
Oops, something went wrong.