From 35746d18cd092ab0f9cb86c537af2b9153f49fdc Mon Sep 17 00:00:00 2001 From: lazebnyi Date: Wed, 25 Aug 2021 17:35:19 +0300 Subject: [PATCH] Updated to format --- .../source_google_analytics_v4/source.py | 25 +++++++------------ .../metrics_dimensions_type_list.json | 6 ++--- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/airbyte-integrations/connectors/source-google-analytics-v4/source_google_analytics_v4/source.py b/airbyte-integrations/connectors/source-google-analytics-v4/source_google_analytics_v4/source.py index 1aa518712a06..0e7bb8d0f0ee 100644 --- a/airbyte-integrations/connectors/source-google-analytics-v4/source_google_analytics_v4/source.py +++ b/airbyte-integrations/connectors/source-google-analytics-v4/source_google_analytics_v4/source.py @@ -140,7 +140,7 @@ def next_page_token(self, response: requests.Response) -> Optional[Mapping[str, return {"pageToken": next_page} def request_body_json( - self, stream_slice: Mapping[str, Any] = None, next_page_token: Mapping[str, Any] = None, **kwargs + self, stream_slice: Mapping[str, Any] = None, next_page_token: Mapping[str, Any] = None, **kwargs ) -> Optional[Mapping]: metrics = [{"expression": metric} for metric in self.metrics] @@ -173,9 +173,7 @@ def get_json_schema(self) -> Mapping[str, Any]: "type": ["null", "object"], "additionalProperties": False, "properties": { - "view_id": { - "type": ["string"] - }, + "view_id": {"type": ["string"]}, }, } @@ -227,8 +225,7 @@ def stream_slices(self, stream_state: Mapping[str, Any] = None, **kwargs) -> Ite while start_date <= end_date: end_date_slice = start_date.add(days=self.window_in_days) - date_slices.append( - {"startDate": self.to_datetime_str(start_date), "endDate": self.to_datetime_str(end_date_slice)}) + date_slices.append({"startDate": self.to_datetime_str(start_date), "endDate": self.to_datetime_str(end_date_slice)}) # add 1 day for start next slice from next day and not duplicate data from previous slice end date. start_date = end_date_slice.add(days=1) @@ -259,7 +256,7 @@ def lookup_data_type(self, field_type, attribute): # Custom Google Analytics Metrics {ga:goalXXStarts, ga:metricXX, ... } # We always treat them as as strings as we can not be sure of their data type if attribute.startswith("ga:goal") and attribute.endswith( - ("Starts", "Completions", "Value", "ConversionRate", "Abandons", "AbandonRate") + ("Starts", "Completions", "Value", "ConversionRate", "Abandons", "AbandonRate") ): return "string" elif attribute.startswith("ga:searchGoal") and attribute.endswith("ConversionRate"): @@ -399,13 +396,11 @@ def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapp class GoogleAnalyticsV4IncrementalObjectsBase(GoogleAnalyticsV4Stream): cursor_field = "ga_date" - def get_updated_state(self, current_stream_state: MutableMapping[str, Any], latest_record: Mapping[str, Any]) -> \ - Mapping[str, Any]: + def get_updated_state(self, current_stream_state: MutableMapping[str, Any], latest_record: Mapping[str, Any]) -> Mapping[str, Any]: """ Update the state value, default CDK method. """ - return {self.cursor_field: max(latest_record.get(self.cursor_field, ""), - current_stream_state.get(self.cursor_field, ""))} + return {self.cursor_field: max(latest_record.get(self.cursor_field, ""), current_stream_state.get(self.cursor_field, ""))} class GoogleAnalyticsOauth2Authenticator(Oauth2Authenticator): @@ -433,8 +428,7 @@ def refresh_access_token(self) -> Tuple[str, int]: """ response_json = None try: - response = requests.request(method="POST", url=self.token_refresh_endpoint, - params=self.get_refresh_request_params()) + response = requests.request(method="POST", url=self.token_refresh_endpoint, params=self.get_refresh_request_params()) response_json = response.json() response.raise_for_status() @@ -492,7 +486,7 @@ def check_connection(self, logger, config) -> Tuple[bool, any]: return True, None except (requests.exceptions.RequestException, ValueError) as e: if e == ValueError: - logger.error(f"Invalid custom reports json structure.") + logger.error("Invalid custom reports json structure.") return False, e def streams(self, config: Mapping[str, Any]) -> List[Stream]: @@ -501,8 +495,7 @@ def streams(self, config: Mapping[str, Any]) -> List[Stream]: authenticator = GoogleAnalyticsOauth2Authenticator(config) config["authenticator"] = authenticator - config["ga_streams"] = json.loads( - pkgutil.get_data("source_google_analytics_v4", "defaults/default_reports.json")) + json.loads( + config["ga_streams"] = json.loads(pkgutil.get_data("source_google_analytics_v4", "defaults/default_reports.json")) + json.loads( config["custom_reports"] ) diff --git a/airbyte-integrations/connectors/source-google-analytics-v4/unit_tests/metrics_dimensions_type_list.json b/airbyte-integrations/connectors/source-google-analytics-v4/unit_tests/metrics_dimensions_type_list.json index 6d86c90c7efd..ebe17ec4028d 100644 --- a/airbyte-integrations/connectors/source-google-analytics-v4/unit_tests/metrics_dimensions_type_list.json +++ b/airbyte-integrations/connectors/source-google-analytics-v4/unit_tests/metrics_dimensions_type_list.json @@ -1,5 +1,5 @@ -{"items": -[ +{ + "items": [ { "id": "ga:users", "kind": "analytics#column", @@ -54,5 +54,5 @@ "addedInApiVersion": "3" } } -] + ] }