-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathgooddata_api_wrapper.py
More file actions
65 lines (47 loc) · 2.06 KB
/
gooddata_api_wrapper.py
File metadata and controls
65 lines (47 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# (C) 2025 GoodData Corporation
"""Wrapper for interaction with GoodData Cloud."""
from gooddata_sdk.sdk import GoodDataSdk
from gooddata_pipelines.api.gooddata_api import ApiMethods
from gooddata_pipelines.api.gooddata_sdk import SdkMethods
# TODO: Refactor the GoodDataApi class to use composition instead of inheritance.
class GoodDataApi(SdkMethods, ApiMethods):
"""Wrapper class for the GoodData Cloud API.
This class combines interactions with the GoodData Python SDK and direct API
calls.
"""
def __init__(self, host: str, token: str) -> None:
"""Initialize the GoodDataApi with host and token.
Args:
host (str): The GoodData Cloud host URL.
token (str): The authentication token for the GoodData Cloud API.
"""
self._domain: str = self._get_clean_host(host)
self._token: str = token
# Initialize the GoodData SDK
self._sdk = GoodDataSdk.create(self._domain, self._token)
# Set up utils for direct API interaction
self.base_url = self._get_base_url(self._domain)
self.headers: dict = {
"Authorization": f"Bearer {self._token}",
"Content-Type": "application/vnd.gooddata.api+json",
}
@staticmethod
def _get_clean_host(host: str) -> str:
"""Returns a clean URL of the GoodData Cloud host.
Method ensures that the URL starts with "https://" and does not
end with a trailing slash.
"""
if host is None:
raise RuntimeError("Host is not set. Please provide a valid host.")
if host == "":
raise ValueError(
"Host is an empty string. Please provide a valid host."
)
# Remove trailing slash if present.
if host[-1] == "/":
host = host[:-1]
if not host.startswith("https://") and not host.startswith("http://"):
host = f"https://{host}"
if host.startswith("http://") and not host.startswith("https://"):
host = host.replace("http://", "https://")
return host