1
0
mirror of synced 2025-12-25 02:09:19 -05:00

🐛 [source-youtube-analytics]: fix issue with empty responses (#53196)

Co-authored-by: Octavia Squidington III <octavia-squidington-iii@users.noreply.github.com>
Co-authored-by: Marcos Marx <marcosmarxm@users.noreply.github.com>
Co-authored-by: marcosmarxm <marcosmarxm@gmail.com>
This commit is contained in:
c200bzh
2025-05-29 22:05:24 +02:00
committed by GitHub
parent edd340a41c
commit 660fc70adf
6 changed files with 1425 additions and 247 deletions

View File

@@ -8,7 +8,7 @@ data:
connectorSubtype: api
connectorType: source
definitionId: afa734e4-3571-11ec-991a-1e0031268139
dockerImageTag: 0.1.7
dockerImageTag: 0.2.0
dockerRepository: airbyte/source-youtube-analytics
documentationUrl: https://docs.airbyte.com/integrations/sources/youtube-analytics
githubIssueLabel: source-youtube-analytics
@@ -38,5 +38,5 @@ data:
type: GSM
alias: airbyte-connector-testing-secret-store
connectorBuildOptions:
baseImage: docker.io/airbyte/python-connector-base:1.2.0@sha256:c22a9d97464b69d6ef01898edf3f8612dc11614f05a84984451dde195f337db9
baseImage: docker.io/airbyte/python-connector-base:2.0.0@sha256:c44839ba84406116e8ba68722a0f30e8f6e7056c726f447681bb9e9ece8bd916
metadataSpecVersion: "1.0"

File diff suppressed because it is too large Load Diff

View File

@@ -3,7 +3,7 @@ requires = [ "poetry-core>=1.0.0",]
build-backend = "poetry.core.masonry.api"
[tool.poetry]
version = "0.1.7"
version = "0.2.0"
name = "source-youtube-analytics"
description = "Source implementation for Youtube Analytics."
authors = [ "Airbyte <contact@airbyte.io>",]
@@ -16,8 +16,9 @@ repository = "https://github.com/airbytehq/airbyte"
include = "source_youtube_analytics"
[tool.poetry.dependencies]
python = "^3.9,<3.12"
airbyte-cdk = "0.38.0"
python = "^3.10,<3.12"
airbyte-cdk = "^6"
pendulum = "^3.0.0"
[tool.poetry.scripts]
source-youtube-analytics = "source_youtube_analytics.run:run"

View File

@@ -143,8 +143,8 @@ class JobsResource(CustomBackoffMixin, HttpStream):
self.name = None
self.http_method = "GET"
results = list(self.read_records(sync_mode=None))
result = results[0]
return result.get("jobs", {})
result = results[0] if results else {"jobs": []}
return result.get("jobs", [])
def create(self, name):
"https://developers.google.com/youtube/reporting/v1/reference/rest/v1/jobs/create"
@@ -262,16 +262,17 @@ class SourceYoutubeAnalytics(AbstractSource):
)
def check_connection(self, logger, config) -> Tuple[bool, any]:
authenticator = self.get_authenticator(config)
jobs_resource = JobsResource(authenticator=authenticator)
result = jobs_resource.list()
if result:
try:
authenticator = self.get_authenticator(config)
jobs_resource = JobsResource(authenticator=authenticator)
jobs_resource.list()
return True, None
else:
return (
False,
"The Youtube account is not valid. Please make sure you're trying to use the active Youtube Account connected to your Google Account.",
)
except requests.exceptions.RequestException as e:
if "401" in str(e):
return False, "Authentication failed. Please verify your credentials."
elif "403" in str(e):
return False, "Authorization failed. Please ensure you have the correct permissions."
return False, f"Unable to connect to YouTube Analytics API: {str(e)}"
def streams(self, config: Mapping[str, Any]) -> List[Stream]:
authenticator = self.get_authenticator(config)

View File

@@ -8,8 +8,6 @@ from unittest.mock import MagicMock
from source_youtube_analytics.source import SourceYoutubeAnalytics
from airbyte_cdk.sources.streams.http.auth.core import NoAuth
def test_check_connection(requests_mock):
access_token = "token"
@@ -27,12 +25,14 @@ def test_check_connection(requests_mock):
def test_streams(requests_mock):
requests_mock.get("https://youtubereporting.googleapis.com/v1/jobs", json={})
requests_mock.post(
"https://oauth2.googleapis.com/token", json={"access_token": "fake-token", "expires_in": 3600, "token_type": "Bearer"}
)
with open(os.path.join(os.path.dirname(__file__), "../source_youtube_analytics/defaults/channel_reports.json")) as fp:
channel_reports = json.load(fp)
source = SourceYoutubeAnalytics()
source.get_authenticator = MagicMock(return_value=NoAuth())
config_mock = MagicMock()
streams = source.streams(config_mock)
assert len(streams) == len(channel_reports)

View File

@@ -86,6 +86,7 @@ Quota usage is not an issue because data is retrieved once and then filtered, so
| Version | Date | Pull Request | Subject |
| :------ | :--------- | :------------------------------------------------------- | :--------------------------------------------- |
| 0.2.0 | 2025-02-07 | [53196](https://github.com/airbytehq/airbyte/pull/53196) | Update check connection and empty responses |
| 0.1.7 | 2025-02-26 | [54696](https://github.com/airbytehq/airbyte/pull/54696) | Update requests-mock dependency versionb |
| 0.1.6 | 2024-06-17 | [39529](https://github.com/airbytehq/airbyte/pull/39529) | Pin CDK version to 0.38.0 |
| 0.1.5 | 2024-05-21 | [38546](https://github.com/airbytehq/airbyte/pull/38546) | [autopull] base image + poetry + up_to_date |