Skip to content

Commit 11742c9

Browse files
[youtube-data-api] Update YouTubeDataApiClient and YouTubeDataApiReportFetcher
* Raise exception when API key is not set or directly provided to YouTubeDataApiClient * Pass YouTubeDataApiQuery to YouTubeDataApiReportFetcher to allow additional query customization * Add common GarfYouTubeDataApiError in exceptions module
1 parent d4f60a9 commit 11742c9

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

libs/garf_community/youtube/garf_youtube_data_api/garf_youtube_data_api/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@
2424
'YouTubeDataApiReportFetcher',
2525
]
2626

27-
__version__ = '0.0.5'
27+
__version__ = '0.0.6'

libs/garf_community/youtube/garf_youtube_data_api/garf_youtube_data_api/api_clients.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,28 @@
1818
from googleapiclient.discovery import build
1919
from typing_extensions import override
2020

21-
from garf_core import api_clients, query_editor
21+
from garf_core import api_clients, exceptions, query_editor
22+
23+
24+
class YouTubeDataApiClientError(exceptions.GarfYouTubeDataApiError):
25+
"""API client specific exception."""
2226

2327

2428
class YouTubeDataApiClient(api_clients.BaseClient):
29+
"""Handles fetching data form YouTube Data API."""
30+
2531
def __init__(
2632
self,
2733
api_key: str = os.getenv('GOOGLE_API_KEY'),
2834
api_version: str = 'v3',
2935
**kwargs: str,
3036
) -> None:
3137
"""Initializes YouTubeDataApiClient."""
38+
if not api_key:
39+
raise YouTubeDataApiClientError(
40+
'api_key is not found. Either pass to YouTubeDataApiClient as api_key '
41+
'parameter or expose as GOOGLE_API_KEY ENV varible'
42+
)
3243
self.api_key = api_key
3344
self.api_version = api_version
3445
self.api_key
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Defines common library exceptions."""
16+
17+
18+
class GarfYouTubeDataApiError(Exception):
19+
"""Base class for all library exceptions."""

libs/garf_community/youtube/garf_youtube_data_api/garf_youtube_data_api/report_fetcher.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from typing_extensions import override
2424

2525
from garf_core import parsers, report, report_fetcher
26+
from garf_youtube_data_api import query_editor
2627
from garf_youtube_data_api.api_clients import YouTubeDataApiClient
2728

2829
ALLOWED_FILTERS: Final[set[str]] = (
@@ -54,10 +55,13 @@ def __init__(
5455
self,
5556
api_client: YouTubeDataApiClient = YouTubeDataApiClient(),
5657
parser: parsers.BaseParser = parsers.NumericConverterDictParser,
58+
query_spec: query_editor.YouTubeDataApiQuery = (
59+
query_editor.YouTubeDataApiQuery
60+
),
5761
**kwargs: str,
5862
) -> None:
5963
"""Initializes YouTubeDataApiReportFetcher."""
60-
super().__init__(api_client, parser, **kwargs)
64+
super().__init__(api_client, parser, query_spec, **kwargs)
6165

6266
@override
6367
def fetch(

0 commit comments

Comments
 (0)